lib/rflow/connection.rb in rflow-0.0.5 vs lib/rflow/connection.rb in rflow-1.0.0a1

- old
+ new

@@ -1,18 +1,29 @@ require 'rflow/message' class RFlow class Connection - attr_accessor :instance_uuid, :name, :configuration, :recv_callback - # Attribute that holds the + class << self + def build(config) + case config.type + when 'RFlow::Configuration::ZMQConnection' + RFlow::Connections::ZMQConnection.new(config) + else + raise ArgumentError, "Only ZMQConnections currently supported" + end + end + end + + attr_accessor :config, :uuid, :name, :options attr_accessor :recv_callback - - def initialize(connection_instance_uuid, connection_name=nil, connection_configuration={}) - @instance_uuid = connection_instance_uuid - @name = connection_name - @configuration = connection_configuration + + def initialize(config) + @config = config + @uuid = config.uuid + @name = config.name + @options = config.options end # Subclass and implement to be able to handle future 'recv' # methods. Will only be called in the context of a running @@ -27,11 +38,11 @@ # EventMachine reactor def connect_output! raise NotImplementedError, "Raw connections do not support connect_output. Please subclass and define a connect_output method." end - + # Subclass and implement to handle outgoing messages. The message # will be a RFlow::Message object and the subclasses are expected # to marshal it up into something that will be unmarshalled on the # other side def send_message(message) @@ -45,15 +56,15 @@ # process_message method. Sublcass is responsible for # deserializing whatever was on the wire into a RFlow::Message object def recv_callback @recv_callback ||= Proc.new {|message|} end - + end # class Connection class Disconnection < Connection def send_message(message) RFlow.logger.debug "Attempting to send without a connection, doing nothing" end end - + end # class RFlow