com.echomine.jabber
Class JabberConnection

java.lang.Object
  extended by com.echomine.net.Connection
      extended by com.echomine.net.TimeableConnection
          extended by com.echomine.jabber.JabberConnection
All Implemented Interfaces:
JabberMessageListener, java.util.EventListener

public class JabberConnection
extends TimeableConnection
implements JabberMessageListener

This class represents a connection to a Jabber Server. Multiple Connections can be created to connect to multiple servers. This class never should deal with any high-level filtering or anything. It is essentially a pass through and receive for the protocol. Anything higher up should be handled by the net service or the service handlers. Authentication should be implemented at the high-level as the the connection does not keep any state other than being connected or disconnected, and queuing of messages to send and receive. This class also supports SSL-based connections if specified.


Field Summary
 
Fields inherited from class com.echomine.net.Connection
listenerList
 
Constructor Summary
JabberConnection(JabberSession session, JabberMessageReceiver receiver)
           
 
Method Summary
 void addConnectionListener(ConnectionListener l)
          adds a subscriber to listen for connection events
 void addMessageListener(JabberMessageListener l)
           
 void connect(ConnectionModel cmodel)
          This method is synchronous and will not return until connection is established or fails.
 void disconnect()
          Disconnects from the remote server
 ConnectionModel getConnectionModel()
           
 boolean isConnected()
           
 void messageReceived(JabberMessageEvent event)
          listens for a session init message in case it comes in before us sending a first.
 void removeConnectionListener(ConnectionListener l)
          remove from listening to connection events
 void removeMessageListener(JabberMessageListener l)
           
 void send(JabberMessage msg)
          Sends a message to the server
 void sendLater(java.lang.Runnable sendThread)
          this works the same as send() with the exception that the message will be wrapped in a separate thread before sending out the message.
 
Methods inherited from class com.echomine.net.TimeableConnection
fireConnectionClosed, fireConnectionEstablished
 
Methods inherited from class com.echomine.net.Connection
fireConnectionStarting, fireConnectionStartingWithoutVeto
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JabberConnection

public JabberConnection(JabberSession session,
                        JabberMessageReceiver receiver)
Method Detail

disconnect

public void disconnect()
Disconnects from the remote server


connect

public void connect(ConnectionModel cmodel)
             throws ConnectionFailedException
This method is synchronous and will not return until connection is established or fails.

Throws:
ConnectionFailedException - if connection is not established within the timeout period

send

public void send(JabberMessage msg)
          throws SendMessageFailedException
Sends a message to the server

Throws:
SendMessageFailedException

sendLater

public void sendLater(java.lang.Runnable sendThread)
this works the same as send() with the exception that the message will be wrapped in a separate thread before sending out the message. This method is most likely used when you need to send a synchronized message but doing so will cause your application to hang due to deadlock. The parameter is a thread. This thread will likely contain code to send a synchronized message. This method is similar to the way that Swing uses its invokeLater() method to do repainting.

Parameters:
sendThread - the thread that will get run to send a message

addConnectionListener

public void addConnectionListener(ConnectionListener l)
Description copied from class: Connection
adds a subscriber to listen for connection events

Overrides:
addConnectionListener in class Connection

removeConnectionListener

public void removeConnectionListener(ConnectionListener l)
Description copied from class: Connection
remove from listening to connection events

Overrides:
removeConnectionListener in class Connection

getConnectionModel

public ConnectionModel getConnectionModel()

isConnected

public boolean isConnected()

addMessageListener

public void addMessageListener(JabberMessageListener l)

removeMessageListener

public void removeMessageListener(JabberMessageListener l)

messageReceived

public void messageReceived(JabberMessageEvent event)
listens for a session init message in case it comes in before us sending a first. This is a workaround patch for servers that send stanzas first before the client does (not conforming to XMPP standards).

Specified by:
messageReceived in interface JabberMessageListener


Copyright © 2001-2005 Echomine. All Rights Reserved.