Class: AgentXmpp::Connection

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
EventMachine::XmlPushParser
Defined in:
lib/agent_xmpp/client/connection.rb

Overview


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Connection

.….….….….….….….….….….….….….….….….….….….….….….….….….….



16
17
18
19
# File 'lib/agent_xmpp/client/connection.rb', line 16

def initialize(client)
  @client = client
  @pipe = MessagePipe.new(self)
end

Instance Attribute Details

#clientObject (readonly)




12
13
14
# File 'lib/agent_xmpp/client/connection.rb', line 12

def client
  @client
end

#delegatesObject (readonly)




12
13
14
# File 'lib/agent_xmpp/client/connection.rb', line 12

def delegates
  @delegates
end

#keepaliveObject (readonly)




12
13
14
# File 'lib/agent_xmpp/client/connection.rb', line 12

def keepalive
  @keepalive
end

#pipeObject (readonly)




12
13
14
# File 'lib/agent_xmpp/client/connection.rb', line 12

def pipe
  @pipe
end

Instance Method Details

#characters(text) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



74
75
76
# File 'lib/agent_xmpp/client/connection.rb', line 74

def characters(text)
  @current.text = @current.text.to_s + text if @current
end

#connection_completedObject


EventMachine::Connection callbacks .….….….….….….….….….….….….….….….….….….….….….….….….….….



24
25
26
27
28
29
30
# File 'lib/agent_xmpp/client/connection.rb', line 24

def connection_completed
  @keepalive = EventMachine::PeriodicTimer.new(60) do 
    send_data("\n")
  end
  AgentXmpp.start_garbage_collection(pipe)
  pipe.connection_completed
end

#end_element(name) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



64
65
66
67
68
69
70
71
# File 'lib/agent_xmpp/client/connection.rb', line 64

def end_element(name)
  if @current and @current.parent
    @current = @current.parent
  else
    process
    @current = nil
  end
end

#error(*args) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



79
80
81
# File 'lib/agent_xmpp/client/connection.rb', line 79

def error(*args)
  AgentXmpp.logger.error *args
end

#processObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/agent_xmpp/client/connection.rb', line 84

def process
  if @current
    @current.add_namespace(@streamns) if @current.namespace('').to_s.eql?('')
    begin
      stanza = Xmpp::Stanza::import(@current)
    rescue Xmpp::NoNameXmlnsRegistered
      stanza = @current
    end
    if @current.xpath.eql?('stream:stream')
      @streamns = @current.namespace('') if @current.namespace('')
    end
    receive(stanza) if respond_to?(:receive)
  end
end

#receive(stanza) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



100
101
102
# File 'lib/agent_xmpp/client/connection.rb', line 100

def receive(stanza)
  pipe.receive(stanza)
end

#receive_data(data) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



33
34
35
# File 'lib/agent_xmpp/client/connection.rb', line 33

def receive_data(data)
  super(data)
end

#start_documentObject


EventMachine::XmlPushParser callbacks .….….….….….….….….….….….….….….….….….….….….….….….….….….



49
50
# File 'lib/agent_xmpp/client/connection.rb', line 49

def start_document
end

#start_element(name, attrs) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



53
54
55
56
57
58
59
60
61
# File 'lib/agent_xmpp/client/connection.rb', line 53

def start_element(name, attrs)
  e = REXML::Element.new(name)
  e.add_attributes(attrs)      
  @current = @current.nil? ? e : @current.add_element(e)  
  if @current.xpath == 'stream:stream'
    process
    @current = nil
  end
end

#unbindObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



38
39
40
41
42
43
44
# File 'lib/agent_xmpp/client/connection.rb', line 38

def unbind
  if @keepalive
    @keepalive.cancel
    @keepalive = nil
  end
  pipe.unbind
end