Class: XmlblasterClient

Inherits:
Object show all
Defined in:
lib/adaptation/xmlblaster/xmlblaster_client.rb

Overview

Direct Known Subclasses

XmlblasterCallbackClient

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xmlblaster_ip = nil, xmlblaster_port = nil, audit = nil) ⇒ XmlblasterClient

Returns a new instance of XmlblasterClient.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/adaptation/xmlblaster/xmlblaster_client.rb', line 11

def initialize( xmlblaster_ip = nil, xmlblaster_port = nil, audit = nil )

  if audit == nil then
    @audit = Logger.new(STDOUT)
    @audit.level = Logger::INFO
  else
    @audit = audit
  end

  @xmlblaster_ip = xmlblaster_ip
  @xmlblaster_port = xmlblaster_port

  @proxy = nil
  @sessionId = nil

  if @xmlblaster_ip then
    begin
      self.connect(@xmlblaster_ip, @xmlblaster_port)
    rescue => e
      @audit.warn( "XMLBlasterClient: Error connecting to XMLBlasterServer." )
      raise e
    end
  end

end

Instance Attribute Details

#xmlblaster_ipObject (readonly)

Returns the value of attribute xmlblaster_ip.



9
10
11
# File 'lib/adaptation/xmlblaster/xmlblaster_client.rb', line 9

def xmlblaster_ip
  @xmlblaster_ip
end

Instance Method Details

#connect(ip, port) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/adaptation/xmlblaster/xmlblaster_client.rb', line 37

def connect( ip, port )
  rpc="/RPC2"
  begin
    @proxy =   XMLRPC::Client.new( ip, rpc, port, nil, nil, nil, nil, nil,nil) 
  rescue => e
    @audit.warn( "XMLBlasterClient: new XMLRPC client creation failed.")
    raise e
  end
  @audit.debug( "XMLBlasterClient: XMLBlaster client to http://#{ip}:#{port}#{rpc}")
  return true
end

#erase(xmlKey, qos) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'lib/adaptation/xmlblaster/xmlblaster_client.rb', line 99

def erase( xmlKey, qos )
  begin
    returnValue = @proxy.call("xmlBlaster.erase", @sessionId, xmlKey,  qos )
    @audit.info( "==> ::ERASE:: <==      Success get with sessionID #{@sessionId}" )
  rescue XMLRPC::FaultException => e
    @audit.warn( "XMLBlasterClient: Error erase from MOM: #{e}" )
    raise e
  end
  return true
end

#get(xmlKey, qos) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/adaptation/xmlblaster/xmlblaster_client.rb', line 88

def get( xmlKey, qos )
  begin
    returnValue = @proxy.call("xmlBlaster.get", @sessionId, xmlKey,  qos )
    @audit.info( "==> ::GET:: <==      Success get with sessionID #{@sessionId}" )
  rescue  => e
    @audit.warn( "XMLBlasterClient: Error get from MOM: #{e}" )
    raise e
  end
  return returnValue
end

#login(username = 'guest', password = 'guest') ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/adaptation/xmlblaster/xmlblaster_client.rb', line 49

def ( username='guest', password='guest')
  qos = "<qos>
    <securityService type='htpasswd' version='1.0'>
      <![CDATA[
      <user>#{username}</user>
      <passwd>#{password}</passwd>
      ]]>
    </securityService>
    <session timeout='30000' maxSessions='99' clearSessions='false' />
  </qos>"
  @audit.debug( "XmlbasterClient: authenticate.connect QoS = #{qos}" )
  returnQos = @proxy.call("authenticate.connect", qos)
  @audit.debug( "XmlblasterClient:: authenticate.connect returnQos = #{returnQos}" )
  xml = REXML::Document.new(returnQos)
  @sessionId = xml.elements["//session"].attributes["sessionId"]
end

#logoutObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/adaptation/xmlblaster/xmlblaster_client.rb', line 66

def logout
  begin
    returnValue = @proxy.call("authenticate.logout", @sessionId)
    @audit.info( "==> ::LOGOUT:: <==      Success with sessionID #{@sessionId}, return Value: #{returnValue.to_s}" )
  rescue  => e
    @audit.warn( "XMLBlasterClient: Error logging out: #{e}" )
    raise e
  end
  return true
end

#printMessage(messages) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/adaptation/xmlblaster/xmlblaster_client.rb', line 110

def printMessage( messages )
  @audit.info( "Received #{messages.length} messages.")
  messages.each{ | message |
    key = message[0]
    content = message[1]
    qos = message[2]
    @audit.info "     Key = " + key.to_s
    @audit.info "     Content = " + content.lenght + " bytes"
    @audit.info "     QOS = " + qos.to_s
  }
end

#publish(xmlKey, content, qos) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/adaptation/xmlblaster/xmlblaster_client.rb', line 77

def publish( xmlKey, content, qos )
  begin
    returnValue = @proxy.call("xmlBlaster.publish", @sessionId, xmlKey, content, qos )
    @audit.info( "==> ::PUBLISH:: <==      Success publishing with sessionID #{@sessionId}")
  rescue  => e
    @audit.warn( "XMLBlasterClient: Error publishing to MOM: #{e}" )
    raise e
  end
  return true
end