Class: StompServer::TopicManager
- Inherits:
-
Object
- Object
- StompServer::TopicManager
- Defined in:
- lib/stomp_server_ng/topic_manager.rb
Instance Attribute Summary collapse
-
#frame_index ⇒ Object
Returns the value of attribute frame_index.
Instance Method Summary collapse
- #disconnect(user) ⇒ Object
- #index ⇒ Object
-
#initialize ⇒ TopicManager
constructor
A new instance of TopicManager.
- #next_index ⇒ Object
- #sendmsg(msg) ⇒ Object
- #subscribe(topic, user) ⇒ Object
- #unsubscribe(topic, user) ⇒ Object
Constructor Details
#initialize ⇒ TopicManager
Returns a new instance of TopicManager.
6 7 8 9 10 11 12 13 14 |
# File 'lib/stomp_server_ng/topic_manager.rb', line 6 def initialize @frame_index =0 @topics = Hash.new { Array.new } @@log = Logger.new(STDOUT) @@log.level = StompServer::LogHelper.get_loglevel() @@log.info("TopicManager initialize comletes") end |
Instance Attribute Details
#frame_index ⇒ Object
Returns the value of attribute frame_index.
5 6 7 |
# File 'lib/stomp_server_ng/topic_manager.rb', line 5 def frame_index @frame_index end |
Instance Method Details
#disconnect(user) ⇒ Object
32 33 34 35 36 |
# File 'lib/stomp_server_ng/topic_manager.rb', line 32 def disconnect(user) @topics.each do |dest, queue| queue.delete_if { |qu| qu == user } end end |
#index ⇒ Object
16 17 18 |
# File 'lib/stomp_server_ng/topic_manager.rb', line 16 def index @frame_index end |
#next_index ⇒ Object
20 21 22 |
# File 'lib/stomp_server_ng/topic_manager.rb', line 20 def next_index @frame_index += 1 end |
#sendmsg(msg) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/stomp_server_ng/topic_manager.rb', line 38 def sendmsg(msg) msg.command = "MESSAGE" topic = msg.headers['destination'] @topics[topic].each do |user| user.stomp_send_data(msg) end end |
#subscribe(topic, user) ⇒ Object
24 25 26 |
# File 'lib/stomp_server_ng/topic_manager.rb', line 24 def subscribe(topic, user) @topics[topic] += [user] end |
#unsubscribe(topic, user) ⇒ Object
28 29 30 |
# File 'lib/stomp_server_ng/topic_manager.rb', line 28 def unsubscribe(topic, user) @topics[topic].delete(user) end |