Class: XmlblasterCallbackClient
Instance Attribute Summary collapse
#xmlblaster_ip
Instance Method Summary
collapse
#connect, #erase, #get, #printMessage, #publish
Constructor Details
#initialize(xmlblaster_ip = nil, xmlblaster_port = "8080", callback_ip = "127.0.0.1", callback_port = "8081", callback_public_ip = nil, callback_public_port = nil, audit = nil) ⇒ XmlblasterCallbackClient
Returns a new instance of XmlblasterCallbackClient.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/adaptation/xmlblaster/xmlblaster_callback_client.rb', line 8
def initialize( xmlblaster_ip = nil, xmlblaster_port = "8080", callback_ip = "127.0.0.1", callback_port = "8081", callback_public_ip = nil, callback_public_port = nil, audit = nil)
super xmlblaster_ip, xmlblaster_port, audit
@xmlblaster_ip = xmlblaster_ip
@xmlblaster_port = xmlblaster_port
@callback_ip = callback_ip
@callback_port = callback_port
@callback_public_ip = callback_public_ip || @callback_ip
@callback_public_port = callback_public_port || @callback_port
@callback_server = nil
@audit = audit
begin
@callback_server = XmlblasterCallbackServer.new( @callback_ip, @callback_port, @callback_public_ip, @callback_public_port, self, @audit )
rescue => e
@audit.warn( "XMLBlasterCallbackClient: Could not create CallbackServer" )
raise e
end
begin
@callback_server.start()
rescue => e
@audit.warn( "XMLBlasterCallbackClient: Error creating XMLRPC Server" )
raise e
end
end
|
Instance Attribute Details
#callback_server ⇒ Object
Returns the value of attribute callback_server.
6
7
8
|
# File 'lib/adaptation/xmlblaster/xmlblaster_callback_client.rb', line 6
def callback_server
@callback_server
end
|
Instance Method Details
#login(username = 'guest', password = 'guest') ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/adaptation/xmlblaster/xmlblaster_callback_client.rb', line 34
def login( username='guest', password='guest' )
qos = "<qos>
<securityService type='htpasswd' version='1.0'>
<![CDATA[
<user>#{username}</user>
<passwd>#{password}</passwd>
]]>
</securityService>
<session name ='#{username}/1' timeout='0' maxSessions='1' clearSessions='true' />
<persistent/>
<callback type='XMLRPC' retries='-1' delay='60000'>#{@callback_server.callback_url}</callback>
</qos>"
@audit.debug( "XmlblasterCallbackClient: authenticate.connect QoS = #{qos}" )
returnQos = @proxy.call("authenticate.connect", qos)
@audit.debug( "XmlblasterCallbackClient: authenticate.connect returnQos = #{returnQos}" )
xml = REXML::Document.new(returnQos)
@sessionId = xml.elements["//session"].attributes["sessionId"]
end
|
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/adaptation/xmlblaster/xmlblaster_callback_client.rb', line 123
def logout
super
if @callback_server then
begin
@callback_server.shutdown()
rescue => e
@audit.warn( "XMLBlasterCallbackClient: Error could not stop CallbackServer" )
raise e
end
else
return false
end
return true
end
|
#ping(*args) ⇒ Object
118
119
120
121
|
# File 'lib/adaptation/xmlblaster/xmlblaster_callback_client.rb', line 118
def ping( *args )
@audit.debug( "XMLBlasterClient: received PING - PONG" )
return "<qos><state>OK</state></qos>"
end
|
#subscribe(xmlKey, qos) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/adaptation/xmlblaster/xmlblaster_callback_client.rb', line 53
def subscribe( xmlKey, qos )
begin
returnValue = @proxy.call("xmlBlaster.subscribe", @sessionId, xmlKey, qos )
puts "Subscribed to mom (xmlblaster at #{@xmlblaster_ip}:#{@xmlblaster_port}). Listening at #{@callback_public_ip || @callback_ip}:#{@callback_public_port || @callback_port}"
@audit.info( "==> ::SUBSCRIBE:: <== Success subscribing with sessionID #{@sessionId}" )
rescue => e
@audit.warn( "XMLBlasterClient: Error subscribing to MOM: #{e}" )
raise e
end
return returnValue
end
|
#unsubscribe(xmlKey, qos) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/adaptation/xmlblaster/xmlblaster_callback_client.rb', line 65
def unsubscribe( xmlKey, qos )
begin
returnValue = @proxy.call("xmlBlaster.unSubscribe", @sessionId, xmlKey, qos )
@audit.info( "==> ::UNSUBSCRIBE:: <== Success unSubscribing with sessionID #{@sessionId}" )
rescue => e
@audit.warn( "XMLBlasterClient: Error unsubscribing from MOM: #{e}" )
raise e
end
return true
end
|
#update(*args) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/adaptation/xmlblaster/xmlblaster_callback_client.rb', line 76
def update( *args )
key =args[0]
content = args[1]
qos = args[2]
@audit.info( "XMLBlasterCallbackClient: Received UPDATE." )
begin
qos_xml = REXML::Document.new args[2]
rescue => e
@audit.warn( "XMLBlasterCallbackClient: Could not open QOS of message." )
end
if qos_xml.elements['qos'].elements['state'] != nil then
begin
value = qos_xml.elements['qos'].elements['state'].attributes['id'].to_s
if value == "ERASED" then
@audit.debug( "XMLBlasterCallbackClient: TOPIC GOT ERASED" )
else
@audit.debug( "XMLBlasterCallbackClient: SOMETHING STRANGE" )
end
rescue => e
@audit.warn( "XMLBlasterCallbackClient: Error: #{e}" )
end
end
begin
key_xml = REXML::Document.new key
topic = key_xml.elements['key'].attributes["oid"]
@audit.debug( "Topic #{topic}" )
puts "-----------------------------------"
puts "Received message in topic: #{topic}"
puts "#{content}"
puts "-----------------------------------"
Adaptation::Base.new.process content
rescue => e
@audit.warn( "XMLBlasterCallbackClient: Could not access content of message." )
end
return "<qos><state>OK</state></qos>"
end
|