celluloid_pubsub 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +2 -2
  4. data/Rakefile +6 -3
  5. data/celluloid_pubsub.gemspec +1 -1
  6. data/lib/celluloid_pubsub/reactor.rb +11 -15
  7. data/lib/celluloid_pubsub/version.rb +1 -1
  8. data/lib/celluloid_pubsub/web_server.rb +3 -0
  9. data/spec/lib/celluloid_pubsub/client_pubsub_spec.rb +128 -0
  10. data/spec/lib/celluloid_pubsub/reactor_spec.rb +208 -0
  11. data/spec/lib/celluloid_pubsub/registry_spec.rb +4 -0
  12. data/spec/lib/celluloid_pubsub/web_server_spec.rb +43 -0
  13. data/spec/spec_helper.rb +8 -0
  14. metadata +12 -70
  15. data/bin/appraisal +0 -16
  16. data/bin/autospec +0 -16
  17. data/bin/bundler +0 -16
  18. data/bin/cdiff +0 -16
  19. data/bin/coderay +0 -16
  20. data/bin/colortab +0 -16
  21. data/bin/coveralls +0 -16
  22. data/bin/decolor +0 -16
  23. data/bin/erubis +0 -16
  24. data/bin/guard +0 -16
  25. data/bin/htmldiff +0 -16
  26. data/bin/inch +0 -16
  27. data/bin/ldiff +0 -16
  28. data/bin/listen +0 -16
  29. data/bin/nokogiri +0 -16
  30. data/bin/phare +0 -16
  31. data/bin/pry +0 -16
  32. data/bin/rackup +0 -16
  33. data/bin/rails +0 -16
  34. data/bin/rake +0 -16
  35. data/bin/restclient +0 -16
  36. data/bin/rspec +0 -16
  37. data/bin/rubocop +0 -16
  38. data/bin/ruby-parse +0 -16
  39. data/bin/ruby-rewrite +0 -16
  40. data/bin/sass +0 -16
  41. data/bin/sass-convert +0 -16
  42. data/bin/scss +0 -16
  43. data/bin/scss-lint +0 -16
  44. data/bin/sparkr +0 -16
  45. data/bin/term_display +0 -16
  46. data/bin/term_mandel +0 -16
  47. data/bin/thor +0 -16
  48. data/bin/yard +0 -16
  49. data/bin/yardoc +0 -16
  50. data/bin/yardstick +0 -16
  51. data/bin/yri +0 -16
  52. data/doc/CelluloidPubsub/Client/PubSubWorker.html +0 -3676
  53. data/doc/CelluloidPubsub/Client.html +0 -340
  54. data/doc/CelluloidPubsub/Reactor.html +0 -3502
  55. data/doc/CelluloidPubsub/Registry.html +0 -234
  56. data/doc/CelluloidPubsub/VERSION.html +0 -204
  57. data/doc/CelluloidPubsub/WebServer.html +0 -4275
  58. data/doc/CelluloidPubsub.html +0 -225
  59. data/doc/_index.html +0 -184
  60. data/doc/class_list.html +0 -58
  61. data/doc/css/common.css +0 -1
  62. data/doc/css/full_list.css +0 -57
  63. data/doc/css/style.css +0 -339
  64. data/doc/file.README.html +0 -150
  65. data/doc/file_list.html +0 -60
  66. data/doc/frames.html +0 -26
  67. data/doc/index.html +0 -150
  68. data/doc/js/app.js +0 -219
  69. data/doc/js/full_list.js +0 -181
  70. data/doc/js/jquery.js +0 -4
  71. data/doc/method_list.html +0 -357
  72. data/doc/top-level-namespace.html +0 -112
