Class: RFlow::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/rflow/connection.rb

Overview

Represents an RFlow connection from one component to another.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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
  @options = config.options
end

Instance Attribute Details

#configConfiguration::Connection

The reference to the connection’s configuration.



23
24
25
# File 'lib/rflow/connection.rb', line 23

def config
  @config
end

#nameString

The connection’s name.

Returns:

  • (String)


31
32
33
# File 'lib/rflow/connection.rb', line 31

def name
  @name
end

#optionsHash

The connection’s options Hash.

Returns:

  • (Hash)


35
36
37
# File 'lib/rflow/connection.rb', line 35

def options
  @options
end

#recv_callbackProc

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.

Returns:

  • (Proc)


81
82
83
# File 'lib/rflow/connection.rb', line 81

def recv_callback
  @recv_callback
end

#uuidString

The connection’s UUID.

Returns:

  • (String)


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.

Returns:



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.

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


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_keyString

If we are connected to an RFlow::Component::InputPort subport, the key for that subport.

Returns:

  • (String)


87
# File 'lib/rflow/connection.rb', line 87

def input_port_key; config.input_port_key; end

#output_port_keyString

If we are connected to an RFlow::Component::OutputPort subport, the key for that subport.

Returns:

  • (String)


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.

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/rflow/connection.rb', line 70

def send_message(message)
  raise NotImplementedError, 'Raw connections do not support send_message.  Please subclass and define a send_message method.'
end