stark 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,451 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.8.0)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require 'profile_types'
9
+
10
+ module UserStorage
11
+ class Client
12
+ include ::Thrift::Client
13
+
14
+ def store(xuser)
15
+ send_store(xuser)
16
+ recv_store()
17
+ end
18
+
19
+ def send_store(xuser)
20
+ send_message('store', Store_args, :xuser => xuser)
21
+ end
22
+
23
+ def recv_store()
24
+ result = receive_message(Store_result)
25
+ return
26
+ end
27
+
28
+ def retrieve(xuid)
29
+ send_retrieve(xuid)
30
+ return recv_retrieve()
31
+ end
32
+
33
+ def send_retrieve(xuid)
34
+ send_message('retrieve', Retrieve_args, :xuid => xuid)
35
+ end
36
+
37
+ def recv_retrieve()
38
+ result = receive_message(Retrieve_result)
39
+ return result.success unless result.success.nil?
40
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'retrieve failed: unknown result')
41
+ end
42
+
43
+ def set_map(m)
44
+ send_set_map(m)
45
+ recv_set_map()
46
+ end
47
+
48
+ def send_set_map(m)
49
+ send_message('set_map', Set_map_args, :m => m)
50
+ end
51
+
52
+ def recv_set_map()
53
+ result = receive_message(Set_map_result)
54
+ return
55
+ end
56
+
57
+ def last_map()
58
+ send_last_map()
59
+ return recv_last_map()
60
+ end
61
+
62
+ def send_last_map()
63
+ send_message('last_map', Last_map_args)
64
+ end
65
+
66
+ def recv_last_map()
67
+ result = receive_message(Last_map_result)
68
+ return result.success unless result.success.nil?
69
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'last_map failed: unknown result')
70
+ end
71
+
72
+ def set_list(l)
73
+ send_set_list(l)
74
+ recv_set_list()
75
+ end
76
+
77
+ def send_set_list(l)
78
+ send_message('set_list', Set_list_args, :l => l)
79
+ end
80
+
81
+ def recv_set_list()
82
+ result = receive_message(Set_list_result)
83
+ return
84
+ end
85
+
86
+ def last_list()
87
+ send_last_list()
88
+ return recv_last_list()
89
+ end
90
+
91
+ def send_last_list()
92
+ send_message('last_list', Last_list_args)
93
+ end
94
+
95
+ def recv_last_list()
96
+ result = receive_message(Last_list_result)
97
+ return result.success unless result.success.nil?
98
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'last_list failed: unknown result')
99
+ end
100
+
101
+ def set_status(s)
102
+ send_set_status(s)
103
+ recv_set_status()
104
+ end
105
+
106
+ def send_set_status(s)
107
+ send_message('set_status', Set_status_args, :s => s)
108
+ end
109
+
110
+ def recv_set_status()
111
+ result = receive_message(Set_status_result)
112
+ return
113
+ end
114
+
115
+ def last_status()
116
+ send_last_status()
117
+ return recv_last_status()
118
+ end
119
+
120
+ def send_last_status()
121
+ send_message('last_status', Last_status_args)
122
+ end
123
+
124
+ def recv_last_status()
125
+ result = receive_message(Last_status_result)
126
+ return result.success unless result.success.nil?
127
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'last_status failed: unknown result')
128
+ end
129
+
130
+ end
131
+
132
+ class Processor
133
+ include ::Thrift::Processor
134
+
135
+ def process_store(seqid, iprot, oprot)
136
+ args = read_args(iprot, Store_args)
137
+ result = Store_result.new()
138
+ @handler.store(args.xuser)
139
+ write_result(result, oprot, 'store', seqid)
140
+ end
141
+
142
+ def process_retrieve(seqid, iprot, oprot)
143
+ args = read_args(iprot, Retrieve_args)
144
+ result = Retrieve_result.new()
145
+ result.success = @handler.retrieve(args.xuid)
146
+ write_result(result, oprot, 'retrieve', seqid)
147
+ end
148
+
149
+ def process_set_map(seqid, iprot, oprot)
150
+ args = read_args(iprot, Set_map_args)
151
+ result = Set_map_result.new()
152
+ @handler.set_map(args.m)
153
+ write_result(result, oprot, 'set_map', seqid)
154
+ end
155
+
156
+ def process_last_map(seqid, iprot, oprot)
157
+ args = read_args(iprot, Last_map_args)
158
+ result = Last_map_result.new()
159
+ result.success = @handler.last_map()
160
+ write_result(result, oprot, 'last_map', seqid)
161
+ end
162
+
163
+ def process_set_list(seqid, iprot, oprot)
164
+ args = read_args(iprot, Set_list_args)
165
+ result = Set_list_result.new()
166
+ @handler.set_list(args.l)
167
+ write_result(result, oprot, 'set_list', seqid)
168
+ end
169
+
170
+ def process_last_list(seqid, iprot, oprot)
171
+ args = read_args(iprot, Last_list_args)
172
+ result = Last_list_result.new()
173
+ result.success = @handler.last_list()
174
+ write_result(result, oprot, 'last_list', seqid)
175
+ end
176
+
177
+ def process_set_status(seqid, iprot, oprot)
178
+ args = read_args(iprot, Set_status_args)
179
+ result = Set_status_result.new()
180
+ @handler.set_status(args.s)
181
+ write_result(result, oprot, 'set_status', seqid)
182
+ end
183
+
184
+ def process_last_status(seqid, iprot, oprot)
185
+ args = read_args(iprot, Last_status_args)
186
+ result = Last_status_result.new()
187
+ result.success = @handler.last_status()
188
+ write_result(result, oprot, 'last_status', seqid)
189
+ end
190
+
191
+ end
192
+
193
+ # HELPER FUNCTIONS AND STRUCTURES
194
+
195
+ class Store_args
196
+ include ::Thrift::Struct, ::Thrift::Struct_Union
197
+ XUSER = 1
198
+
199
+ FIELDS = {
200
+ XUSER => {:type => ::Thrift::Types::STRUCT, :name => 'xuser', :class => UserProfile}
201
+ }
202
+
203
+ def struct_fields; FIELDS; end
204
+
205
+ def validate
206
+ end
207
+
208
+ ::Thrift::Struct.generate_accessors self
209
+ end
210
+
211
+ class Store_result
212
+ include ::Thrift::Struct, ::Thrift::Struct_Union
213
+
214
+ FIELDS = {
215
+
216
+ }
217
+
218
+ def struct_fields; FIELDS; end
219
+
220
+ def validate
221
+ end
222
+
223
+ ::Thrift::Struct.generate_accessors self
224
+ end
225
+
226
+ class Retrieve_args
227
+ include ::Thrift::Struct, ::Thrift::Struct_Union
228
+ XUID = 1
229
+
230
+ FIELDS = {
231
+ XUID => {:type => ::Thrift::Types::I32, :name => 'xuid'}
232
+ }
233
+
234
+ def struct_fields; FIELDS; end
235
+
236
+ def validate
237
+ end
238
+
239
+ ::Thrift::Struct.generate_accessors self
240
+ end
241
+
242
+ class Retrieve_result
243
+ include ::Thrift::Struct, ::Thrift::Struct_Union
244
+ SUCCESS = 0
245
+
246
+ FIELDS = {
247
+ SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => UserProfile}
248
+ }
249
+
250
+ def struct_fields; FIELDS; end
251
+
252
+ def validate
253
+ end
254
+
255
+ ::Thrift::Struct.generate_accessors self
256
+ end
257
+
258
+ class Set_map_args
259
+ include ::Thrift::Struct, ::Thrift::Struct_Union
260
+ M = 1
261
+
262
+ FIELDS = {
263
+ M => {:type => ::Thrift::Types::MAP, :name => 'm', :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::STRING}}
264
+ }
265
+
266
+ def struct_fields; FIELDS; end
267
+
268
+ def validate
269
+ end
270
+
271
+ ::Thrift::Struct.generate_accessors self
272
+ end
273
+
274
+ class Set_map_result
275
+ include ::Thrift::Struct, ::Thrift::Struct_Union
276
+
277
+ FIELDS = {
278
+
279
+ }
280
+
281
+ def struct_fields; FIELDS; end
282
+
283
+ def validate
284
+ end
285
+
286
+ ::Thrift::Struct.generate_accessors self
287
+ end
288
+
289
+ class Last_map_args
290
+ include ::Thrift::Struct, ::Thrift::Struct_Union
291
+
292
+ FIELDS = {
293
+
294
+ }
295
+
296
+ def struct_fields; FIELDS; end
297
+
298
+ def validate
299
+ end
300
+
301
+ ::Thrift::Struct.generate_accessors self
302
+ end
303
+
304
+ class Last_map_result
305
+ include ::Thrift::Struct, ::Thrift::Struct_Union
306
+ SUCCESS = 0
307
+
308
+ FIELDS = {
309
+ SUCCESS => {:type => ::Thrift::Types::MAP, :name => 'success', :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::STRING}}
310
+ }
311
+
312
+ def struct_fields; FIELDS; end
313
+
314
+ def validate
315
+ end
316
+
317
+ ::Thrift::Struct.generate_accessors self
318
+ end
319
+
320
+ class Set_list_args
321
+ include ::Thrift::Struct, ::Thrift::Struct_Union
322
+ L = 1
323
+
324
+ FIELDS = {
325
+ L => {:type => ::Thrift::Types::LIST, :name => 'l', :element => {:type => ::Thrift::Types::STRING}}
326
+ }
327
+
328
+ def struct_fields; FIELDS; end
329
+
330
+ def validate
331
+ end
332
+
333
+ ::Thrift::Struct.generate_accessors self
334
+ end
335
+
336
+ class Set_list_result
337
+ include ::Thrift::Struct, ::Thrift::Struct_Union
338
+
339
+ FIELDS = {
340
+
341
+ }
342
+
343
+ def struct_fields; FIELDS; end
344
+
345
+ def validate
346
+ end
347
+
348
+ ::Thrift::Struct.generate_accessors self
349
+ end
350
+
351
+ class Last_list_args
352
+ include ::Thrift::Struct, ::Thrift::Struct_Union
353
+
354
+ FIELDS = {
355
+
356
+ }
357
+
358
+ def struct_fields; FIELDS; end
359
+
360
+ def validate
361
+ end
362
+
363
+ ::Thrift::Struct.generate_accessors self
364
+ end
365
+
366
+ class Last_list_result
367
+ include ::Thrift::Struct, ::Thrift::Struct_Union
368
+ SUCCESS = 0
369
+
370
+ FIELDS = {
371
+ SUCCESS => {:type => ::Thrift::Types::LIST, :name => 'success', :element => {:type => ::Thrift::Types::STRING}}
372
+ }
373
+
374
+ def struct_fields; FIELDS; end
375
+
376
+ def validate
377
+ end
378
+
379
+ ::Thrift::Struct.generate_accessors self
380
+ end
381
+
382
+ class Set_status_args
383
+ include ::Thrift::Struct, ::Thrift::Struct_Union
384
+ S = 1
385
+
386
+ FIELDS = {
387
+ S => {:type => ::Thrift::Types::I32, :name => 's', :enum_class => Status}
388
+ }
389
+
390
+ def struct_fields; FIELDS; end
391
+
392
+ def validate
393
+ unless @s.nil? || Status::VALID_VALUES.include?(@s)
394
+ raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field s!')
395
+ end
396
+ end
397
+
398
+ ::Thrift::Struct.generate_accessors self
399
+ end
400
+
401
+ class Set_status_result
402
+ include ::Thrift::Struct, ::Thrift::Struct_Union
403
+
404
+ FIELDS = {
405
+
406
+ }
407
+
408
+ def struct_fields; FIELDS; end
409
+
410
+ def validate
411
+ end
412
+
413
+ ::Thrift::Struct.generate_accessors self
414
+ end
415
+
416
+ class Last_status_args
417
+ include ::Thrift::Struct, ::Thrift::Struct_Union
418
+
419
+ FIELDS = {
420
+
421
+ }
422
+
423
+ def struct_fields; FIELDS; end
424
+
425
+ def validate
426
+ end
427
+
428
+ ::Thrift::Struct.generate_accessors self
429
+ end
430
+
431
+ class Last_status_result
432
+ include ::Thrift::Struct, ::Thrift::Struct_Union
433
+ SUCCESS = 0
434
+
435
+ FIELDS = {
436
+ SUCCESS => {:type => ::Thrift::Types::I32, :name => 'success', :enum_class => Status}
437
+ }
438
+
439
+ def struct_fields; FIELDS; end
440
+
441
+ def validate
442
+ unless @success.nil? || Status::VALID_VALUES.include?(@success)
443
+ raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field success!')
444
+ end
445
+ end
446
+
447
+ ::Thrift::Struct.generate_accessors self
448
+ end
449
+
450
+ end
451
+
data/test/leg.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'rubygems'
2
+ require 'thrift'
3
+
4
+ $: << "test/legacy_profile"
5
+
6
+ require 'user_storage'
7
+
8
+ f = File.read("test/new_client.rb")
9
+
10
+ eval "module New; #{f}; end"
11
+
12
+ cr, cw = IO.pipe
13
+ sr, sw = IO.pipe
14
+
15
+
16
+ class LogTransport < Thrift::BaseTransport
17
+ def initialize(inner, prefix="log")
18
+ @prefix = prefix
19
+ @inner = inner
20
+ end
21
+
22
+ def log(name)
23
+ puts "#{@prefix}: #{name}"
24
+ end
25
+
26
+ def open?; log :open?; @inner.open? end
27
+ def read(sz); log :read; @inner.read(sz) end
28
+ def write(buf); log :write; @inner.write(buf) end
29
+ def close; log :close; @inner.close end
30
+ def to_io; @inner.to_io end
31
+ end
32
+
33
+ client_t = Thrift::IOStreamTransport.new sr, cw
34
+
35
+ client_p = Thrift::BinaryProtocol.new LogTransport.new(client_t, "client")
36
+
37
+ client = New::UserStorage::Client.new client_p, client_p
38
+
39
+
40
+ server_t = Thrift::IOStreamTransport.new cr, sw
41
+ server_p = Thrift::BinaryProtocol.new LogTransport.new(server_t, "server")
42
+
43
+ class Handler
44
+ def initialize
45
+ @users = {}
46
+ end
47
+
48
+ def store(obj)
49
+ p obj
50
+ @users[obj.uid] = obj
51
+ end
52
+
53
+ def retrieve(id)
54
+ @users[id]
55
+ end
56
+ end
57
+
58
+ server = UserStorage::Processor.new Handler.new
59
+
60
+ Thread.abort_on_exception = true
61
+
62
+ st = Thread.new do
63
+ server.process server_p, server_p
64
+ end
65
+
66
+ xuser = New::UserProfile.new 'uid' => 0, 'name' => 'root', 'blurb' => 'god'
67
+
68
+ client.store xuser
69
+
70
+ st.join
71
+
72
+ st = Thread.new do
73
+ server.process server_p, server_p
74
+ end
75
+
76
+ obj = client.retrieve 0
77
+ p obj
@@ -0,0 +1,8 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.8.0)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'profile_types'
8
+
@@ -0,0 +1,36 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.8.0)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+
8
+ module Status
9
+ ON = 0
10
+ OFF = 1
11
+ DEAD = 2
12
+ ALIVE = 3
13
+ VALUE_MAP = {0 => "ON", 1 => "OFF", 2 => "DEAD", 3 => "ALIVE"}
14
+ VALID_VALUES = Set.new([ON, OFF, DEAD, ALIVE]).freeze
15
+ end
16
+
17
+ class UserProfile
18
+ include ::Thrift::Struct, ::Thrift::Struct_Union
19
+ UID = 1
20
+ NAME = 2
21
+ BLURB = 3
22
+
23
+ FIELDS = {
24
+ UID => {:type => ::Thrift::Types::I32, :name => 'uid'},
25
+ NAME => {:type => ::Thrift::Types::STRING, :name => 'name'},
26
+ BLURB => {:type => ::Thrift::Types::STRING, :name => 'blurb'}
27
+ }
28
+
29
+ def struct_fields; FIELDS; end
30
+
31
+ def validate
32
+ end
33
+
34
+ ::Thrift::Struct.generate_accessors self
35
+ end
36
+