Class: OpenWFE::SocketParticipant

Inherits:
Object
  • Object
show all
Defined in:
lib/openwfe/participants/socketparticipants.rb

Overview

This participant implementation dispatches workitems over TCP sockets. By default the workitem are dumped as YAML strings, but you can override the encode_workitem(wi) method.

A small example :

require 'openwfe/particpants/socketparticipants'

sp = OpenWFE::SocketParticipant.new("target.host.xx", 7007)

engine.register_participant("Alfred", sp)

Direct Known Subclasses

XmlSocketParticipant

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ SocketParticipant

The constructor



70
71
72
73
74
# File 'lib/openwfe/participants/socketparticipants.rb', line 70

def initialize (host, port)

    @host = host
    @port = port
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



65
66
67
# File 'lib/openwfe/participants/socketparticipants.rb', line 65

def host
  @host
end

#portObject

Returns the value of attribute port.



65
66
67
# File 'lib/openwfe/participants/socketparticipants.rb', line 65

def port
  @port
end

Class Method Details

.dispatch(host, port, workitem) ⇒ Object

A ‘static’ method for dispatching workitems, you can use it directly, without instantiating the SocketParticipant :

require 'openwfe/participants/socketparticipants'

SocketParticipant.dispatch("127.0.0.1", 7007, workitem)


109
110
111
112
# File 'lib/openwfe/participants/socketparticipants.rb', line 109

def SocketParticipant.dispatch (host, port, workitem)

    SocketParticipant.new(host, port).dispatch(workitem)
end

Instance Method Details

#consume(workitem) ⇒ Object

The method called by the engine for each incoming workitem. Will dispatch the workitem over a TCP connection.



80
81
82
83
# File 'lib/openwfe/participants/socketparticipants.rb', line 80

def consume (workitem)

    dispatch(workitem)
end

#dispatch(workitem) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/openwfe/participants/socketparticipants.rb', line 85

def dispatch (workitem)

    socket = TCPSocket.new(@host, @port)
    socket.puts encode_workitem(workitem)
    socket.puts
    socket.close_write

    #print "\n__socket.closed? #{socket.closed?}"

    reply = fetch_reply(socket)

    socket.close

    decode_reply(reply)
end