Class Jabber::Reliable::Listener
In: lib/xmpp4r/reliable.rb
Parent: Object
Message Presence XMPPStanza Iq XMPPElement ErrorResponse X IqQuery JabberError ComponentAuthenticationFailure ArgumentError InvalidChatState SOCKS5Error ServerError NoNameXmlnsRegistered ServerDisconnected ClientAuthenticationFailure Connection Client Component Connection Client Singleton IdGenerator Comparable JID Enumerable CallbackList Items Publish StandardError REXML::Element Stream XMPPElement Location IqFeature StreamHost IqSiFile IqSiFileRange IqSi StreamHostUsed XRosterItem RosterItem C Body HTML UserItem XMUCUserInvite Configuration Retract IqPubSub Item IqPubSubOwner Event Subscription Unsubscribe Tune XDataField XDataReported XDataTitle XDataInstructions Feature Item Identity IqVcard PubSub::ServiceHelper Helper Helper SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IqQuery IqQueryBytestreams IqQueryRoster IqQueryVersion IqQueryRPC IqQueryMUCOwner IqQueryMUCAdmin IqQueryDiscoItems IqQueryDiscoInfo IqQueryLastActivity IBB IBBTarget IBBInitiator RosterXItem XRoster RosterX X XDelay XMUC XMUCUser XData Responder SimpleResponder Iq IqCommand XMLRPC::ParserWriterChooseMixin Client Server XMLRPC::ParseContentType XMLRPC::BasicServer MUCClient SimpleMUCClient MUC::UserItem XMUCUserItem IqQueryMUCAdminItem XParent SubscriptionConfig NodeConfig OwnerNodeConfig EventItems ServiceHelper OAuthServiceHelper NodeHelper EventItem Base Anonymous DigestMD5 Plain FileSource Base Bot Callback StreamParser Semaphore SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Helper Responder Helper Listener MUCBrowser NodeBrowser ListenerMocker Helper Responder Helper Helper Helper lib/xmpp4r/message.rb lib/xmpp4r/connection.rb lib/xmpp4r/xmppstanza.rb lib/xmpp4r/iq.rb lib/xmpp4r/callbacks.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/stream.rb lib/xmpp4r/client.rb lib/xmpp4r/jid.rb lib/xmpp4r/x.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/semaphore.rb lib/xmpp4r/errors.rb lib/xmpp4r/component.rb lib/xmpp4r/presence.rb lib/xmpp4r/xmppelement.rb lib/xmpp4r/query.rb XParent lib/xmpp4r/location/helper/helper.rb lib/xmpp4r/location/location.rb UserLocation lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb Bytestreams lib/xmpp4r/roster/x/roster.rb lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb Roster lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb lib/xmpp4r/version/iq/version.rb Version lib/xmpp4r/command/iq/command.rb lib/xmpp4r/command/helper/responder.rb Command lib/xmpp4r/caps/helper/helper.rb lib/xmpp4r/caps/c.rb Caps lib/xmpp4r/reliable.rb Reliable lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/xhtml/html.rb XHTML lib/xmpp4r/rpc/helper/server.rb lib/xmpp4r/rpc/helper/client.rb lib/xmpp4r/rpc/iq/rpc.rb RPC lib/xmpp4r/muc/iq/mucadminitem.rb lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/item.rb lib/xmpp4r/muc/helper/simplemucclient.rb lib/xmpp4r/muc/iq/mucadmin.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/iq/mucowner.rb lib/xmpp4r/muc/helper/mucclient.rb MUC lib/xmpp4r/pubsub/children/item.rb lib/xmpp4r/pubsub/children/configuration.rb lib/xmpp4r/pubsub/children/subscription.rb lib/xmpp4r/pubsub/helper/servicehelper.rb lib/xmpp4r/pubsub/children/unsubscribe.rb lib/xmpp4r/pubsub/children/publish.rb lib/xmpp4r/pubsub/helper/oauth_service_helper.rb lib/xmpp4r/pubsub/children/event.rb lib/xmpp4r/pubsub/iq/pubsub.rb lib/xmpp4r/pubsub/children/retract.rb lib/xmpp4r/pubsub/helper/nodebrowser.rb lib/xmpp4r/pubsub/helper/nodehelper.rb lib/xmpp4r/pubsub/children/items.rb lib/xmpp4r/pubsub/children/subscription_config.rb lib/xmpp4r/pubsub/children/node_config.rb OAuthPubSubStreamHelper PubSub lib/xmpp4r/httpbinding/client.rb HTTPBinding lib/xmpp4r/tune/helper/helper.rb lib/xmpp4r/tune/tune.rb UserTune lib/xmpp4r/sasl.rb SASL lib/xmpp4r/test/listener_mocker.rb Test lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/discovery/helper/helper.rb lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/helper/responder.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/last/helper/helper.rb lib/xmpp4r/last/iq/last.rb LastActivity lib/xmpp4r/framework/base.rb lib/xmpp4r/framework/bot.rb Framework lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard Jabber dot/m_110_0.png

