Class: RFlow::Connection
- Inherits:
-
Object
- Object
- RFlow::Connection
- Defined in:
- lib/rflow/connection.rb
Overview
Represents an RFlow connection from one component to another.
Direct Known Subclasses
RFlow::Connections::ZMQConnection, ForwardToInputPort, ForwardToOutputPort, MessageCollectingConnection
Instance Attribute Summary collapse
-
#config ⇒ Configuration::Connection
The reference to the connection’s configuration.
-
#name ⇒ String
The connection’s name.
-
#options ⇒ Hash
The connection’s options Hash.
-
#recv_callback ⇒ Proc
Parent component will set this attribute if it expects to receive messages.
-
#uuid ⇒ String
The connection’s UUID.
Class Method Summary collapse
-
.build(config) ⇒ Connection
Build an appropriate subclass of Connection based on the configuration.
Instance Method Summary collapse
-
#connect_input! ⇒ void
Subclass and implement to be able to handle future
recvmethods. -
#connect_output! ⇒ void
Subclass and implement to be able to handle future
sendmethods. -
#initialize(config) ⇒ Connection
constructor
A new instance of Connection.
-
#input_port_key ⇒ String
If we are connected to an RFlow::Component::InputPort subport, the key for that subport.
-
#output_port_key ⇒ String
If we are connected to an RFlow::Component::OutputPort subport, the key for that subport.
-
#send_message(message) ⇒ void
Subclass and implement to handle outgoing messages.
Constructor Details
#initialize(config) ⇒ Connection
Returns a new instance of Connection.
42 43 44 45 46 47 |
# File 'lib/rflow/connection.rb', line 42 def initialize(config) @config = config @uuid = config.uuid @name = config.name = config. end |
Instance Attribute Details
#config ⇒ Configuration::Connection
The reference to the connection’s configuration.
23 24 25 |
# File 'lib/rflow/connection.rb', line 23 def config @config end |
#name ⇒ String
The connection’s name.
31 32 33 |
# File 'lib/rflow/connection.rb', line 31 def name @name end |
#options ⇒ Hash
The connection’s options Hash.
35 36 37 |
# File 'lib/rflow/connection.rb', line 35 def end |
#recv_callback ⇒ Proc
Parent component will set this attribute if it expects to receive messages. RFlow::Connection subclass should call it (recv_callback.call(message)) when it gets a new message, which will be transmitted back to the parent component’s RFlow::Component#process_message method. Subclass is responsible for deserializing whatever was on the wire into a Message object.
81 82 83 |
# File 'lib/rflow/connection.rb', line 81 def recv_callback @recv_callback end |
#uuid ⇒ String
The connection’s UUID.
27 28 29 |
# File 'lib/rflow/connection.rb', line 27 def uuid @uuid end |
Class Method Details
.build(config) ⇒ Connection
Build an appropriate subclass of RFlow::Connection based on the configuration.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rflow/connection.rb', line 9 def build(config) case config.type when 'RFlow::Configuration::ZMQConnection' RFlow::Connections::ZMQConnection.new(config) when 'RFlow::Configuration::BrokeredZMQConnection' RFlow::Connections::BrokeredZMQConnection.new(config) else raise ArgumentError, 'Only ZMQConnections currently supported' end end |
Instance Method Details
#connect_input! ⇒ void
This method returns an undefined value.
Subclass and implement to be able to handle future recv methods. Will only be called in the context of a running EventMachine reactor.
53 54 55 |
# File 'lib/rflow/connection.rb', line 53 def connect_input! raise NotImplementedError, 'Raw connections do not support connect_input. Please subclass and define a connect_input method.' end |
#connect_output! ⇒ void
This method returns an undefined value.
Subclass and implement to be able to handle future send methods. Will only be called in the context of a running EventMachine reactor.
61 62 63 |
# File 'lib/rflow/connection.rb', line 61 def connect_output! raise NotImplementedError, 'Raw connections do not support connect_output. Please subclass and define a connect_output method.' end |
#input_port_key ⇒ String
If we are connected to an RFlow::Component::InputPort subport, the key for that subport.
87 |
# File 'lib/rflow/connection.rb', line 87 def input_port_key; config.input_port_key; end |
#output_port_key ⇒ String
If we are connected to an RFlow::Component::OutputPort subport, the key for that subport.
91 |
# File 'lib/rflow/connection.rb', line 91 def output_port_key; config.output_port_key; end |
#send_message(message) ⇒ void
This method returns an undefined value.
Subclass and implement to handle outgoing messages. The message will be a Message object and the subclasses are expected to marshal it up into something that will be unmarshalled on the other side.
70 71 72 |
# File 'lib/rflow/connection.rb', line 70 def () raise NotImplementedError, 'Raw connections do not support send_message. Please subclass and define a send_message method.' end |