@@ -1,3502 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title>
7
- Class: CelluloidPubsub::Reactor
8
-
9
- &mdash; Documentation by YARD 0.8.7.6
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- hasFrames = window.top.frames.main ? true : false;
19
- relpath = '../';
20
- framesUrl = "../frames.html#!CelluloidPubsub/Reactor.html";
21
- </script>
22
-
23
-
24
- <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
25
-
26
- <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
27
-
28
-
29
- </head>
30
- <body>
31
- <div id="header">
32
- <div id="menu">
33
-
34
- <a href="../_index.html">Index (R)</a> &raquo;
35
- <span class='title'><span class='object_link'><a href="../CelluloidPubsub.html" title="CelluloidPubsub (module)">CelluloidPubsub</a></span></span>
36
- &raquo;
37
- <span class="title">Reactor</span>
38
-
39
-
40
- <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
- </div>
42
-
43
- <div id="search">
44
-
45
- <a class="full_list_link" id="class_list_link"
46
- href="../class_list.html">
47
- Class List
48
- </a>
49
-
50
- <a class="full_list_link" id="method_list_link"
51
- href="../method_list.html">
52
- Method List
53
- </a>
54
-
55
- <a class="full_list_link" id="file_list_link"
56
- href="../file_list.html">
57
- File List
58
- </a>
59
-
60
- </div>
61
- <div class="clear"></div>
62
- </div>
63
-
64
- <iframe id="search_frame"></iframe>
65
-
66
- <div id="content"><h1>Class: CelluloidPubsub::Reactor
67
-
68
-
69
-
70
- </h1>
71
-
72
- <dl class="box">
73
-
74
- <dt class="r1">Inherits:</dt>
75
- <dd class="r1">
76
- <span class="inheritName">Object</span>
77
-
78
- <ul class="fullTree">
79
- <li>Object</li>
80
-
81
- <li class="next">CelluloidPubsub::Reactor</li>
82
-
83
- </ul>
84
- <a href="#" class="inheritanceTree">show all</a>
85
-
86
- </dd>
87
-
88
-
89
-
90
-
91
-
92
-
93
- <dt class="r2">Includes:</dt>
94
- <dd class="r2">Celluloid, Celluloid::IO, Celluloid::Logger</dd>
95
-
96
-
97
-
98
-
99
-
100
- <dt class="r1 last">Defined in:</dt>
101
- <dd class="r1 last">lib/celluloid_pubsub/reactor.rb</dd>
102
-
103
- </dl>
104
- <div class="clear"></div>
105
-
106
- <h2>Overview</h2><div class="docstring">
107
- <div class="discussion">
108
-
109
- <p>The reactor handles new connections. Based on what the client sends it
110
- either subscribes to a channel or will publish to a channel or just
111
- dispatch to the server if command is neither subscribe, publish or
112
- unsubscribe</p>
113
-
114
-
115
- </div>
116
- </div>
117
- <div class="tags">
118
-
119
-
120
- </div>
121
-
122
-
123
-
124
- <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
125
- <ul class="summary">
126
-
127
- <li class="public ">
128
- <span class="summary_signature">
129
-
130
- <a href="#channels-instance_method" title="#channels (instance method)">- (Array) <strong>channels</strong> </a>
131
-
132
-
133
-
134
- </span>
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
- <span class="summary_desc"><div class='inline'>
148
- <p>Array of channels to which the current reactor has subscribed to.</p>
149
- </div></span>
150
-
151
- </li>
152
-
153
-
154
- <li class="public ">
155
- <span class="summary_signature">
156
-
157
- <a href="#mutex-instance_method" title="#mutex (instance method)">- (Mutex) <strong>mutex</strong> </a>
158
-
159
-
160
-
161
- </span>
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
- <span class="summary_desc"><div class='inline'>
175
- <p>Mutex used to lock when subscribing to a channel.</p>
176
- </div></span>
177
-
178
- </li>
179
-
180
-
181
- <li class="public ">
182
- <span class="summary_signature">
183
-
184
- <a href="#server-instance_method" title="#server (instance method)">- (CelluloidPubsub::Webserver) <strong>server</strong> </a>
185
-
186
-
187
-
188
- </span>
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
- <span class="summary_desc"><div class='inline'>
202
- <p>The server actor to which the reactor is connected to.</p>
203
- </div></span>
204
-
205
- </li>
206
-
207
-
208
- <li class="public ">
209
- <span class="summary_signature">
210
-
211
- <a href="#websocket-instance_method" title="#websocket (instance method)">- (Reel::WebSocket) <strong>websocket</strong> </a>
212
-
213
-
214
-
215
- </span>
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
- <span class="summary_desc"><div class='inline'>
229
- <p>Websocket connection.</p>
230
- </div></span>
231
-
232
- </li>
233
-
234
-
235
- </ul>
236
-
237
-
238
-
239
-
240
-
241
- <h2>
242
- Instance Method Summary
243
- <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
244
- </h2>
245
-
246
- <ul class="summary">
247
-
248
- <li class="public ">
249
- <span class="summary_signature">
250
-
251
- <a href="#add_subscriber_to_channel-instance_method" title="#add_subscriber_to_channel (instance method)">- (void) <strong>add_subscriber_to_channel</strong>(channel, message) </a>
252
-
253
-
254
-
255
- </span>
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
- <span class="summary_desc"><div class='inline'>
266
- <p>adds the curent actor the list of the subscribers for a particular channel
267
- and registers the new channel.</p>
268
- </div></span>
269
-
270
- </li>
271
-
272
-
273
- <li class="public ">
274
- <span class="summary_signature">
275
-
276
- <a href="#delegate_action-instance_method" title="#delegate_action (instance method)">- (void) <strong>delegate_action</strong>(json_data) </a>
277
-
278
-
279
-
280
- </span>
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
- <span class="summary_desc"><div class='inline'>
291
- <p>method that checks if the data is a Hash.</p>
292
- </div></span>
293
-
294
- </li>
295
-
296
-
297
- <li class="public ">
298
- <span class="summary_signature">
299
-
300
- <a href="#handle_parsed_websocket_message-instance_method" title="#handle_parsed_websocket_message (instance method)">- (void) <strong>handle_parsed_websocket_message</strong>(json_data) </a>
301
-
302
-
303
-
304
- </span>
305
-
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
- <span class="summary_desc"><div class='inline'>
315
- <p>method that checks if the data is a Hash.</p>
316
- </div></span>
317
-
318
- </li>
319
-
320
-
321
- <li class="public ">
322
- <span class="summary_signature">
323
-
324
- <a href="#handle_unknown_action-instance_method" title="#handle_unknown_action (instance method)">- (void) <strong>handle_unknown_action</strong>(json_data) </a>
325
-
326
-
327
-
328
- </span>
329
-
330
-
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
- <span class="summary_desc"><div class='inline'>
339
- <p>the method will delegate the message to the server in an asyncronous way by
340
- sending the current actor and the message.</p>
341
- </div></span>
342
-
343
- </li>
344
-
345
-
346
- <li class="public ">
347
- <span class="summary_signature">
348
-
349
- <a href="#handle_websocket_message-instance_method" title="#handle_websocket_message (instance method)">- (void) <strong>handle_websocket_message</strong>(message) </a>
350
-
351
-
352
-
353
- </span>
354
-
355
-
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
- <span class="summary_desc"><div class='inline'>
364
- <p>method that handles the message received from the websocket connection
365
- first will try to parse the message <span class='object_link'><a href="#parse_json_data-instance_method" title="CelluloidPubsub::Reactor#parse_json_data (method)">#parse_json_data</a></span> and then it will
366
- dispatch it to another method that will decide depending the message what
367
- action should the reactor take <span class='object_link'><a href="#handle_parsed_websocket_message-instance_method" title="CelluloidPubsub::Reactor#handle_parsed_websocket_message (method)">#handle_parsed_websocket_message</a></span>.</p>
368
- </div></span>
369
-
370
- </li>
371
-
372
-
373
- <li class="public ">
374
- <span class="summary_signature">
375
-
376
- <a href="#parse_json_data-instance_method" title="#parse_json_data (instance method)">- (Hash) <strong>parse_json_data</strong>(message) </a>
377
-
378
-
379
-
380
- </span>
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
-
390
- <span class="summary_desc"><div class='inline'>
391
- <p>method used to parse a JSON object into a Hash object.</p>
392
- </div></span>
393
-
394
- </li>
395
-
396
-
397
- <li class="public ">
398
- <span class="summary_signature">
399
-
400
- <a href="#run-instance_method" title="#run (instance method)">- (void) <strong>run</strong> </a>
401
-
402
-
403
-
404
- </span>
405
-
406
-
407
-
408
-
409
-
410
-
411
-
412
-
413
-
414
- <span class="summary_desc"><div class='inline'>
415
- <p>reads from the socket the message and dispatches it to the
416
- handle_websocket_message method.</p>
417
- </div></span>
418
-
419
- </li>
420
-
421
-
422
- <li class="public ">
423
- <span class="summary_signature">
424
-
425
- <a href="#shutdown-instance_method" title="#shutdown (instance method)">- (void) <strong>shutdown</strong> </a>
426
-
427
-
428
-
429
- </span>
430
-
431
-
432
-
433
-
434
-
435
-
436
-
437
-
438
-
439
- <span class="summary_desc"><div class='inline'>
440
- <p>the method will terminate the current actor.</p>
441
- </div></span>
442
-
443
- </li>
444
-
445
-
446
- <li class="public ">
447
- <span class="summary_signature">
448
-
449
- <a href="#start_subscriber-instance_method" title="#start_subscriber (instance method)">- (void) <strong>start_subscriber</strong>(channel, message) </a>
450
-
451
-
452
-
453
- </span>
454
-
455
-
456
-
457
-
458
-
459
-
460
-
461
-
462
-
463
- <span class="summary_desc"><div class='inline'>
464
- <p>this method will add the current actor to the list of the subscribers
465
- <span class='object_link'><a href="#add_subscriber_to_channel-instance_method" title="CelluloidPubsub::Reactor#add_subscriber_to_channel (method)">#add_subscriber_to_channel</a></span> and will write to the socket a message for
466
- succesful subscription.</p>
467
- </div></span>
468
-
469
- </li>
470
-
471
-
472
- <li class="public ">
473
- <span class="summary_signature">
474
-
475
- <a href="#unsubscribe_all-instance_method" title="#unsubscribe_all (instance method)">- (void) <strong>unsubscribe_all</strong> </a>
476
-
477
-
478
-
479
- </span>
480
-
481
-
482
-
483
-
484
-
485
-
486
-
487
-
488
-
489
- <span class="summary_desc"><div class='inline'>
490
- <p>unsubscribes all actors from all channels and terminates the curent actor.</p>
491
- </div></span>
492
-
493
- </li>
494
-
495
-
496
- <li class="public ">
497
- <span class="summary_signature">
498
-
499
- <a href="#unsubscribe_client-instance_method" title="#unsubscribe_client (instance method)">- (void) <strong>unsubscribe_client</strong>(channel) </a>
500
-
501
-
502
-
503
- </span>
504
-
505
-
506
-
507
-
508
-
509
-
510
-
511
-
512
-
513
- <span class="summary_desc"><div class='inline'>
514
- <p>the method will unsubscribe a client by closing the websocket connection if
515
- has unscribed from all channels and deleting the reactor from the channel
516
- list on the server.</p>
517
- </div></span>
518
-
519
- </li>
520
-
521
-
522
- <li class="public ">
523
- <span class="summary_signature">
524
-
525
- <a href="#work-instance_method" title="#work (instance method)">- (void) <strong>work</strong>(websocket, server) </a>
526
-
527
-
528
-
529
- </span>
530
-
531
-
532
-
533
-
534
-
535
-
536
-
537
-
538
-
539
- <span class="summary_desc"><div class='inline'>
540
- <p>rececives a new socket connection from the server and initiates a new
541
- mutex that can be used when subsribing to a channel.</p>
542
- </div></span>
543
-
544
- </li>
545
-
546
-
547
- </ul>
548
-
549
-
550
-
551
-
552
-
553
-
554
- <div id="instance_attr_details" class="attr_details">
555
- <h2>Instance Attribute Details</h2>
556
-
557
-
558
- <span id="channels=-instance_method"></span>
559
- <div class="method_details first">
560
- <h3 class="signature first" id="channels-instance_method">
561
-
562
- - (<tt>Array</tt>) <strong>channels</strong>
563
-
564
-
565
-
566
-
567
-
568
- </h3><div class="docstring">
569
- <div class="discussion">
570
-
571
- <p>Returns array of channels to which the current reactor has subscribed to</p>
572
-
573
-
574
- </div>
575
- </div>
576
- <div class="tags">
577
-
578
- <p class="tag_title">Returns:</p>
579
- <ul class="return">
580
-
581
- <li>
582
-
583
-
584
- <span class='type'>(<tt>Array</tt>)</span>
585
-
586
-
587
-
588
- &mdash;
589
- <div class='inline'>
590
- <p>array of channels to which the current reactor has subscribed to</p>
591
- </div>
592
-
593
- </li>
594
-
595
- </ul>
596
-
597
- </div><table class="source_code">
598
- <tr>
599
- <td>
600
- <pre class="lines">
601
-
602
-
603
- 16
604
- 17
605
- 18
606
- 19
607
- 20
608
- 21
609
- 22
610
- 23
611
- 24
612
- 25
613
- 26
614
- 27
615
- 28
616
- 29
617
- 30
618
- 31
619
- 32
620
- 33
621
- 34
622
- 35
623
- 36
624
- 37
625
- 38
626
- 39
627
- 40
628
- 41
629
- 42
630
- 43
631
- 44
632
- 45
633
- 46
634
- 47
635
- 48
636
- 49
637
- 50
638
- 51
639
- 52
640
- 53
641
- 54
642
- 55
643
- 56
644
- 57
645
- 58
646
- 59
647
- 60
648
- 61
649
- 62
650
- 63
651
- 64
652
- 65
653
- 66
654
- 67
655
- 68
656
- 69
657
- 70
658
- 71
659
- 72
660
- 73
661
- 74
662
- 75
663
- 76
664
- 77
665
- 78
666
- 79
667
- 80
668
- 81
669
- 82
670
- 83
671
- 84
672
- 85
673
- 86
674
- 87
675
- 88
676
- 89
677
- 90
678
- 91
679
- 92
680
- 93
681
- 94
682
- 95
683
- 96
684
- 97
685
- 98
686
- 99
687
- 100
688
- 101
689
- 102
690
- 103
691
- 104
692
- 105
693
- 106
694
- 107
695
- 108
696
- 109
697
- 110
698
- 111
699
- 112
700
- 113
701
- 114
702
- 115
703
- 116
704
- 117
705
- 118
706
- 119
707
- 120
708
- 121
709
- 122
710
- 123
711
- 124
712
- 125
713
- 126
714
- 127
715
- 128
716
- 129
717
- 130
718
- 131
719
- 132
720
- 133
721
- 134
722
- 135
723
- 136
724
- 137
725
- 138
726
- 139
727
- 140
728
- 141
729
- 142
730
- 143
731
- 144
732
- 145
733
- 146
734
- 147
735
- 148
736
- 149
737
- 150
738
- 151
739
- 152
740
- 153
741
- 154
742
- 155
743
- 156
744
- 157
745
- 158
746
- 159
747
- 160
748
- 161
749
- 162
750
- 163
751
- 164
752
- 165
753
- 166
754
- 167
755
- 168
756
- 169
757
- 170
758
- 171
759
- 172
760
- 173
761
- 174
762
- 175
763
- 176
764
- 177
765
- 178
766
- 179
767
- 180
768
- 181
769
- 182
770
- 183
771
- 184
772
- 185
773
- 186
774
- 187
775
- 188
776
- 189
777
- 190
778
- 191
779
- 192
780
- 193
781
- 194
782
- 195
783
- 196
784
- 197
785
- 198
786
- 199
787
- 200
788
- 201
789
- 202
790
- 203
791
- 204
792
- 205
793
- 206
794
- 207
795
- 208
796
- 209
797
- 210
798
- 211
799
- 212
800
- 213
801
- 214
802
- 215
803
- 216
804
- 217
805
- 218
806
- 219
807
- 220
808
- 221
809
- 222
810
- 223
811
- 224
812
- 225
813
- 226
814
- 227
815
- 228
816
- 229
817
- 230
818
- 231
819
- 232
820
- 233
821
- 234
822
- 235
823
- 236
824
- 237
825
- 238
826
- 239
827
- 240
828
- 241
829
- 242
830
- 243
831
- 244</pre>
832
- </td>
833
- <td>
834
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 16</span>
835
-
836
- <span class='kw'>class</span> <span class='const'>Reactor</span>
837
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
838
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>IO</span>
839
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
840
-
841
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:websocket</span><span class='comma'>,</span> <span class='symbol'>:server</span><span class='comma'>,</span> <span class='symbol'>:mutex</span><span class='comma'>,</span> <span class='symbol'>:channels</span>
842
-
843
- <span class='comment'># rececives a new socket connection from the server
844
- </span> <span class='comment'># and initiates a new mutex that can be used when subsribing to a channel
845
- </span> <span class='comment'>#
846
- </span> <span class='comment'># @param [Reel::WebSocket] websocket
847
- </span> <span class='comment'>#
848
- </span> <span class='comment'># @return [void]
849
- </span> <span class='comment'>#
850
- </span> <span class='comment'># @api public
851
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_work'>work</span><span class='lparen'>(</span><span class='id identifier rubyid_websocket'>websocket</span><span class='comma'>,</span> <span class='id identifier rubyid_server'>server</span><span class='rparen'>)</span>
852
- <span class='ivar'>@server</span> <span class='op'>=</span> <span class='id identifier rubyid_server'>server</span>
853
- <span class='ivar'>@mutex</span> <span class='op'>=</span> <span class='const'>Mutex</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
854
- <span class='ivar'>@channels</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
855
- <span class='ivar'>@websocket</span> <span class='op'>=</span> <span class='id identifier rubyid_websocket'>websocket</span>
856
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Streaming changes for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
857
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span>
858
- <span class='kw'>end</span>
859
-
860
- <span class='comment'># reads from the socket the message
861
- </span> <span class='comment'># and dispatches it to the handle_websocket_message method
862
- </span> <span class='comment'># @see #handle_websocket_message
863
- </span> <span class='comment'>#
864
- </span> <span class='comment'># @return [void]
865
- </span> <span class='comment'>#
866
- </span> <span class='comment'># @api public
867
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span>
868
- <span class='kw'>while</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span>
869
- <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
870
- <span class='kw'>end</span>
871
- <span class='kw'>end</span>
872
-
873
- <span class='comment'># method used to parse a JSON object into a Hash object
874
- </span> <span class='comment'>#
875
- </span> <span class='comment'># @param [JSON] message
876
- </span> <span class='comment'>#
877
- </span> <span class='comment'># @return [Hash]
878
- </span> <span class='comment'>#
879
- </span> <span class='comment'># @api public
880
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
881
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor read message </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
882
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='kw'>nil</span>
883
- <span class='kw'>begin</span>
884
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
885
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
886
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor could not parse </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_content'> because of </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
887
- <span class='comment'># do nothing
888
- </span> <span class='kw'>end</span>
889
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
890
- <span class='id identifier rubyid_json_data'>json_data</span>
891
- <span class='kw'>end</span>
892
-
893
- <span class='comment'># method that handles the message received from the websocket connection
894
- </span> <span class='comment'># first will try to parse the message {#parse_json_data} and then it will dispatch
895
- </span> <span class='comment'># it to another method that will decide depending the message what action
896
- </span> <span class='comment'># should the reactor take {#handle_parsed_websocket_message}
897
- </span> <span class='comment'>#
898
- </span> <span class='comment'># @see #parse_json_data
899
- </span> <span class='comment'># @see #handle_parsed_websocket_message
900
- </span> <span class='comment'>#
901
- </span> <span class='comment'># @param [JSON] message
902
- </span> <span class='comment'>#
903
- </span> <span class='comment'># @return [void]
904
- </span> <span class='comment'>#
905
- </span> <span class='comment'># @api public
906
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
907
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
908
- <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
909
- <span class='kw'>end</span>
910
-
911
- <span class='comment'># method that checks if the data is a Hash
912
- </span> <span class='comment'>#
913
- </span> <span class='comment'># if the data is a hash then will stringify the keys and will call the method {#delegate_action}
914
- </span> <span class='comment'># that will handle the message, otherwise will call the method {#handle_unknown_action}
915
- </span> <span class='comment'>#
916
- </span> <span class='comment'># @see #delegate_action
917
- </span> <span class='comment'># @see #handle_unknown_action
918
- </span> <span class='comment'>#
919
- </span> <span class='comment'># @param [Hash] json_data
920
- </span> <span class='comment'>#
921
- </span> <span class='comment'># @return [void]
922
- </span> <span class='comment'>#
923
- </span> <span class='comment'># @api public
924
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
925
- <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
926
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys'>stringify_keys</span>
927
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor finds actions for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
928
- <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
929
- <span class='kw'>else</span>
930
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
931
- <span class='kw'>end</span>
932
- <span class='kw'>end</span>
933
-
934
- <span class='comment'># method that checks if the data is a Hash
935
- </span> <span class='comment'>#
936
- </span> <span class='comment'># if the data is a hash then will stringify the keys and will call the method {#delegate_action}
937
- </span> <span class='comment'># that will handle the message, otherwise will call the method {#handle_unknown_action}
938
- </span> <span class='comment'>#
939
- </span> <span class='comment'># @see #delegate_action
940
- </span> <span class='comment'># @see #handle_unknown_action
941
- </span> <span class='comment'>#
942
- </span> <span class='comment'># @param [Hash] json_data
943
- </span> <span class='comment'># @option json_data [String] :client_action The action based on which the reactor will decide what action should make
944
- </span> <span class='comment'>#
945
- </span> <span class='comment'># Possible values are:
946
- </span> <span class='comment'># unsubscribe_client
947
- </span> <span class='comment'># unsubscribe
948
- </span> <span class='comment'># subscribe
949
- </span> <span class='comment'># publish
950
- </span> <span class='comment'>#
951
- </span> <span class='comment'>#
952
- </span> <span class='comment'># @return [void]
953
- </span> <span class='comment'>#
954
- </span> <span class='comment'># @api public
955
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
956
- <span class='kw'>case</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span>
957
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe_all</span><span class='tstring_end'>&#39;</span></span>
958
- <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
959
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe</span><span class='tstring_end'>&#39;</span></span>
960
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='rparen'>)</span>
961
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span>
962
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
963
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span>
964
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_publish_event'>publish_event</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
965
- <span class='kw'>else</span>
966
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
967
- <span class='kw'>end</span>
968
- <span class='kw'>end</span>
969
-
970
- <span class='comment'># the method will delegate the message to the server in an asyncronous way by sending the current actor and the message
971
- </span> <span class='comment'># @see {CelluloidPubsub::WebServer#handle_dispatched_message}
972
- </span> <span class='comment'>#
973
- </span> <span class='comment'># @param [Hash] json_data
974
- </span> <span class='comment'>#
975
- </span> <span class='comment'># @return [void]
976
- </span> <span class='comment'>#
977
- </span> <span class='comment'># @api public
978
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
979
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Trying to dispatch to server </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
980
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_handle_dispatched_message'>handle_dispatched_message</span><span class='lparen'>(</span><span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
981
- <span class='kw'>end</span>
982
-
983
- <span class='comment'># the method will unsubscribe a client by closing the websocket connection if has unscribed from all channels
984
- </span> <span class='comment'># and deleting the reactor from the channel list on the server
985
- </span> <span class='comment'>#
986
- </span> <span class='comment'># @param [String] channel
987
- </span> <span class='comment'>#
988
- </span> <span class='comment'># @return [void]
989
- </span> <span class='comment'>#
990
- </span> <span class='comment'># @api public
991
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
992
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
993
- <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
994
- <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
995
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_delete_if'>delete_if</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
996
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
997
- <span class='kw'>end</span>
998
- <span class='kw'>end</span>
999
-
1000
- <span class='comment'># the method will terminate the current actor
1001
- </span> <span class='comment'>#
1002
- </span> <span class='comment'>#
1003
- </span> <span class='comment'># @return [void]
1004
- </span> <span class='comment'>#
1005
- </span> <span class='comment'># @api public
1006
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_shutdown'>shutdown</span>
1007
- <span class='id identifier rubyid_terminate'>terminate</span>
1008
- <span class='kw'>end</span>
1009
-
1010
- <span class='comment'># this method will add the current actor to the list of the subscribers {#add_subscriber_to_channel}
1011
- </span> <span class='comment'># and will write to the socket a message for succesful subscription
1012
- </span> <span class='comment'>#
1013
- </span> <span class='comment'># @see #add_subscriber_to_channel
1014
- </span> <span class='comment'>#
1015
- </span> <span class='comment'># @param [String] channel
1016
- </span> <span class='comment'># @param [Object] message
1017
- </span> <span class='comment'>#
1018
- </span> <span class='comment'># @return [void]
1019
- </span> <span class='comment'>#
1020
- </span> <span class='comment'># @api public
1021
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1022
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
1023
- <span class='kw'>begin</span>
1024
- <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1025
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Subscribed to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> with </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1026
- <span class='ivar'>@websocket</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>successful_subscription</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
1027
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
1028
- <span class='id identifier rubyid_raise'>raise</span> <span class='lbracket'>[</span><span class='id identifier rubyid_e'>e</span><span class='comma'>,</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:backtrace</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_backtrace'>backtrace</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span>
1029
- <span class='kw'>end</span>
1030
- <span class='kw'>end</span>
1031
-
1032
- <span class='comment'># adds the curent actor the list of the subscribers for a particular channel
1033
- </span> <span class='comment'># and registers the new channel
1034
- </span> <span class='comment'>#
1035
- </span> <span class='comment'># @param [String] channel
1036
- </span> <span class='comment'># @param [Object] message
1037
- </span> <span class='comment'>#
1038
- </span> <span class='comment'># @return [void]
1039
- </span> <span class='comment'>#
1040
- </span> <span class='comment'># @api public
1041
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1042
- <span class='ivar'>@channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span>
1043
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='kw'>unless</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
1044
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
1045
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>&lt;&lt;</span> <span class='lbrace'>{</span> <span class='label'>reactor:</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span> <span class='rbrace'>}</span>
1046
- <span class='kw'>end</span>
1047
-
1048
- <span class='comment'># unsubscribes all actors from all channels and terminates the curent actor
1049
- </span> <span class='comment'>#
1050
- </span> <span class='comment'># @return [void]
1051
- </span> <span class='comment'>#
1052
- </span> <span class='comment'># @api public
1053
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
1054
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_channel'>channel</span><span class='op'>|</span>
1055
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
1056
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
1057
- <span class='kw'>end</span>
1058
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
1059
- <span class='kw'>end</span>
1060
-
1061
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>clearing connections</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1062
- <span class='id identifier rubyid_shutdown'>shutdown</span>
1063
- <span class='kw'>end</span>
1064
- <span class='kw'>end</span></pre>
1065
- </td>
1066
- </tr>
1067
- </table>
1068
- </div>
1069
-
1070
-
1071
- <span id="mutex=-instance_method"></span>
1072
- <div class="method_details ">
1073
- <h3 class="signature " id="mutex-instance_method">
1074
-
1075
- - (<tt>Mutex</tt>) <strong>mutex</strong>
1076
-
1077
-
1078
-
1079
-
1080
-
1081
- </h3><div class="docstring">
1082
- <div class="discussion">
1083
-
1084
- <p>Returns mutex used to lock when subscribing to a channel</p>
1085
-
1086
-
1087
- </div>
1088
- </div>
1089
- <div class="tags">
1090
-
1091
- <p class="tag_title">Returns:</p>
1092
- <ul class="return">
1093
-
1094
- <li>
1095
-
1096
-
1097
- <span class='type'>(<tt>Mutex</tt>)</span>
1098
-
1099
-
1100
-
1101
- &mdash;
1102
- <div class='inline'>
1103
- <p>mutex used to lock when subscribing to a channel</p>
1104
- </div>
1105
-
1106
- </li>
1107
-
1108
- </ul>
1109
-
1110
- </div><table class="source_code">
1111
- <tr>
1112
- <td>
1113
- <pre class="lines">
1114
-
1115
-
1116
- 16
1117
- 17
1118
- 18
1119
- 19
1120
- 20
1121
- 21
1122
- 22
1123
- 23
1124
- 24
1125
- 25
1126
- 26
1127
- 27
1128
- 28
1129
- 29
1130
- 30
1131
- 31
1132
- 32
1133
- 33
1134
- 34
1135
- 35
1136
- 36
1137
- 37
1138
- 38
1139
- 39
1140
- 40
1141
- 41
1142
- 42
1143
- 43
1144
- 44
1145
- 45
1146
- 46
1147
- 47
1148
- 48
1149
- 49
1150
- 50
1151
- 51
1152
- 52
1153
- 53
1154
- 54
1155
- 55
1156
- 56
1157
- 57
1158
- 58
1159
- 59
1160
- 60
1161
- 61
1162
- 62
1163
- 63
1164
- 64
1165
- 65
1166
- 66
1167
- 67
1168
- 68
1169
- 69
1170
- 70
1171
- 71
1172
- 72
1173
- 73
1174
- 74
1175
- 75
1176
- 76
1177
- 77
1178
- 78
1179
- 79
1180
- 80
1181
- 81
1182
- 82
1183
- 83
1184
- 84
1185
- 85
1186
- 86
1187
- 87
1188
- 88
1189
- 89
1190
- 90
1191
- 91
1192
- 92
1193
- 93
1194
- 94
1195
- 95
1196
- 96
1197
- 97
1198
- 98
1199
- 99
1200
- 100
1201
- 101
1202
- 102
1203
- 103
1204
- 104
1205
- 105
1206
- 106
1207
- 107
1208
- 108
1209
- 109
1210
- 110
1211
- 111
1212
- 112
1213
- 113
1214
- 114
1215
- 115
1216
- 116
1217
- 117
1218
- 118
1219
- 119
1220
- 120
1221
- 121
1222
- 122
1223
- 123
1224
- 124
1225
- 125
1226
- 126
1227
- 127
1228
- 128
1229
- 129
1230
- 130
1231
- 131
1232
- 132
1233
- 133
1234
- 134
1235
- 135
1236
- 136
1237
- 137
1238
- 138
1239
- 139
1240
- 140
1241
- 141
1242
- 142
1243
- 143
1244
- 144
1245
- 145
1246
- 146
1247
- 147
1248
- 148
1249
- 149
1250
- 150
1251
- 151
1252
- 152
1253
- 153
1254
- 154
1255
- 155
1256
- 156
1257
- 157
1258
- 158
1259
- 159
1260
- 160
1261
- 161
1262
- 162
1263
- 163
1264
- 164
1265
- 165
1266
- 166
1267
- 167
1268
- 168
1269
- 169
1270
- 170
1271
- 171
1272
- 172
1273
- 173
1274
- 174
1275
- 175
1276
- 176
1277
- 177
1278
- 178
1279
- 179
1280
- 180
1281
- 181
1282
- 182
1283
- 183
1284
- 184
1285
- 185
1286
- 186
1287
- 187
1288
- 188
1289
- 189
1290
- 190
1291
- 191
1292
- 192
1293
- 193
1294
- 194
1295
- 195
1296
- 196
1297
- 197
1298
- 198
1299
- 199
1300
- 200
1301
- 201
1302
- 202
1303
- 203
1304
- 204
1305
- 205
1306
- 206
1307
- 207
1308
- 208
1309
- 209
1310
- 210
1311
- 211
1312
- 212
1313
- 213
1314
- 214
1315
- 215
1316
- 216
1317
- 217
1318
- 218
1319
- 219
1320
- 220
1321
- 221
1322
- 222
1323
- 223
1324
- 224
1325
- 225
1326
- 226
1327
- 227
1328
- 228
1329
- 229
1330
- 230
1331
- 231
1332
- 232
1333
- 233
1334
- 234
1335
- 235
1336
- 236
1337
- 237
1338
- 238
1339
- 239
1340
- 240
1341
- 241
1342
- 242
1343
- 243
1344
- 244</pre>
1345
- </td>
1346
- <td>
1347
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 16</span>
1348
-
1349
- <span class='kw'>class</span> <span class='const'>Reactor</span>
1350
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
1351
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>IO</span>
1352
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
1353
-
1354
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:websocket</span><span class='comma'>,</span> <span class='symbol'>:server</span><span class='comma'>,</span> <span class='symbol'>:mutex</span><span class='comma'>,</span> <span class='symbol'>:channels</span>
1355
-
1356
- <span class='comment'># rececives a new socket connection from the server
1357
- </span> <span class='comment'># and initiates a new mutex that can be used when subsribing to a channel
1358
- </span> <span class='comment'>#
1359
- </span> <span class='comment'># @param [Reel::WebSocket] websocket
1360
- </span> <span class='comment'>#
1361
- </span> <span class='comment'># @return [void]
1362
- </span> <span class='comment'>#
1363
- </span> <span class='comment'># @api public
1364
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_work'>work</span><span class='lparen'>(</span><span class='id identifier rubyid_websocket'>websocket</span><span class='comma'>,</span> <span class='id identifier rubyid_server'>server</span><span class='rparen'>)</span>
1365
- <span class='ivar'>@server</span> <span class='op'>=</span> <span class='id identifier rubyid_server'>server</span>
1366
- <span class='ivar'>@mutex</span> <span class='op'>=</span> <span class='const'>Mutex</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
1367
- <span class='ivar'>@channels</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
1368
- <span class='ivar'>@websocket</span> <span class='op'>=</span> <span class='id identifier rubyid_websocket'>websocket</span>
1369
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Streaming changes for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1370
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span>
1371
- <span class='kw'>end</span>
1372
-
1373
- <span class='comment'># reads from the socket the message
1374
- </span> <span class='comment'># and dispatches it to the handle_websocket_message method
1375
- </span> <span class='comment'># @see #handle_websocket_message
1376
- </span> <span class='comment'>#
1377
- </span> <span class='comment'># @return [void]
1378
- </span> <span class='comment'>#
1379
- </span> <span class='comment'># @api public
1380
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span>
1381
- <span class='kw'>while</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span>
1382
- <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1383
- <span class='kw'>end</span>
1384
- <span class='kw'>end</span>
1385
-
1386
- <span class='comment'># method used to parse a JSON object into a Hash object
1387
- </span> <span class='comment'>#
1388
- </span> <span class='comment'># @param [JSON] message
1389
- </span> <span class='comment'>#
1390
- </span> <span class='comment'># @return [Hash]
1391
- </span> <span class='comment'>#
1392
- </span> <span class='comment'># @api public
1393
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1394
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor read message </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1395
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='kw'>nil</span>
1396
- <span class='kw'>begin</span>
1397
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1398
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
1399
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor could not parse </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_content'> because of </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1400
- <span class='comment'># do nothing
1401
- </span> <span class='kw'>end</span>
1402
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
1403
- <span class='id identifier rubyid_json_data'>json_data</span>
1404
- <span class='kw'>end</span>
1405
-
1406
- <span class='comment'># method that handles the message received from the websocket connection
1407
- </span> <span class='comment'># first will try to parse the message {#parse_json_data} and then it will dispatch
1408
- </span> <span class='comment'># it to another method that will decide depending the message what action
1409
- </span> <span class='comment'># should the reactor take {#handle_parsed_websocket_message}
1410
- </span> <span class='comment'>#
1411
- </span> <span class='comment'># @see #parse_json_data
1412
- </span> <span class='comment'># @see #handle_parsed_websocket_message
1413
- </span> <span class='comment'>#
1414
- </span> <span class='comment'># @param [JSON] message
1415
- </span> <span class='comment'>#
1416
- </span> <span class='comment'># @return [void]
1417
- </span> <span class='comment'>#
1418
- </span> <span class='comment'># @api public
1419
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1420
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1421
- <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1422
- <span class='kw'>end</span>
1423
-
1424
- <span class='comment'># method that checks if the data is a Hash
1425
- </span> <span class='comment'>#
1426
- </span> <span class='comment'># if the data is a hash then will stringify the keys and will call the method {#delegate_action}
1427
- </span> <span class='comment'># that will handle the message, otherwise will call the method {#handle_unknown_action}
1428
- </span> <span class='comment'>#
1429
- </span> <span class='comment'># @see #delegate_action
1430
- </span> <span class='comment'># @see #handle_unknown_action
1431
- </span> <span class='comment'>#
1432
- </span> <span class='comment'># @param [Hash] json_data
1433
- </span> <span class='comment'>#
1434
- </span> <span class='comment'># @return [void]
1435
- </span> <span class='comment'>#
1436
- </span> <span class='comment'># @api public
1437
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1438
- <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
1439
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys'>stringify_keys</span>
1440
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor finds actions for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1441
- <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
1442
- <span class='kw'>else</span>
1443
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1444
- <span class='kw'>end</span>
1445
- <span class='kw'>end</span>
1446
-
1447
- <span class='comment'># method that checks if the data is a Hash
1448
- </span> <span class='comment'>#
1449
- </span> <span class='comment'># if the data is a hash then will stringify the keys and will call the method {#delegate_action}
1450
- </span> <span class='comment'># that will handle the message, otherwise will call the method {#handle_unknown_action}
1451
- </span> <span class='comment'>#
1452
- </span> <span class='comment'># @see #delegate_action
1453
- </span> <span class='comment'># @see #handle_unknown_action
1454
- </span> <span class='comment'>#
1455
- </span> <span class='comment'># @param [Hash] json_data
1456
- </span> <span class='comment'># @option json_data [String] :client_action The action based on which the reactor will decide what action should make
1457
- </span> <span class='comment'>#
1458
- </span> <span class='comment'># Possible values are:
1459
- </span> <span class='comment'># unsubscribe_client
1460
- </span> <span class='comment'># unsubscribe
1461
- </span> <span class='comment'># subscribe
1462
- </span> <span class='comment'># publish
1463
- </span> <span class='comment'>#
1464
- </span> <span class='comment'>#
1465
- </span> <span class='comment'># @return [void]
1466
- </span> <span class='comment'>#
1467
- </span> <span class='comment'># @api public
1468
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1469
- <span class='kw'>case</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span>
1470
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe_all</span><span class='tstring_end'>&#39;</span></span>
1471
- <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
1472
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe</span><span class='tstring_end'>&#39;</span></span>
1473
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='rparen'>)</span>
1474
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span>
1475
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1476
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span>
1477
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_publish_event'>publish_event</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
1478
- <span class='kw'>else</span>
1479
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1480
- <span class='kw'>end</span>
1481
- <span class='kw'>end</span>
1482
-
1483
- <span class='comment'># the method will delegate the message to the server in an asyncronous way by sending the current actor and the message
1484
- </span> <span class='comment'># @see {CelluloidPubsub::WebServer#handle_dispatched_message}
1485
- </span> <span class='comment'>#
1486
- </span> <span class='comment'># @param [Hash] json_data
1487
- </span> <span class='comment'>#
1488
- </span> <span class='comment'># @return [void]
1489
- </span> <span class='comment'>#
1490
- </span> <span class='comment'># @api public
1491
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1492
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Trying to dispatch to server </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1493
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_handle_dispatched_message'>handle_dispatched_message</span><span class='lparen'>(</span><span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1494
- <span class='kw'>end</span>
1495
-
1496
- <span class='comment'># the method will unsubscribe a client by closing the websocket connection if has unscribed from all channels
1497
- </span> <span class='comment'># and deleting the reactor from the channel list on the server
1498
- </span> <span class='comment'>#
1499
- </span> <span class='comment'># @param [String] channel
1500
- </span> <span class='comment'>#
1501
- </span> <span class='comment'># @return [void]
1502
- </span> <span class='comment'>#
1503
- </span> <span class='comment'># @api public
1504
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
1505
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
1506
- <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
1507
- <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
1508
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_delete_if'>delete_if</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
1509
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
1510
- <span class='kw'>end</span>
1511
- <span class='kw'>end</span>
1512
-
1513
- <span class='comment'># the method will terminate the current actor
1514
- </span> <span class='comment'>#
1515
- </span> <span class='comment'>#
1516
- </span> <span class='comment'># @return [void]
1517
- </span> <span class='comment'>#
1518
- </span> <span class='comment'># @api public
1519
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_shutdown'>shutdown</span>
1520
- <span class='id identifier rubyid_terminate'>terminate</span>
1521
- <span class='kw'>end</span>
1522
-
1523
- <span class='comment'># this method will add the current actor to the list of the subscribers {#add_subscriber_to_channel}
1524
- </span> <span class='comment'># and will write to the socket a message for succesful subscription
1525
- </span> <span class='comment'>#
1526
- </span> <span class='comment'># @see #add_subscriber_to_channel
1527
- </span> <span class='comment'>#
1528
- </span> <span class='comment'># @param [String] channel
1529
- </span> <span class='comment'># @param [Object] message
1530
- </span> <span class='comment'>#
1531
- </span> <span class='comment'># @return [void]
1532
- </span> <span class='comment'>#
1533
- </span> <span class='comment'># @api public
1534
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1535
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
1536
- <span class='kw'>begin</span>
1537
- <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1538
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Subscribed to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> with </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1539
- <span class='ivar'>@websocket</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>successful_subscription</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
1540
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
1541
- <span class='id identifier rubyid_raise'>raise</span> <span class='lbracket'>[</span><span class='id identifier rubyid_e'>e</span><span class='comma'>,</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:backtrace</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_backtrace'>backtrace</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span>
1542
- <span class='kw'>end</span>
1543
- <span class='kw'>end</span>
1544
-
1545
- <span class='comment'># adds the curent actor the list of the subscribers for a particular channel
1546
- </span> <span class='comment'># and registers the new channel
1547
- </span> <span class='comment'>#
1548
- </span> <span class='comment'># @param [String] channel
1549
- </span> <span class='comment'># @param [Object] message
1550
- </span> <span class='comment'>#
1551
- </span> <span class='comment'># @return [void]
1552
- </span> <span class='comment'>#
1553
- </span> <span class='comment'># @api public
1554
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1555
- <span class='ivar'>@channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span>
1556
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='kw'>unless</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
1557
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
1558
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>&lt;&lt;</span> <span class='lbrace'>{</span> <span class='label'>reactor:</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span> <span class='rbrace'>}</span>
1559
- <span class='kw'>end</span>
1560
-
1561
- <span class='comment'># unsubscribes all actors from all channels and terminates the curent actor
1562
- </span> <span class='comment'>#
1563
- </span> <span class='comment'># @return [void]
1564
- </span> <span class='comment'>#
1565
- </span> <span class='comment'># @api public
1566
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
1567
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_channel'>channel</span><span class='op'>|</span>
1568
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
1569
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
1570
- <span class='kw'>end</span>
1571
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
1572
- <span class='kw'>end</span>
1573
-
1574
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>clearing connections</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1575
- <span class='id identifier rubyid_shutdown'>shutdown</span>
1576
- <span class='kw'>end</span>
1577
- <span class='kw'>end</span></pre>
1578
- </td>
1579
- </tr>
1580
- </table>
1581
- </div>
1582
-
1583
-
1584
- <span id="server=-instance_method"></span>
1585
- <div class="method_details ">
1586
- <h3 class="signature " id="server-instance_method">
1587
-
1588
- - (<tt>CelluloidPubsub::Webserver</tt>) <strong>server</strong>
1589
-
1590
-
1591
-
1592
-
1593
-
1594
- </h3><div class="docstring">
1595
- <div class="discussion">
1596
-
1597
- <p>Returns the server actor to which the reactor is connected to</p>
1598
-
1599
-
1600
- </div>
1601
- </div>
1602
- <div class="tags">
1603
-
1604
- <p class="tag_title">Returns:</p>
1605
- <ul class="return">
1606
-
1607
- <li>
1608
-
1609
-
1610
- <span class='type'>(<tt>CelluloidPubsub::Webserver</tt>)</span>
1611
-
1612
-
1613
-
1614
- &mdash;
1615
- <div class='inline'>
1616
- <p>the server actor to which the reactor is connected to</p>
1617
- </div>
1618
-
1619
- </li>
1620
-
1621
- </ul>
1622
-
1623
- </div><table class="source_code">
1624
- <tr>
1625
- <td>
1626
- <pre class="lines">
1627
-
1628
-
1629
- 16
1630
- 17
1631
- 18
1632
- 19
1633
- 20
1634
- 21
1635
- 22
1636
- 23
1637
- 24
1638
- 25
1639
- 26
1640
- 27
1641
- 28
1642
- 29
1643
- 30
1644
- 31
1645
- 32
1646
- 33
1647
- 34
1648
- 35
1649
- 36
1650
- 37
1651
- 38
1652
- 39
1653
- 40
1654
- 41
1655
- 42
1656
- 43
1657
- 44
1658
- 45
1659
- 46
1660
- 47
1661
- 48
1662
- 49
1663
- 50
1664
- 51
1665
- 52
1666
- 53
1667
- 54
1668
- 55
1669
- 56
1670
- 57
1671
- 58
1672
- 59
1673
- 60
1674
- 61
1675
- 62
1676
- 63
1677
- 64
1678
- 65
1679
- 66
1680
- 67
1681
- 68
1682
- 69
1683
- 70
1684
- 71
1685
- 72
1686
- 73
1687
- 74
1688
- 75
1689
- 76
1690
- 77
1691
- 78
1692
- 79
1693
- 80
1694
- 81
1695
- 82
1696
- 83
1697
- 84
1698
- 85
1699
- 86
1700
- 87
1701
- 88
1702
- 89
1703
- 90
1704
- 91
1705
- 92
1706
- 93
1707
- 94
1708
- 95
1709
- 96
1710
- 97
1711
- 98
1712
- 99
1713
- 100
1714
- 101
1715
- 102
1716
- 103
1717
- 104
1718
- 105
1719
- 106
1720
- 107
1721
- 108
1722
- 109
1723
- 110
1724
- 111
1725
- 112
1726
- 113
1727
- 114
1728
- 115
1729
- 116
1730
- 117
1731
- 118
1732
- 119
1733
- 120
1734
- 121
1735
- 122
1736
- 123
1737
- 124
1738
- 125
1739
- 126
1740
- 127
1741
- 128
1742
- 129
1743
- 130
1744
- 131
1745
- 132
1746
- 133
1747
- 134
1748
- 135
1749
- 136
1750
- 137
1751
- 138
1752
- 139
1753
- 140
1754
- 141
1755
- 142
1756
- 143
1757
- 144
1758
- 145
1759
- 146
1760
- 147
1761
- 148
1762
- 149
1763
- 150
1764
- 151
1765
- 152
1766
- 153
1767
- 154
1768
- 155
1769
- 156
1770
- 157
1771
- 158
1772
- 159
1773
- 160
1774
- 161
1775
- 162
1776
- 163
1777
- 164
1778
- 165
1779
- 166
1780
- 167
1781
- 168
1782
- 169
1783
- 170
1784
- 171
1785
- 172
1786
- 173
1787
- 174
1788
- 175
1789
- 176
1790
- 177
1791
- 178
1792
- 179
1793
- 180
1794
- 181
1795
- 182
1796
- 183
1797
- 184
1798
- 185
1799
- 186
1800
- 187
1801
- 188
1802
- 189
1803
- 190
1804
- 191
1805
- 192
1806
- 193
1807
- 194
1808
- 195
1809
- 196
1810
- 197
1811
- 198
1812
- 199
1813
- 200
1814
- 201
1815
- 202
1816
- 203
1817
- 204
1818
- 205
1819
- 206
1820
- 207
1821
- 208
1822
- 209
1823
- 210
1824
- 211
1825
- 212
1826
- 213
1827
- 214
1828
- 215
1829
- 216
1830
- 217
1831
- 218
1832
- 219
1833
- 220
1834
- 221
1835
- 222
1836
- 223
1837
- 224
1838
- 225
1839
- 226
1840
- 227
1841
- 228
1842
- 229
1843
- 230
1844
- 231
1845
- 232
1846
- 233
1847
- 234
1848
- 235
1849
- 236
1850
- 237
1851
- 238
1852
- 239
1853
- 240
1854
- 241
1855
- 242
1856
- 243
1857
- 244</pre>
1858
- </td>
1859
- <td>
1860
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 16</span>
1861
-
1862
- <span class='kw'>class</span> <span class='const'>Reactor</span>
1863
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
1864
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>IO</span>
1865
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
1866
-
1867
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:websocket</span><span class='comma'>,</span> <span class='symbol'>:server</span><span class='comma'>,</span> <span class='symbol'>:mutex</span><span class='comma'>,</span> <span class='symbol'>:channels</span>
1868
-
1869
- <span class='comment'># rececives a new socket connection from the server
1870
- </span> <span class='comment'># and initiates a new mutex that can be used when subsribing to a channel
1871
- </span> <span class='comment'>#
1872
- </span> <span class='comment'># @param [Reel::WebSocket] websocket
1873
- </span> <span class='comment'>#
1874
- </span> <span class='comment'># @return [void]
1875
- </span> <span class='comment'>#
1876
- </span> <span class='comment'># @api public
1877
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_work'>work</span><span class='lparen'>(</span><span class='id identifier rubyid_websocket'>websocket</span><span class='comma'>,</span> <span class='id identifier rubyid_server'>server</span><span class='rparen'>)</span>
1878
- <span class='ivar'>@server</span> <span class='op'>=</span> <span class='id identifier rubyid_server'>server</span>
1879
- <span class='ivar'>@mutex</span> <span class='op'>=</span> <span class='const'>Mutex</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
1880
- <span class='ivar'>@channels</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
1881
- <span class='ivar'>@websocket</span> <span class='op'>=</span> <span class='id identifier rubyid_websocket'>websocket</span>
1882
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Streaming changes for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1883
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span>
1884
- <span class='kw'>end</span>
1885
-
1886
- <span class='comment'># reads from the socket the message
1887
- </span> <span class='comment'># and dispatches it to the handle_websocket_message method
1888
- </span> <span class='comment'># @see #handle_websocket_message
1889
- </span> <span class='comment'>#
1890
- </span> <span class='comment'># @return [void]
1891
- </span> <span class='comment'>#
1892
- </span> <span class='comment'># @api public
1893
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span>
1894
- <span class='kw'>while</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span>
1895
- <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1896
- <span class='kw'>end</span>
1897
- <span class='kw'>end</span>
1898
-
1899
- <span class='comment'># method used to parse a JSON object into a Hash object
1900
- </span> <span class='comment'>#
1901
- </span> <span class='comment'># @param [JSON] message
1902
- </span> <span class='comment'>#
1903
- </span> <span class='comment'># @return [Hash]
1904
- </span> <span class='comment'>#
1905
- </span> <span class='comment'># @api public
1906
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1907
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor read message </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1908
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='kw'>nil</span>
1909
- <span class='kw'>begin</span>
1910
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1911
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
1912
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor could not parse </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_content'> because of </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1913
- <span class='comment'># do nothing
1914
- </span> <span class='kw'>end</span>
1915
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
1916
- <span class='id identifier rubyid_json_data'>json_data</span>
1917
- <span class='kw'>end</span>
1918
-
1919
- <span class='comment'># method that handles the message received from the websocket connection
1920
- </span> <span class='comment'># first will try to parse the message {#parse_json_data} and then it will dispatch
1921
- </span> <span class='comment'># it to another method that will decide depending the message what action
1922
- </span> <span class='comment'># should the reactor take {#handle_parsed_websocket_message}
1923
- </span> <span class='comment'>#
1924
- </span> <span class='comment'># @see #parse_json_data
1925
- </span> <span class='comment'># @see #handle_parsed_websocket_message
1926
- </span> <span class='comment'>#
1927
- </span> <span class='comment'># @param [JSON] message
1928
- </span> <span class='comment'>#
1929
- </span> <span class='comment'># @return [void]
1930
- </span> <span class='comment'>#
1931
- </span> <span class='comment'># @api public
1932
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1933
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1934
- <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1935
- <span class='kw'>end</span>
1936
-
1937
- <span class='comment'># method that checks if the data is a Hash
1938
- </span> <span class='comment'>#
1939
- </span> <span class='comment'># if the data is a hash then will stringify the keys and will call the method {#delegate_action}
1940
- </span> <span class='comment'># that will handle the message, otherwise will call the method {#handle_unknown_action}
1941
- </span> <span class='comment'>#
1942
- </span> <span class='comment'># @see #delegate_action
1943
- </span> <span class='comment'># @see #handle_unknown_action
1944
- </span> <span class='comment'>#
1945
- </span> <span class='comment'># @param [Hash] json_data
1946
- </span> <span class='comment'>#
1947
- </span> <span class='comment'># @return [void]
1948
- </span> <span class='comment'>#
1949
- </span> <span class='comment'># @api public
1950
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1951
- <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
1952
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys'>stringify_keys</span>
1953
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor finds actions for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1954
- <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
1955
- <span class='kw'>else</span>
1956
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1957
- <span class='kw'>end</span>
1958
- <span class='kw'>end</span>
1959
-
1960
- <span class='comment'># method that checks if the data is a Hash
1961
- </span> <span class='comment'>#
1962
- </span> <span class='comment'># if the data is a hash then will stringify the keys and will call the method {#delegate_action}
1963
- </span> <span class='comment'># that will handle the message, otherwise will call the method {#handle_unknown_action}
1964
- </span> <span class='comment'>#
1965
- </span> <span class='comment'># @see #delegate_action
1966
- </span> <span class='comment'># @see #handle_unknown_action
1967
- </span> <span class='comment'>#
1968
- </span> <span class='comment'># @param [Hash] json_data
1969
- </span> <span class='comment'># @option json_data [String] :client_action The action based on which the reactor will decide what action should make
1970
- </span> <span class='comment'>#
1971
- </span> <span class='comment'># Possible values are:
1972
- </span> <span class='comment'># unsubscribe_client
1973
- </span> <span class='comment'># unsubscribe
1974
- </span> <span class='comment'># subscribe
1975
- </span> <span class='comment'># publish
1976
- </span> <span class='comment'>#
1977
- </span> <span class='comment'>#
1978
- </span> <span class='comment'># @return [void]
1979
- </span> <span class='comment'>#
1980
- </span> <span class='comment'># @api public
1981
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1982
- <span class='kw'>case</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span>
1983
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe_all</span><span class='tstring_end'>&#39;</span></span>
1984
- <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
1985
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe</span><span class='tstring_end'>&#39;</span></span>
1986
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='rparen'>)</span>
1987
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span>
1988
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1989
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span>
1990
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_publish_event'>publish_event</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
1991
- <span class='kw'>else</span>
1992
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
1993
- <span class='kw'>end</span>
1994
- <span class='kw'>end</span>
1995
-
1996
- <span class='comment'># the method will delegate the message to the server in an asyncronous way by sending the current actor and the message
1997
- </span> <span class='comment'># @see {CelluloidPubsub::WebServer#handle_dispatched_message}
1998
- </span> <span class='comment'>#
1999
- </span> <span class='comment'># @param [Hash] json_data
2000
- </span> <span class='comment'>#
2001
- </span> <span class='comment'># @return [void]
2002
- </span> <span class='comment'>#
2003
- </span> <span class='comment'># @api public
2004
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2005
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Trying to dispatch to server </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2006
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_handle_dispatched_message'>handle_dispatched_message</span><span class='lparen'>(</span><span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2007
- <span class='kw'>end</span>
2008
-
2009
- <span class='comment'># the method will unsubscribe a client by closing the websocket connection if has unscribed from all channels
2010
- </span> <span class='comment'># and deleting the reactor from the channel list on the server
2011
- </span> <span class='comment'>#
2012
- </span> <span class='comment'># @param [String] channel
2013
- </span> <span class='comment'>#
2014
- </span> <span class='comment'># @return [void]
2015
- </span> <span class='comment'>#
2016
- </span> <span class='comment'># @api public
2017
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2018
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
2019
- <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2020
- <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
2021
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_delete_if'>delete_if</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
2022
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
2023
- <span class='kw'>end</span>
2024
- <span class='kw'>end</span>
2025
-
2026
- <span class='comment'># the method will terminate the current actor
2027
- </span> <span class='comment'>#
2028
- </span> <span class='comment'>#
2029
- </span> <span class='comment'># @return [void]
2030
- </span> <span class='comment'>#
2031
- </span> <span class='comment'># @api public
2032
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_shutdown'>shutdown</span>
2033
- <span class='id identifier rubyid_terminate'>terminate</span>
2034
- <span class='kw'>end</span>
2035
-
2036
- <span class='comment'># this method will add the current actor to the list of the subscribers {#add_subscriber_to_channel}
2037
- </span> <span class='comment'># and will write to the socket a message for succesful subscription
2038
- </span> <span class='comment'>#
2039
- </span> <span class='comment'># @see #add_subscriber_to_channel
2040
- </span> <span class='comment'>#
2041
- </span> <span class='comment'># @param [String] channel
2042
- </span> <span class='comment'># @param [Object] message
2043
- </span> <span class='comment'>#
2044
- </span> <span class='comment'># @return [void]
2045
- </span> <span class='comment'>#
2046
- </span> <span class='comment'># @api public
2047
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2048
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
2049
- <span class='kw'>begin</span>
2050
- <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2051
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Subscribed to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> with </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2052
- <span class='ivar'>@websocket</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>successful_subscription</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
2053
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
2054
- <span class='id identifier rubyid_raise'>raise</span> <span class='lbracket'>[</span><span class='id identifier rubyid_e'>e</span><span class='comma'>,</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:backtrace</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_backtrace'>backtrace</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span>
2055
- <span class='kw'>end</span>
2056
- <span class='kw'>end</span>
2057
-
2058
- <span class='comment'># adds the curent actor the list of the subscribers for a particular channel
2059
- </span> <span class='comment'># and registers the new channel
2060
- </span> <span class='comment'>#
2061
- </span> <span class='comment'># @param [String] channel
2062
- </span> <span class='comment'># @param [Object] message
2063
- </span> <span class='comment'>#
2064
- </span> <span class='comment'># @return [void]
2065
- </span> <span class='comment'>#
2066
- </span> <span class='comment'># @api public
2067
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2068
- <span class='ivar'>@channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span>
2069
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='kw'>unless</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2070
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
2071
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>&lt;&lt;</span> <span class='lbrace'>{</span> <span class='label'>reactor:</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span> <span class='rbrace'>}</span>
2072
- <span class='kw'>end</span>
2073
-
2074
- <span class='comment'># unsubscribes all actors from all channels and terminates the curent actor
2075
- </span> <span class='comment'>#
2076
- </span> <span class='comment'># @return [void]
2077
- </span> <span class='comment'>#
2078
- </span> <span class='comment'># @api public
2079
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
2080
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_channel'>channel</span><span class='op'>|</span>
2081
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
2082
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
2083
- <span class='kw'>end</span>
2084
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
2085
- <span class='kw'>end</span>
2086
-
2087
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>clearing connections</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2088
- <span class='id identifier rubyid_shutdown'>shutdown</span>
2089
- <span class='kw'>end</span>
2090
- <span class='kw'>end</span></pre>
2091
- </td>
2092
- </tr>
2093
- </table>
2094
- </div>
2095
-
2096
-
2097
- <span id="websocket=-instance_method"></span>
2098
- <div class="method_details ">
2099
- <h3 class="signature " id="websocket-instance_method">
2100
-
2101
- - (<tt>Reel::WebSocket</tt>) <strong>websocket</strong>
2102
-
2103
-
2104
-
2105
-
2106
-
2107
- </h3><div class="docstring">
2108
- <div class="discussion">
2109
-
2110
- <p>Returns websocket connection</p>
2111
-
2112
-
2113
- </div>
2114
- </div>
2115
- <div class="tags">
2116
-
2117
- <p class="tag_title">Returns:</p>
2118
- <ul class="return">
2119
-
2120
- <li>
2121
-
2122
-
2123
- <span class='type'>(<tt>Reel::WebSocket</tt>)</span>
2124
-
2125
-
2126
-
2127
- &mdash;
2128
- <div class='inline'>
2129
- <p>websocket connection</p>
2130
- </div>
2131
-
2132
- </li>
2133
-
2134
- </ul>
2135
-
2136
- </div><table class="source_code">
2137
- <tr>
2138
- <td>
2139
- <pre class="lines">
2140
-
2141
-
2142
- 16
2143
- 17
2144
- 18
2145
- 19
2146
- 20
2147
- 21
2148
- 22
2149
- 23
2150
- 24
2151
- 25
2152
- 26
2153
- 27
2154
- 28
2155
- 29
2156
- 30
2157
- 31
2158
- 32
2159
- 33
2160
- 34
2161
- 35
2162
- 36
2163
- 37
2164
- 38
2165
- 39
2166
- 40
2167
- 41
2168
- 42
2169
- 43
2170
- 44
2171
- 45
2172
- 46
2173
- 47
2174
- 48
2175
- 49
2176
- 50
2177
- 51
2178
- 52
2179
- 53
2180
- 54
2181
- 55
2182
- 56
2183
- 57
2184
- 58
2185
- 59
2186
- 60
2187
- 61
2188
- 62
2189
- 63
2190
- 64
2191
- 65
2192
- 66
2193
- 67
2194
- 68
2195
- 69
2196
- 70
2197
- 71
2198
- 72
2199
- 73
2200
- 74
2201
- 75
2202
- 76
2203
- 77
2204
- 78
2205
- 79
2206
- 80
2207
- 81
2208
- 82
2209
- 83
2210
- 84
2211
- 85
2212
- 86
2213
- 87
2214
- 88
2215
- 89
2216
- 90
2217
- 91
2218
- 92
2219
- 93
2220
- 94
2221
- 95
2222
- 96
2223
- 97
2224
- 98
2225
- 99
2226
- 100
2227
- 101
2228
- 102
2229
- 103
2230
- 104
2231
- 105
2232
- 106
2233
- 107
2234
- 108
2235
- 109
2236
- 110
2237
- 111
2238
- 112
2239
- 113
2240
- 114
2241
- 115
2242
- 116
2243
- 117
2244
- 118
2245
- 119
2246
- 120
2247
- 121
2248
- 122
2249
- 123
2250
- 124
2251
- 125
2252
- 126
2253
- 127
2254
- 128
2255
- 129
2256
- 130
2257
- 131
2258
- 132
2259
- 133
2260
- 134
2261
- 135
2262
- 136
2263
- 137
2264
- 138
2265
- 139
2266
- 140
2267
- 141
2268
- 142
2269
- 143
2270
- 144
2271
- 145
2272
- 146
2273
- 147
2274
- 148
2275
- 149
2276
- 150
2277
- 151
2278
- 152
2279
- 153
2280
- 154
2281
- 155
2282
- 156
2283
- 157
2284
- 158
2285
- 159
2286
- 160
2287
- 161
2288
- 162
2289
- 163
2290
- 164
2291
- 165
2292
- 166
2293
- 167
2294
- 168
2295
- 169
2296
- 170
2297
- 171
2298
- 172
2299
- 173
2300
- 174
2301
- 175
2302
- 176
2303
- 177
2304
- 178
2305
- 179
2306
- 180
2307
- 181
2308
- 182
2309
- 183
2310
- 184
2311
- 185
2312
- 186
2313
- 187
2314
- 188
2315
- 189
2316
- 190
2317
- 191
2318
- 192
2319
- 193
2320
- 194
2321
- 195
2322
- 196
2323
- 197
2324
- 198
2325
- 199
2326
- 200
2327
- 201
2328
- 202
2329
- 203
2330
- 204
2331
- 205
2332
- 206
2333
- 207
2334
- 208
2335
- 209
2336
- 210
2337
- 211
2338
- 212
2339
- 213
2340
- 214
2341
- 215
2342
- 216
2343
- 217
2344
- 218
2345
- 219
2346
- 220
2347
- 221
2348
- 222
2349
- 223
2350
- 224
2351
- 225
2352
- 226
2353
- 227
2354
- 228
2355
- 229
2356
- 230
2357
- 231
2358
- 232
2359
- 233
2360
- 234
2361
- 235
2362
- 236
2363
- 237
2364
- 238
2365
- 239
2366
- 240
2367
- 241
2368
- 242
2369
- 243
2370
- 244</pre>
2371
- </td>
2372
- <td>
2373
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 16</span>
2374
-
2375
- <span class='kw'>class</span> <span class='const'>Reactor</span>
2376
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
2377
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>IO</span>
2378
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
2379
-
2380
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:websocket</span><span class='comma'>,</span> <span class='symbol'>:server</span><span class='comma'>,</span> <span class='symbol'>:mutex</span><span class='comma'>,</span> <span class='symbol'>:channels</span>
2381
-
2382
- <span class='comment'># rececives a new socket connection from the server
2383
- </span> <span class='comment'># and initiates a new mutex that can be used when subsribing to a channel
2384
- </span> <span class='comment'>#
2385
- </span> <span class='comment'># @param [Reel::WebSocket] websocket
2386
- </span> <span class='comment'>#
2387
- </span> <span class='comment'># @return [void]
2388
- </span> <span class='comment'>#
2389
- </span> <span class='comment'># @api public
2390
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_work'>work</span><span class='lparen'>(</span><span class='id identifier rubyid_websocket'>websocket</span><span class='comma'>,</span> <span class='id identifier rubyid_server'>server</span><span class='rparen'>)</span>
2391
- <span class='ivar'>@server</span> <span class='op'>=</span> <span class='id identifier rubyid_server'>server</span>
2392
- <span class='ivar'>@mutex</span> <span class='op'>=</span> <span class='const'>Mutex</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
2393
- <span class='ivar'>@channels</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
2394
- <span class='ivar'>@websocket</span> <span class='op'>=</span> <span class='id identifier rubyid_websocket'>websocket</span>
2395
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Streaming changes for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2396
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span>
2397
- <span class='kw'>end</span>
2398
-
2399
- <span class='comment'># reads from the socket the message
2400
- </span> <span class='comment'># and dispatches it to the handle_websocket_message method
2401
- </span> <span class='comment'># @see #handle_websocket_message
2402
- </span> <span class='comment'>#
2403
- </span> <span class='comment'># @return [void]
2404
- </span> <span class='comment'>#
2405
- </span> <span class='comment'># @api public
2406
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span>
2407
- <span class='kw'>while</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span>
2408
- <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2409
- <span class='kw'>end</span>
2410
- <span class='kw'>end</span>
2411
-
2412
- <span class='comment'># method used to parse a JSON object into a Hash object
2413
- </span> <span class='comment'>#
2414
- </span> <span class='comment'># @param [JSON] message
2415
- </span> <span class='comment'>#
2416
- </span> <span class='comment'># @return [Hash]
2417
- </span> <span class='comment'>#
2418
- </span> <span class='comment'># @api public
2419
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2420
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor read message </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2421
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='kw'>nil</span>
2422
- <span class='kw'>begin</span>
2423
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2424
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
2425
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor could not parse </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_content'> because of </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2426
- <span class='comment'># do nothing
2427
- </span> <span class='kw'>end</span>
2428
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
2429
- <span class='id identifier rubyid_json_data'>json_data</span>
2430
- <span class='kw'>end</span>
2431
-
2432
- <span class='comment'># method that handles the message received from the websocket connection
2433
- </span> <span class='comment'># first will try to parse the message {#parse_json_data} and then it will dispatch
2434
- </span> <span class='comment'># it to another method that will decide depending the message what action
2435
- </span> <span class='comment'># should the reactor take {#handle_parsed_websocket_message}
2436
- </span> <span class='comment'>#
2437
- </span> <span class='comment'># @see #parse_json_data
2438
- </span> <span class='comment'># @see #handle_parsed_websocket_message
2439
- </span> <span class='comment'>#
2440
- </span> <span class='comment'># @param [JSON] message
2441
- </span> <span class='comment'>#
2442
- </span> <span class='comment'># @return [void]
2443
- </span> <span class='comment'>#
2444
- </span> <span class='comment'># @api public
2445
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2446
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2447
- <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2448
- <span class='kw'>end</span>
2449
-
2450
- <span class='comment'># method that checks if the data is a Hash
2451
- </span> <span class='comment'>#
2452
- </span> <span class='comment'># if the data is a hash then will stringify the keys and will call the method {#delegate_action}
2453
- </span> <span class='comment'># that will handle the message, otherwise will call the method {#handle_unknown_action}
2454
- </span> <span class='comment'>#
2455
- </span> <span class='comment'># @see #delegate_action
2456
- </span> <span class='comment'># @see #handle_unknown_action
2457
- </span> <span class='comment'>#
2458
- </span> <span class='comment'># @param [Hash] json_data
2459
- </span> <span class='comment'>#
2460
- </span> <span class='comment'># @return [void]
2461
- </span> <span class='comment'>#
2462
- </span> <span class='comment'># @api public
2463
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2464
- <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
2465
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys'>stringify_keys</span>
2466
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor finds actions for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2467
- <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
2468
- <span class='kw'>else</span>
2469
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2470
- <span class='kw'>end</span>
2471
- <span class='kw'>end</span>
2472
-
2473
- <span class='comment'># method that checks if the data is a Hash
2474
- </span> <span class='comment'>#
2475
- </span> <span class='comment'># if the data is a hash then will stringify the keys and will call the method {#delegate_action}
2476
- </span> <span class='comment'># that will handle the message, otherwise will call the method {#handle_unknown_action}
2477
- </span> <span class='comment'>#
2478
- </span> <span class='comment'># @see #delegate_action
2479
- </span> <span class='comment'># @see #handle_unknown_action
2480
- </span> <span class='comment'>#
2481
- </span> <span class='comment'># @param [Hash] json_data
2482
- </span> <span class='comment'># @option json_data [String] :client_action The action based on which the reactor will decide what action should make
2483
- </span> <span class='comment'>#
2484
- </span> <span class='comment'># Possible values are:
2485
- </span> <span class='comment'># unsubscribe_client
2486
- </span> <span class='comment'># unsubscribe
2487
- </span> <span class='comment'># subscribe
2488
- </span> <span class='comment'># publish
2489
- </span> <span class='comment'>#
2490
- </span> <span class='comment'>#
2491
- </span> <span class='comment'># @return [void]
2492
- </span> <span class='comment'>#
2493
- </span> <span class='comment'># @api public
2494
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2495
- <span class='kw'>case</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span>
2496
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe_all</span><span class='tstring_end'>&#39;</span></span>
2497
- <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
2498
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe</span><span class='tstring_end'>&#39;</span></span>
2499
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='rparen'>)</span>
2500
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span>
2501
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2502
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span>
2503
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_publish_event'>publish_event</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
2504
- <span class='kw'>else</span>
2505
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2506
- <span class='kw'>end</span>
2507
- <span class='kw'>end</span>
2508
-
2509
- <span class='comment'># the method will delegate the message to the server in an asyncronous way by sending the current actor and the message
2510
- </span> <span class='comment'># @see {CelluloidPubsub::WebServer#handle_dispatched_message}
2511
- </span> <span class='comment'>#
2512
- </span> <span class='comment'># @param [Hash] json_data
2513
- </span> <span class='comment'>#
2514
- </span> <span class='comment'># @return [void]
2515
- </span> <span class='comment'>#
2516
- </span> <span class='comment'># @api public
2517
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2518
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Trying to dispatch to server </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2519
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_handle_dispatched_message'>handle_dispatched_message</span><span class='lparen'>(</span><span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2520
- <span class='kw'>end</span>
2521
-
2522
- <span class='comment'># the method will unsubscribe a client by closing the websocket connection if has unscribed from all channels
2523
- </span> <span class='comment'># and deleting the reactor from the channel list on the server
2524
- </span> <span class='comment'>#
2525
- </span> <span class='comment'># @param [String] channel
2526
- </span> <span class='comment'>#
2527
- </span> <span class='comment'># @return [void]
2528
- </span> <span class='comment'>#
2529
- </span> <span class='comment'># @api public
2530
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2531
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
2532
- <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2533
- <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
2534
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_delete_if'>delete_if</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
2535
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
2536
- <span class='kw'>end</span>
2537
- <span class='kw'>end</span>
2538
-
2539
- <span class='comment'># the method will terminate the current actor
2540
- </span> <span class='comment'>#
2541
- </span> <span class='comment'>#
2542
- </span> <span class='comment'># @return [void]
2543
- </span> <span class='comment'>#
2544
- </span> <span class='comment'># @api public
2545
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_shutdown'>shutdown</span>
2546
- <span class='id identifier rubyid_terminate'>terminate</span>
2547
- <span class='kw'>end</span>
2548
-
2549
- <span class='comment'># this method will add the current actor to the list of the subscribers {#add_subscriber_to_channel}
2550
- </span> <span class='comment'># and will write to the socket a message for succesful subscription
2551
- </span> <span class='comment'>#
2552
- </span> <span class='comment'># @see #add_subscriber_to_channel
2553
- </span> <span class='comment'>#
2554
- </span> <span class='comment'># @param [String] channel
2555
- </span> <span class='comment'># @param [Object] message
2556
- </span> <span class='comment'>#
2557
- </span> <span class='comment'># @return [void]
2558
- </span> <span class='comment'>#
2559
- </span> <span class='comment'># @api public
2560
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2561
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
2562
- <span class='kw'>begin</span>
2563
- <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2564
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Subscribed to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> with </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2565
- <span class='ivar'>@websocket</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>successful_subscription</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
2566
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
2567
- <span class='id identifier rubyid_raise'>raise</span> <span class='lbracket'>[</span><span class='id identifier rubyid_e'>e</span><span class='comma'>,</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:backtrace</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_backtrace'>backtrace</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span>
2568
- <span class='kw'>end</span>
2569
- <span class='kw'>end</span>
2570
-
2571
- <span class='comment'># adds the curent actor the list of the subscribers for a particular channel
2572
- </span> <span class='comment'># and registers the new channel
2573
- </span> <span class='comment'>#
2574
- </span> <span class='comment'># @param [String] channel
2575
- </span> <span class='comment'># @param [Object] message
2576
- </span> <span class='comment'>#
2577
- </span> <span class='comment'># @return [void]
2578
- </span> <span class='comment'>#
2579
- </span> <span class='comment'># @api public
2580
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2581
- <span class='ivar'>@channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span>
2582
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='kw'>unless</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2583
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
2584
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>&lt;&lt;</span> <span class='lbrace'>{</span> <span class='label'>reactor:</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span> <span class='rbrace'>}</span>
2585
- <span class='kw'>end</span>
2586
-
2587
- <span class='comment'># unsubscribes all actors from all channels and terminates the curent actor
2588
- </span> <span class='comment'>#
2589
- </span> <span class='comment'># @return [void]
2590
- </span> <span class='comment'>#
2591
- </span> <span class='comment'># @api public
2592
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
2593
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_channel'>channel</span><span class='op'>|</span>
2594
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
2595
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
2596
- <span class='kw'>end</span>
2597
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
2598
- <span class='kw'>end</span>
2599
-
2600
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>clearing connections</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2601
- <span class='id identifier rubyid_shutdown'>shutdown</span>
2602
- <span class='kw'>end</span>
2603
- <span class='kw'>end</span></pre>
2604
- </td>
2605
- </tr>
2606
- </table>
2607
- </div>
2608
-
2609
- </div>
2610
-
2611
-
2612
- <div id="instance_method_details" class="method_details_list">
2613
- <h2>Instance Method Details</h2>
2614
-
2615
-
2616
- <div class="method_details first">
2617
- <h3 class="signature first" id="add_subscriber_to_channel-instance_method">
2618
-
2619
- - (<tt>void</tt>) <strong>add_subscriber_to_channel</strong>(channel, message)
2620
-
2621
-
2622
-
2623
-
2624
-
2625
- </h3><div class="docstring">
2626
- <div class="discussion">
2627
- <p class="note returns_void">This method returns an undefined value.</p>
2628
- <p>adds the curent actor the list of the subscribers for a particular channel
2629
- and registers the new channel</p>
2630
-
2631
-
2632
- </div>
2633
- </div>
2634
- <div class="tags">
2635
- <p class="tag_title">Parameters:</p>
2636
- <ul class="param">
2637
-
2638
- <li>
2639
-
2640
- <span class='name'>channel</span>
2641
-
2642
-
2643
- <span class='type'>(<tt>String</tt>)</span>
2644
-
2645
-
2646
-
2647
- </li>
2648
-
2649
- <li>
2650
-
2651
- <span class='name'>message</span>
2652
-
2653
-
2654
- <span class='type'>(<tt>Object</tt>)</span>
2655
-
2656
-
2657
-
2658
- </li>
2659
-
2660
- </ul>
2661
-
2662
-
2663
- </div><table class="source_code">
2664
- <tr>
2665
- <td>
2666
- <pre class="lines">
2667
-
2668
-
2669
- 221
2670
- 222
2671
- 223
2672
- 224
2673
- 225
2674
- 226</pre>
2675
- </td>
2676
- <td>
2677
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 221</span>
2678
-
2679
- <span class='kw'>def</span> <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2680
- <span class='ivar'>@channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span>
2681
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='kw'>unless</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2682
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
2683
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>&lt;&lt;</span> <span class='lbrace'>{</span> <span class='label'>reactor:</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span> <span class='rbrace'>}</span>
2684
- <span class='kw'>end</span></pre>
2685
- </td>
2686
- </tr>
2687
- </table>
2688
- </div>
2689
-
2690
- <div class="method_details ">
2691
- <h3 class="signature " id="delegate_action-instance_method">
2692
-
2693
- - (<tt>void</tt>) <strong>delegate_action</strong>(json_data)
2694
-
2695
-
2696
-
2697
-
2698
-
2699
- </h3><div class="docstring">
2700
- <div class="discussion">
2701
- <p class="note returns_void">This method returns an undefined value.</p>
2702
- <p>method that checks if the data is a Hash</p>
2703
-
2704
- <p>if the data is a hash then will stringify the keys and will call the method
2705
- <span class='object_link'><a href="#delegate_action-instance_method" title="CelluloidPubsub::Reactor#delegate_action (method)">#delegate_action</a></span> that will handle the message, otherwise will call the
2706
- method <span class='object_link'><a href="#handle_unknown_action-instance_method" title="CelluloidPubsub::Reactor#handle_unknown_action (method)">#handle_unknown_action</a></span></p>
2707
-
2708
-
2709
- </div>
2710
- </div>
2711
- <div class="tags">
2712
- <p class="tag_title">Parameters:</p>
2713
- <ul class="param">
2714
-
2715
- <li>
2716
-
2717
- <span class='name'>json_data</span>
2718
-
2719
-
2720
- <span class='type'>(<tt>Hash</tt>)</span>
2721
-
2722
-
2723
-
2724
- </li>
2725
-
2726
- </ul>
2727
-
2728
-
2729
-
2730
-
2731
- <p class="tag_title">Options Hash (<tt>json_data</tt>):</p>
2732
- <ul class="option">
2733
-
2734
- <li>
2735
- <span class="name">:client_action</span>
2736
- <span class="type">(<tt>String</tt>)</span>
2737
- <span class="default">
2738
-
2739
- </span>
2740
-
2741
- &mdash; <div class='inline'>
2742
- <p>The action based on which the reactor will decide what action should make</p>
2743
-
2744
- <p>Possible values are:</p>
2745
-
2746
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span>
2747
- <span class='id identifier rubyid_unsubscribe'>unsubscribe</span>
2748
- <span class='id identifier rubyid_subscribe'>subscribe</span>
2749
- <span class='id identifier rubyid_publish'>publish</span></code></pre>
2750
- </div>
2751
-
2752
- </li>
2753
-
2754
- </ul>
2755
-
2756
-
2757
-
2758
- <p class="tag_title">See Also:</p>
2759
- <ul class="see">
2760
-
2761
- <li><span class='object_link'><a href="#delegate_action-instance_method" title="CelluloidPubsub::Reactor#delegate_action (method)">#delegate_action</a></span></li>
2762
-
2763
- <li><span class='object_link'><a href="#handle_unknown_action-instance_method" title="CelluloidPubsub::Reactor#handle_unknown_action (method)">#handle_unknown_action</a></span></li>
2764
-
2765
- </ul>
2766
-
2767
- </div><table class="source_code">
2768
- <tr>
2769
- <td>
2770
- <pre class="lines">
2771
-
2772
-
2773
- 135
2774
- 136
2775
- 137
2776
- 138
2777
- 139
2778
- 140
2779
- 141
2780
- 142
2781
- 143
2782
- 144
2783
- 145
2784
- 146
2785
- 147
2786
- 148</pre>
2787
- </td>
2788
- <td>
2789
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 135</span>
2790
-
2791
- <span class='kw'>def</span> <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2792
- <span class='kw'>case</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span>
2793
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe_all</span><span class='tstring_end'>&#39;</span></span>
2794
- <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
2795
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unsubscribe</span><span class='tstring_end'>&#39;</span></span>
2796
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='rparen'>)</span>
2797
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span>
2798
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2799
- <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span>
2800
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_publish_event'>publish_event</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
2801
- <span class='kw'>else</span>
2802
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2803
- <span class='kw'>end</span>
2804
- <span class='kw'>end</span></pre>
2805
- </td>
2806
- </tr>
2807
- </table>
2808
- </div>
2809
-
2810
- <div class="method_details ">
2811
- <h3 class="signature " id="handle_parsed_websocket_message-instance_method">
2812
-
2813
- - (<tt>void</tt>) <strong>handle_parsed_websocket_message</strong>(json_data)
2814
-
2815
-
2816
-
2817
-
2818
-
2819
- </h3><div class="docstring">
2820
- <div class="discussion">
2821
- <p class="note returns_void">This method returns an undefined value.</p>
2822
- <p>method that checks if the data is a Hash</p>
2823
-
2824
- <p>if the data is a hash then will stringify the keys and will call the method
2825
- <span class='object_link'><a href="#delegate_action-instance_method" title="CelluloidPubsub::Reactor#delegate_action (method)">#delegate_action</a></span> that will handle the message, otherwise will call the
2826
- method <span class='object_link'><a href="#handle_unknown_action-instance_method" title="CelluloidPubsub::Reactor#handle_unknown_action (method)">#handle_unknown_action</a></span></p>
2827
-
2828
-
2829
- </div>
2830
- </div>
2831
- <div class="tags">
2832
- <p class="tag_title">Parameters:</p>
2833
- <ul class="param">
2834
-
2835
- <li>
2836
-
2837
- <span class='name'>json_data</span>
2838
-
2839
-
2840
- <span class='type'>(<tt>Hash</tt>)</span>
2841
-
2842
-
2843
-
2844
- </li>
2845
-
2846
- </ul>
2847
-
2848
-
2849
- <p class="tag_title">See Also:</p>
2850
- <ul class="see">
2851
-
2852
- <li><span class='object_link'><a href="#delegate_action-instance_method" title="CelluloidPubsub::Reactor#delegate_action (method)">#delegate_action</a></span></li>
2853
-
2854
- <li><span class='object_link'><a href="#handle_unknown_action-instance_method" title="CelluloidPubsub::Reactor#handle_unknown_action (method)">#handle_unknown_action</a></span></li>
2855
-
2856
- </ul>
2857
-
2858
- </div><table class="source_code">
2859
- <tr>
2860
- <td>
2861
- <pre class="lines">
2862
-
2863
-
2864
- 104
2865
- 105
2866
- 106
2867
- 107
2868
- 108
2869
- 109
2870
- 110
2871
- 111
2872
- 112</pre>
2873
- </td>
2874
- <td>
2875
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 104</span>
2876
-
2877
- <span class='kw'>def</span> <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2878
- <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
2879
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys'>stringify_keys</span>
2880
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor finds actions for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2881
- <span class='id identifier rubyid_delegate_action'>delegate_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
2882
- <span class='kw'>else</span>
2883
- <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2884
- <span class='kw'>end</span>
2885
- <span class='kw'>end</span></pre>
2886
- </td>
2887
- </tr>
2888
- </table>
2889
- </div>
2890
-
2891
- <div class="method_details ">
2892
- <h3 class="signature " id="handle_unknown_action-instance_method">
2893
-
2894
- - (<tt>void</tt>) <strong>handle_unknown_action</strong>(json_data)
2895
-
2896
-
2897
-
2898
-
2899
-
2900
- </h3><div class="docstring">
2901
- <div class="discussion">
2902
- <p class="note returns_void">This method returns an undefined value.</p>
2903
- <p>the method will delegate the message to the server in an asyncronous way by
2904
- sending the current actor and the message</p>
2905
-
2906
-
2907
- </div>
2908
- </div>
2909
- <div class="tags">
2910
- <p class="tag_title">Parameters:</p>
2911
- <ul class="param">
2912
-
2913
- <li>
2914
-
2915
- <span class='name'>json_data</span>
2916
-
2917
-
2918
- <span class='type'>(<tt>Hash</tt>)</span>
2919
-
2920
-
2921
-
2922
- </li>
2923
-
2924
- </ul>
2925
-
2926
-
2927
- <p class="tag_title">See Also:</p>
2928
- <ul class="see">
2929
-
2930
- <li>CelluloidPubsub::Reactor.{CelluloidPubsub{CelluloidPubsub::WebServer{CelluloidPubsub::WebServer#handle_dispatched_message}</li>
2931
-
2932
- </ul>
2933
-
2934
- </div><table class="source_code">
2935
- <tr>
2936
- <td>
2937
- <pre class="lines">
2938
-
2939
-
2940
- 158
2941
- 159
2942
- 160
2943
- 161</pre>
2944
- </td>
2945
- <td>
2946
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 158</span>
2947
-
2948
- <span class='kw'>def</span> <span class='id identifier rubyid_handle_unknown_action'>handle_unknown_action</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2949
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Trying to dispatch to server </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_json_data'>json_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2950
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_handle_dispatched_message'>handle_dispatched_message</span><span class='lparen'>(</span><span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
2951
- <span class='kw'>end</span></pre>
2952
- </td>
2953
- </tr>
2954
- </table>
2955
- </div>
2956
-
2957
- <div class="method_details ">
2958
- <h3 class="signature " id="handle_websocket_message-instance_method">
2959
-
2960
- - (<tt>void</tt>) <strong>handle_websocket_message</strong>(message)
2961
-
2962
-
2963
-
2964
-
2965
-
2966
- </h3><div class="docstring">
2967
- <div class="discussion">
2968
- <p class="note returns_void">This method returns an undefined value.</p>
2969
- <p>method that handles the message received from the websocket connection
2970
- first will try to parse the message <span class='object_link'><a href="#parse_json_data-instance_method" title="CelluloidPubsub::Reactor#parse_json_data (method)">#parse_json_data</a></span> and then it will
2971
- dispatch it to another method that will decide depending the message what
2972
- action should the reactor take <span class='object_link'><a href="#handle_parsed_websocket_message-instance_method" title="CelluloidPubsub::Reactor#handle_parsed_websocket_message (method)">#handle_parsed_websocket_message</a></span></p>
2973
-
2974
-
2975
- </div>
2976
- </div>
2977
- <div class="tags">
2978
- <p class="tag_title">Parameters:</p>
2979
- <ul class="param">
2980
-
2981
- <li>
2982
-
2983
- <span class='name'>message</span>
2984
-
2985
-
2986
- <span class='type'>(<tt>JSON</tt>)</span>
2987
-
2988
-
2989
-
2990
- </li>
2991
-
2992
- </ul>
2993
-
2994
-
2995
- <p class="tag_title">See Also:</p>
2996
- <ul class="see">
2997
-
2998
- <li><span class='object_link'><a href="#parse_json_data-instance_method" title="CelluloidPubsub::Reactor#parse_json_data (method)">#parse_json_data</a></span></li>
2999
-
3000
- <li><span class='object_link'><a href="#handle_parsed_websocket_message-instance_method" title="CelluloidPubsub::Reactor#handle_parsed_websocket_message (method)">#handle_parsed_websocket_message</a></span></li>
3001
-
3002
- </ul>
3003
-
3004
- </div><table class="source_code">
3005
- <tr>
3006
- <td>
3007
- <pre class="lines">
3008
-
3009
-
3010
- 86
3011
- 87
3012
- 88
3013
- 89</pre>
3014
- </td>
3015
- <td>
3016
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 86</span>
3017
-
3018
- <span class='kw'>def</span> <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3019
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3020
- <span class='id identifier rubyid_handle_parsed_websocket_message'>handle_parsed_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_json_data'>json_data</span><span class='rparen'>)</span>
3021
- <span class='kw'>end</span></pre>
3022
- </td>
3023
- </tr>
3024
- </table>
3025
- </div>
3026
-
3027
- <div class="method_details ">
3028
- <h3 class="signature " id="parse_json_data-instance_method">
3029
-
3030
- - (<tt>Hash</tt>) <strong>parse_json_data</strong>(message)
3031
-
3032
-
3033
-
3034
-
3035
-
3036
- </h3><div class="docstring">
3037
- <div class="discussion">
3038
-
3039
- <p>method used to parse a JSON object into a Hash object</p>
3040
-
3041
-
3042
- </div>
3043
- </div>
3044
- <div class="tags">
3045
- <p class="tag_title">Parameters:</p>
3046
- <ul class="param">
3047
-
3048
- <li>
3049
-
3050
- <span class='name'>message</span>
3051
-
3052
-
3053
- <span class='type'>(<tt>JSON</tt>)</span>
3054
-
3055
-
3056
-
3057
- </li>
3058
-
3059
- </ul>
3060
-
3061
- <p class="tag_title">Returns:</p>
3062
- <ul class="return">
3063
-
3064
- <li>
3065
-
3066
-
3067
- <span class='type'>(<tt>Hash</tt>)</span>
3068
-
3069
-
3070
-
3071
- </li>
3072
-
3073
- </ul>
3074
-
3075
- </div><table class="source_code">
3076
- <tr>
3077
- <td>
3078
- <pre class="lines">
3079
-
3080
-
3081
- 60
3082
- 61
3083
- 62
3084
- 63
3085
- 64
3086
- 65
3087
- 66
3088
- 67
3089
- 68
3090
- 69
3091
- 70
3092
- 71</pre>
3093
- </td>
3094
- <td>
3095
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 60</span>
3096
-
3097
- <span class='kw'>def</span> <span class='id identifier rubyid_parse_json_data'>parse_json_data</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3098
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor read message </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3099
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='kw'>nil</span>
3100
- <span class='kw'>begin</span>
3101
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3102
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
3103
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reactor could not parse </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_content'> because of </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3104
- <span class='comment'># do nothing
3105
- </span> <span class='kw'>end</span>
3106
- <span class='id identifier rubyid_json_data'>json_data</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span> <span class='kw'>if</span> <span class='id identifier rubyid_json_data'>json_data</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
3107
- <span class='id identifier rubyid_json_data'>json_data</span>
3108
- <span class='kw'>end</span></pre>
3109
- </td>
3110
- </tr>
3111
- </table>
3112
- </div>
3113
-
3114
- <div class="method_details ">
3115
- <h3 class="signature " id="run-instance_method">
3116
-
3117
- - (<tt>void</tt>) <strong>run</strong>
3118
-
3119
-
3120
-
3121
-
3122
-
3123
- </h3><div class="docstring">
3124
- <div class="discussion">
3125
- <p class="note returns_void">This method returns an undefined value.</p>
3126
- <p>reads from the socket the message and dispatches it to the
3127
- handle_websocket_message method</p>
3128
-
3129
-
3130
- </div>
3131
- </div>
3132
- <div class="tags">
3133
-
3134
-
3135
- <p class="tag_title">See Also:</p>
3136
- <ul class="see">
3137
-
3138
- <li><span class='object_link'><a href="#handle_websocket_message-instance_method" title="CelluloidPubsub::Reactor#handle_websocket_message (method)">#handle_websocket_message</a></span></li>
3139
-
3140
- </ul>
3141
-
3142
- </div><table class="source_code">
3143
- <tr>
3144
- <td>
3145
- <pre class="lines">
3146
-
3147
-
3148
- 47
3149
- 48
3150
- 49
3151
- 50
3152
- 51</pre>
3153
- </td>
3154
- <td>
3155
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 47</span>
3156
-
3157
- <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span>
3158
- <span class='kw'>while</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span>
3159
- <span class='id identifier rubyid_handle_websocket_message'>handle_websocket_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3160
- <span class='kw'>end</span>
3161
- <span class='kw'>end</span></pre>
3162
- </td>
3163
- </tr>
3164
- </table>
3165
- </div>
3166
-
3167
- <div class="method_details ">
3168
- <h3 class="signature " id="shutdown-instance_method">
3169
-
3170
- - (<tt>void</tt>) <strong>shutdown</strong>
3171
-
3172
-
3173
-
3174
-
3175
-
3176
- </h3><div class="docstring">
3177
- <div class="discussion">
3178
- <p class="note returns_void">This method returns an undefined value.</p>
3179
- <p>the method will terminate the current actor</p>
3180
-
3181
-
3182
- </div>
3183
- </div>
3184
- <div class="tags">
3185
-
3186
-
3187
- </div><table class="source_code">
3188
- <tr>
3189
- <td>
3190
- <pre class="lines">
3191
-
3192
-
3193
- 186
3194
- 187
3195
- 188</pre>
3196
- </td>
3197
- <td>
3198
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 186</span>
3199
-
3200
- <span class='kw'>def</span> <span class='id identifier rubyid_shutdown'>shutdown</span>
3201
- <span class='id identifier rubyid_terminate'>terminate</span>
3202
- <span class='kw'>end</span></pre>
3203
- </td>
3204
- </tr>
3205
- </table>
3206
- </div>
3207
-
3208
- <div class="method_details ">
3209
- <h3 class="signature " id="start_subscriber-instance_method">
3210
-
3211
- - (<tt>void</tt>) <strong>start_subscriber</strong>(channel, message)
3212
-
3213
-
3214
-
3215
-
3216
-
3217
- </h3><div class="docstring">
3218
- <div class="discussion">
3219
- <p class="note returns_void">This method returns an undefined value.</p>
3220
- <p>this method will add the current actor to the list of the subscribers
3221
- <span class='object_link'><a href="#add_subscriber_to_channel-instance_method" title="CelluloidPubsub::Reactor#add_subscriber_to_channel (method)">#add_subscriber_to_channel</a></span> and will write to the socket a message for
3222
- succesful subscription</p>
3223
-
3224
-
3225
- </div>
3226
- </div>
3227
- <div class="tags">
3228
- <p class="tag_title">Parameters:</p>
3229
- <ul class="param">
3230
-
3231
- <li>
3232
-
3233
- <span class='name'>channel</span>
3234
-
3235
-
3236
- <span class='type'>(<tt>String</tt>)</span>
3237
-
3238
-
3239
-
3240
- </li>
3241
-
3242
- <li>
3243
-
3244
- <span class='name'>message</span>
3245
-
3246
-
3247
- <span class='type'>(<tt>Object</tt>)</span>
3248
-
3249
-
3250
-
3251
- </li>
3252
-
3253
- </ul>
3254
-
3255
-
3256
- <p class="tag_title">See Also:</p>
3257
- <ul class="see">
3258
-
3259
- <li><span class='object_link'><a href="#add_subscriber_to_channel-instance_method" title="CelluloidPubsub::Reactor#add_subscriber_to_channel (method)">#add_subscriber_to_channel</a></span></li>
3260
-
3261
- </ul>
3262
-
3263
- </div><table class="source_code">
3264
- <tr>
3265
- <td>
3266
- <pre class="lines">
3267
-
3268
-
3269
- 201
3270
- 202
3271
- 203
3272
- 204
3273
- 205
3274
- 206
3275
- 207
3276
- 208
3277
- 209
3278
- 210</pre>
3279
- </td>
3280
- <td>
3281
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 201</span>
3282
-
3283
- <span class='kw'>def</span> <span class='id identifier rubyid_start_subscriber'>start_subscriber</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3284
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
3285
- <span class='kw'>begin</span>
3286
- <span class='id identifier rubyid_add_subscriber_to_channel'>add_subscriber_to_channel</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3287
- <span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Subscribed to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> with </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3288
- <span class='ivar'>@websocket</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>successful_subscription</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
3289
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
3290
- <span class='id identifier rubyid_raise'>raise</span> <span class='lbracket'>[</span><span class='id identifier rubyid_e'>e</span><span class='comma'>,</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:backtrace</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_backtrace'>backtrace</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span>
3291
- <span class='kw'>end</span>
3292
- <span class='kw'>end</span></pre>
3293
- </td>
3294
- </tr>
3295
- </table>
3296
- </div>
3297
-
3298
- <div class="method_details ">
3299
- <h3 class="signature " id="unsubscribe_all-instance_method">
3300
-
3301
- - (<tt>void</tt>) <strong>unsubscribe_all</strong>
3302
-
3303
-
3304
-
3305
-
3306
-
3307
- </h3><div class="docstring">
3308
- <div class="discussion">
3309
- <p class="note returns_void">This method returns an undefined value.</p>
3310
- <p>unsubscribes all actors from all channels and terminates the curent actor</p>
3311
-
3312
-
3313
- </div>
3314
- </div>
3315
- <div class="tags">
3316
-
3317
-
3318
- </div><table class="source_code">
3319
- <tr>
3320
- <td>
3321
- <pre class="lines">
3322
-
3323
-
3324
- 233
3325
- 234
3326
- 235
3327
- 236
3328
- 237
3329
- 238
3330
- 239
3331
- 240
3332
- 241
3333
- 242
3334
- 243</pre>
3335
- </td>
3336
- <td>
3337
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 233</span>
3338
-
3339
- <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_all'>unsubscribe_all</span>
3340
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_channels'>channels</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_channel'>channel</span><span class='op'>|</span>
3341
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
3342
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
3343
- <span class='kw'>end</span>
3344
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
3345
- <span class='kw'>end</span>
3346
-
3347
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>clearing connections</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3348
- <span class='id identifier rubyid_shutdown'>shutdown</span>
3349
- <span class='kw'>end</span></pre>
3350
- </td>
3351
- </tr>
3352
- </table>
3353
- </div>
3354
-
3355
- <div class="method_details ">
3356
- <h3 class="signature " id="unsubscribe_client-instance_method">
3357
-
3358
- - (<tt>void</tt>) <strong>unsubscribe_client</strong>(channel)
3359
-
3360
-
3361
-
3362
-
3363
-
3364
- </h3><div class="docstring">
3365
- <div class="discussion">
3366
- <p class="note returns_void">This method returns an undefined value.</p>
3367
- <p>the method will unsubscribe a client by closing the websocket connection if
3368
- has unscribed from all channels and deleting the reactor from the channel
3369
- list on the server</p>
3370
-
3371
-
3372
- </div>
3373
- </div>
3374
- <div class="tags">
3375
- <p class="tag_title">Parameters:</p>
3376
- <ul class="param">
3377
-
3378
- <li>
3379
-
3380
- <span class='name'>channel</span>
3381
-
3382
-
3383
- <span class='type'>(<tt>String</tt>)</span>
3384
-
3385
-
3386
-
3387
- </li>
3388
-
3389
- </ul>
3390
-
3391
-
3392
- </div><table class="source_code">
3393
- <tr>
3394
- <td>
3395
- <pre class="lines">
3396
-
3397
-
3398
- 171
3399
- 172
3400
- 173
3401
- 174
3402
- 175
3403
- 176
3404
- 177
3405
- 178</pre>
3406
- </td>
3407
- <td>
3408
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 171</span>
3409
-
3410
- <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe_client'>unsubscribe_client</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
3411
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_channel'>channel</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
3412
- <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
3413
- <span class='ivar'>@websocket</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='ivar'>@channels</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
3414
- <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_subscribers'>subscribers</span><span class='lbracket'>[</span><span class='id identifier rubyid_channel'>channel</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_delete_if'>delete_if</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hash'>hash</span><span class='op'>|</span>
3415
- <span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='symbol'>:reactor</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
3416
- <span class='kw'>end</span>
3417
- <span class='kw'>end</span></pre>
3418
- </td>
3419
- </tr>
3420
- </table>
3421
- </div>
3422
-
3423
- <div class="method_details ">
3424
- <h3 class="signature " id="work-instance_method">
3425
-
3426
- - (<tt>void</tt>) <strong>work</strong>(websocket, server)
3427
-
3428
-
3429
-
3430
-
3431
-
3432
- </h3><div class="docstring">
3433
- <div class="discussion">
3434
- <p class="note returns_void">This method returns an undefined value.</p>
3435
- <p>rececives a new socket connection from the server</p>
3436
-
3437
- <pre class="code ruby"><code class="ruby">and initiates a new mutex that can be used when subsribing to a channel</code></pre>
3438
-
3439
-
3440
- </div>
3441
- </div>
3442
- <div class="tags">
3443
- <p class="tag_title">Parameters:</p>
3444
- <ul class="param">
3445
-
3446
- <li>
3447
-
3448
- <span class='name'>websocket</span>
3449
-
3450
-
3451
- <span class='type'>(<tt>Reel::WebSocket</tt>)</span>
3452
-
3453
-
3454
-
3455
- </li>
3456
-
3457
- </ul>
3458
-
3459
-
3460
- </div><table class="source_code">
3461
- <tr>
3462
- <td>
3463
- <pre class="lines">
3464
-
3465
-
3466
- 31
3467
- 32
3468
- 33
3469
- 34
3470
- 35
3471
- 36
3472
- 37
3473
- 38</pre>
3474
- </td>
3475
- <td>
3476
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/reactor.rb', line 31</span>
3477
-
3478
- <span class='kw'>def</span> <span class='id identifier rubyid_work'>work</span><span class='lparen'>(</span><span class='id identifier rubyid_websocket'>websocket</span><span class='comma'>,</span> <span class='id identifier rubyid_server'>server</span><span class='rparen'>)</span>
3479
- <span class='ivar'>@server</span> <span class='op'>=</span> <span class='id identifier rubyid_server'>server</span>
3480
- <span class='ivar'>@mutex</span> <span class='op'>=</span> <span class='const'>Mutex</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
3481
- <span class='ivar'>@channels</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
3482
- <span class='ivar'>@websocket</span> <span class='op'>=</span> <span class='id identifier rubyid_websocket'>websocket</span>
3483
- <span class='id identifier rubyid_info'>info</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Streaming changes for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_websocket'>websocket</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@server</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3484
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span>
3485
- <span class='kw'>end</span></pre>
3486
- </td>
3487
- </tr>
3488
- </table>
3489
- </div>
3490
-
3491
- </div>
3492
-
3493
- </div>
3494
-
3495
- <div id="footer">
3496
- Generated on Fri Mar 13 18:05:41 2015 by
3497
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
3498
- 0.8.7.6 (ruby-2.0.0).
3499
- </div>
3500
-
3501
- </body>
3502
- </html>