Class: SCXMLServer::StatefulProtocol
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- SCXMLServer::StatefulProtocol
- Includes:
- EM::Protocols::LineText2
- Defined in:
- lib/MINT-core/manager/scxml_server.rb
Instance Attribute Summary collapse
-
#manager ⇒ Object
Returns the value of attribute manager.
Instance Method Summary collapse
-
#initialize ⇒ StatefulProtocol
constructor
A new instance of StatefulProtocol.
- #send_active_state(name) ⇒ Object
- #send_inactive_state(name) ⇒ Object
- #subscribe_redis(interactor, name) ⇒ Object
Constructor Details
#initialize ⇒ StatefulProtocol
Returns a new instance of StatefulProtocol.
15 16 17 |
# File 'lib/MINT-core/manager/scxml_server.rb', line 15 def initialize super() end |
Instance Attribute Details
#manager ⇒ Object
Returns the value of attribute manager.
13 14 15 |
# File 'lib/MINT-core/manager/scxml_server.rb', line 13 def manager @manager end |
Instance Method Details
#send_active_state(name) ⇒ Object
58 59 60 |
# File 'lib/MINT-core/manager/scxml_server.rb', line 58 def send_active_state(name) send_data "1 #{name}" end |
#send_inactive_state(name) ⇒ Object
62 63 64 |
# File 'lib/MINT-core/manager/scxml_server.rb', line 62 def send_inactive_state(name) send_data "0 #{name}" end |
#subscribe_redis(interactor, name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/MINT-core/manager/scxml_server.rb', line 19 def subscribe_redis(interactor,name) @interactor = interactor @name = name redis = EventMachine::Hiredis.connect redis.pubsub.psubscribe(@interactor) { |key, | found=MultiJson.decode if @name.nil? or @name.eql? found["name"] if found.has_key? "new_states" # send new state found["new_states"].each { |state| p "activated: #{state}" send_active_state state } end if(@state_store[key]) activated_states = @state_store[key] current_active_states = found["states"] + found["abstract_states"] deactivated_states = activated_states - current_active_states # send deactivate states deactivated_states.each {|state| p "deactivated: #{state}" send_inactive_state state } #save activated states @state_store[key] = current_active_states end end }.callback { p "subscribed to #{@interactor} name #{@name}"} end |