simplepubsub 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27b1c6f566163fa794d7fda59a0246096258b8fc
4
- data.tar.gz: 96ff3301c355dbbd76daed09ead3efb6d9815a8e
3
+ metadata.gz: 9c4513ee74222d8aa5deebdb2c14e81a9c909a5b
4
+ data.tar.gz: c7009e918084ad0d56fbc9684ab179bf81ecda10
5
5
  SHA512:
6
- metadata.gz: c09955fc2a312ffbb910577af68409dac51f7a5ef4b0d8a618566d6631f9aa791b2a1ac791b1cf7ef2d7d49c9e2200678639889bbdf981e070e99ea9bd28c81b
7
- data.tar.gz: f1092acdbe6727e490f26f8dad67ecf146728687d9325303b7cdc0404931e443713023a821ca866ce639ac9375e51a32848cf414a7afd5a12a4f3d205ea5a758
6
+ metadata.gz: 16ae4e1c743711ebde933b5a28c83c78ae10de79b4dc97596dc8ee68698d8420dfeef86b883dfceb98dc22cfdd7e2bac674c84660ee6a5292750a8e1480e7172
7
+ data.tar.gz: 7ea66c7fd40680761b3f47800a1a3db27a917ed250ed247f2d4fe8d02117986a58e5cbd3bbcd19d9f07853fe320bcbc06548a8c8a9dabcc02850eeeb9ef9c82d
checksums.yaml.gz.sig CHANGED
@@ -1,3 +1,6 @@
1
- nd١(�����`�+L�m��M f_���|ߤ���b`�44=;?i�C����..=r>�0Gr*K����fq
2
- ���)М�iA|���YA{����uR��׎awq���lPྊ�O���Hd_}Z�@���o.1��iFH��5
3
- l?�ڈ�紉48l{ #��j-� ��)x~�K&��)�/�BDVwh��vMw����m�e�y�������d�FMF�w��'uz�\�mh
1
+ !���;`j�
2
+ ��'Y��hݚ�"E[|4o6YG��ő���"`�
3
+ ��O:"����sr��{դ*��cdl
4
+ AZJE����+���s� ~e[��ׄ<f�̐�E��QQNp�u@�
5
+ ��P����x�[<���J3t埂���,R��xj��[i��+g3��Tk� �4pt�_��*��V��hP%k5�fFN���/����7/
6
+ ����?n�}\D;
data/lib/simplepubsub.rb CHANGED
@@ -6,7 +6,7 @@ require 'open-uri'
6
6
  require 'drb'
7
7
 
8
8
 
9
- USER_AGENT = 'SimplePubSub client 0.1'
9
+ USER_AGENT = 'SimplePubSub client 0.2'
10
10
 
11
11
  module SimplePubSub
12
12
 
@@ -51,4 +51,81 @@ module SimplePubSub
51
51
  yield(PubSub.new base_url)
52
52
  end
53
53
  end
54
+
55
+ class Server
56
+
57
+ attr_reader :subscribers
58
+
59
+ def initialize()
60
+ @subscribers = {'#' => []}
61
+ @bridges = {'#' => []}
62
+ end
63
+
64
+ def subscribe(topic, uri)
65
+ @subscribers[topic] ||= []
66
+ @subscribers[topic] << uri
67
+ end
68
+
69
+ def deliver(topic, msg)
70
+
71
+ if not @subscribers.include?(topic) and \
72
+ not @subscribers.include?('#') then
73
+ return 'no topic subscribers'
74
+ end
75
+
76
+
77
+ DRb.start_service
78
+
79
+ topic_subscribers = @subscribers[topic]
80
+
81
+ if topic_subscribers then
82
+
83
+ topic_subscribers.each do |uri|
84
+
85
+ next if @subscribers['#'].include? uri
86
+ echo = DRbObject.new nil, uri
87
+
88
+ begin
89
+ echo.message topic, msg
90
+ rescue DRb::DRbConnError => e
91
+ @subscribers[topic].delete uri
92
+ end
93
+
94
+ end
95
+ end
96
+
97
+ @subscribers['#'].each do |uri|
98
+
99
+ echo = DRbObject.new nil, uri
100
+
101
+ begin
102
+ echo.message topic, msg
103
+ rescue DRb::DRbConnError => e
104
+ @subscribers['#'].delete uri
105
+ end
106
+
107
+ end
108
+ end
109
+
110
+ def add_bridge(topic, hostname, address)
111
+ @bridges[topic] ||= {}
112
+ @bridges[topic].merge!(hostname => address)
113
+ end
114
+
115
+ def bridge_deliver(topic, message, excluded_host=nil)
116
+
117
+ if excluded_host then
118
+ bridges = @bridges[topic].select{|x| x != excluded_host}
119
+ else
120
+ bridges = @bridges[topic]
121
+ end
122
+
123
+ bridges.each do |bridge|
124
+ url = "http://%s/do/simplepubsub/bridge_published?topic=%s&message=%s" % [address, topic, URI.escape(message)]
125
+ r = open(url, 'UserAgent' => USER_AGENT)
126
+ end
127
+ end
128
+
129
+ end
130
+
54
131
  end
data.tar.gz.sig CHANGED
@@ -1,3 +1 @@
1
- }im���O޻�ƊE.�oze��qLHS���;��{�>�l6v~�}����U���&�m�߷&Q��S��)"���wg3F,s~�iv7-y͓�� �bB��ų�38:<��[ѐ�s{Q����(������������l����Y-۶1��Ȗ�y�d�^�8���PXt.�-~�W�*�l����4��z����*�\/�V���MIaқY
2
- ����ܐvٞm0� 1��@!�N��k�؄{��,����DF
3
- D
1
+ j���,2lo@�v��jA��݈�,JNT4C ��iqJ !`��a�
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplepubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  i0PBE6fLwlIMk8jNNUcX3J1csSMgLNTwE8CwrlSZE8sueHj0pQzICM7lF0gGREO6
32
32
  hQHD0LljU3MusQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2013-06-13 00:00:00.000000000 Z
34
+ date: 2013-06-20 00:00:00.000000000 Z
35
35
  dependencies: []
36
36
  description:
37
37
  email:
metadata.gz.sig CHANGED
@@ -1 +1 @@
1
- ���̦�H��O�,R_g��i(G��a݊_K�DZdF����r�� jY���9u�fB�[�����#�y-b��F�v�*t��$�khڻ�-3����xZ I��s{�!8�����4f3dwQvU[e� �.^�]� �~W��5G����qo;���N�1V|�jV^q��Lj�/�2Sz�*�#͉ �o�����Y��I�:u�u�oy���]�6�|e�J]�daG8����*+r��G DS#�:�L;���͉��
1
+ IG���Pg3r|]]���ПwoE��߬I��q϶�{��D3>�A�<_Ri2\�NU����MnO3x��+�M�+9\۩�=��y�=�O#�Oc��!�˛��7���?nz��3ՈL(u�{G$