Methods

Public Class methods

[Source]

    # File lib/xmpp4r/reliable.rb, line 49
49:       def initialize(full_jid, password, config, &block)
50:         @on_message_block = block
51:         @full_jid = full_jid
52:         @config = config
53:         @password = password
54:         @max_retry = config[:max_retry] || 30
55:       end

Public Instance methods

[Source]

     # File lib/xmpp4r/reliable.rb, line 100
100:       def add_exception_handler(&block)
101:         @exception_handlers << block
102:       end

[Source]

     # File lib/xmpp4r/reliable.rb, line 125
125:       def auth
126:         @connection.auth(@password)
127:       end

[Source]

     # File lib/xmpp4r/reliable.rb, line 121
121:       def connect
122:         @connection.connect        
123:       end

[Source]

    # File lib/xmpp4r/reliable.rb, line 88
88:       def run_exception_handlers(e, connection, where_failed)
89:         @exception_handlers.each do |ex_handler|
90:           ex_handler.call(e, connection, where_failed)
91:         end
92:         if where_failed == :sending
93:           @message_to_send_on_reconnect = @message_now_sending
94:         end
95:         if where_failed != :close && !@connection.is_connected?
96:           @reconnection_thread.raise(e)
97:         end
98:       end

TODO: test and fix situation where we get disconnected while sending but then successfully reconnect

 (and make sure in such cases we resent)

[Source]

     # File lib/xmpp4r/reliable.rb, line 138
138:       def send_message(message)
139:         unless @connection
140:           raise ::ArgumentError, "Can't send messages while listener is stopped.  Plase 'start' the listener first."
141:         end
142:         retry_count = 0
143:         begin
144:           while(not @connection.is_connected?)
145:             #wait
146:             Thread.pass
147:           end
148:           @message_now_sending = message
149:           @connection.send(message)
150:           return true #true, message was sent
151:         rescue => e
152:           if e.is_a?(Interrupt)
153:             raise e
154:           end
155:           if(retry_count > @max_retry.to_i)
156:             Jabber::debuglog "reached max retry count on message re-send, failing"
157:             raise e
158:           end
159:           retry_count += 1
160:           Jabber::debuglog "retrying message send.." + e.inspect
161:           retry
162:         end
163:       end

[Source]

     # File lib/xmpp4r/reliable.rb, line 129
129:       def send_presence
130:         presence_message = @config[:presence_message]
131:         if presence_message && !presence_message.empty?
132:           @connection.send(Jabber::Presence.new.set_show(:chat).set_status(presence_message))
133:         end
134:       end

[Source]

    # File lib/xmpp4r/reliable.rb, line 57
57:       def setup_connection
58:         @connection = Connection.new(@full_jid, @config)
59:         if @on_message_block
60:           @connection.add_message_callback(&@on_message_block)
61:         else
62:           @connection.add_message_callback do |msg|
63:             self.on_message(msg)
64:           end
65:         end
66:         
67:         #We could just reconnect in @connection.on_exception, 
68:         #but by raising into this seperate thread, we avoid growing our stack trace
69:         @reconnection_thread = Thread.new do
70:           first_run = true
71:           begin
72:             self.start unless first_run
73:             loop do 
74:               sleep(1)
75:               Thread.pass
76:             end
77:           rescue => e
78:             first_run = false
79:             retry
80:           end
81:         end
82:         @exception_handlers = []
83:         @connection.on_exception do |e, connection, where_failed|
84:           self.run_exception_handlers(e, connection, where_failed)
85:         end
86:       end

[Source]

     # File lib/xmpp4r/reliable.rb, line 104
104:       def start
105:         setup_connection unless @connection
106:         connect
107:         auth
108:         send_presence
109:         if @message_to_send_on_reconnect
110:           send_message(@message_to_send_on_reconnect)
111:         end
112:         @message_to_send_on_reconnect = nil
113:       end

Stop the listener. (close the connection)

[Source]

     # File lib/xmpp4r/reliable.rb, line 116
116:       def stop
117:         @connection.close if @connection and @connection.is_connected?
118:         @connection = nil
119:       end

[Validate]