Class: EventState::ObjectMachine
- Includes:
- EventMachine::P::ObjectProtocol
- Defined in:
- lib/event_state/object_machine.rb
Overview
Base class for a machine in which the messages are ruby objects. See the README for examples.
Instance Attribute Summary
Attributes inherited from Machine
Instance Method Summary collapse
-
#message_name(message) ⇒ Object
Return the class of the message as the message name.
-
#receive_object(message) ⇒ nil
Called by
EventMachine
(actually, theObjectProtocol
) when a message is received; makes the appropriate transition. -
#send_message(message) ⇒ nil
Call
ObjectProtocol
‘ssend_object
on the message and make the transition.
Methods inherited from Machine
#add_state_timer, on_enter, on_exit, on_recv, on_send, on_unbind, #post_init, print_state_machine_dot, protocol, reverse_protocol, state, timeout, #transition_on_recv, #transition_on_send, transitions, #unbind
Instance Method Details
#message_name(message) ⇒ Object
Return the class of the message as the message name. You can override this method to provide your own mapping from messages to names.
18 19 20 |
# File 'lib/event_state/object_machine.rb', line 18 def .class end |
#receive_object(message) ⇒ nil
Called by EventMachine
(actually, the ObjectProtocol
) when a message is received; makes the appropriate transition.
Note: if you want to receive non-messages as well, you should override this method in your subclass, and call super
only when a message is received.
34 35 36 |
# File 'lib/event_state/object_machine.rb', line 34 def receive_object transition_on_recv (), end |
#send_message(message) ⇒ nil
Call ObjectProtocol
‘s send_object
on the message and make the transition.
46 47 48 49 50 51 |
# File 'lib/event_state/object_machine.rb', line 46 def raise "not on the reactor thread" unless EM.reactor_thread? transition_on_send (), do |msg| send_object msg end end |