Class: XmppGateway::XmppPool

Inherits:
Object
  • Object
show all
Defined in:
lib/xmpp_gateway/xmpp_pool.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, password) ⇒ XmppPool

Returns a new instance of XmppPool.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xmpp_gateway/xmpp_pool.rb', line 16

def initialize(user, password)
  @jid = Blather::JID.new(user)
  
  if stale?
    XmppGateway.logger.debug "Stale XMPP connection #{@jid}"
    connections.delete @jid.to_s
  end
  
  if record = connections[@jid.to_s]
    # Connection exists
    XmppGateway.logger.debug "Reusing XMPP connection #{@jid}"
    
    @connection = record[:connection]
    @connected  = record[:password] == password
  else
    # Create connection
    XmppGateway.logger.debug "Creating XMPP connection #{@jid}"
    
    @connection = XmppInterface.new(user, password)
    @connected  = @connection.connected
    
    if @connected
      # Cache the connection
      connections[@jid.to_s] = {:password => password, :connection => @connection}
    end
  end
end

Instance Attribute Details

#connectedObject (readonly)

Returns the value of attribute connected.



6
7
8
# File 'lib/xmpp_gateway/xmpp_pool.rb', line 6

def connected
  @connected
end

Class Method Details

.connectionsObject



12
13
14
# File 'lib/xmpp_gateway/xmpp_pool.rb', line 12

def self.connections
  @@connections ||= {}
end

.stanza(s) ⇒ Object



8
9
10
# File 'lib/xmpp_gateway/xmpp_pool.rb', line 8

def self.stanza(s)
  XmppInterface.stanza s
end

Instance Method Details

#clientObject



44
45
46
# File 'lib/xmpp_gateway/xmpp_pool.rb', line 44

def client
  @connection.client
end

#write(s) ⇒ Object



48
49
50
# File 'lib/xmpp_gateway/xmpp_pool.rb', line 48

def write(s)
  @connection.write(s)
end