Jive Messenger 2.2.2 Javadoc

org.jivesoftware.messenger.net
Class SocketConnection

java.lang.Object
  extended by org.jivesoftware.messenger.net.SocketConnection
All Implemented Interfaces:
Connection

public class SocketConnection
extends Object
implements Connection

An object to track the state of a XMPP client-server session. Currently this class contains the socket channel connecting the client and server.

Author:
Iain Shigeoka

Field Summary
static String CHARSET
          The utf-8 charset for decoding and encoding XMPP packet streams.
 
Constructor Summary
SocketConnection(PacketDeliverer deliverer, Socket socket, boolean isSecure)
          Create a new session using the supplied socket.
 
Method Summary
 void close()
          Close this session including associated socket connection.
 void deliver(Packet packet)
          Delivers the packet to this connection without checking the recipient.
 void deliverRawText(String text)
          Delivers raw text to this connection.
 InetAddress getInetAddress()
          Returns the InetAddress describing the connection.
 String getLanguage()
          Returns the language code that should be used for this connection (e.g.
 int getMajorXMPPVersion()
          Returns the major version of XMPP being used by this connection (major_version.minor_version.
 int getMinorXMPPVersion()
          Returns the minor version of XMPP being used by this connection (major_version.minor_version.
 Writer getWriter()
          Returns the Writer used to send data to the connection.
 void init(Session owner)
          Initializes the connection with it's owning session.
 boolean isClosed()
          Returns true if the connection/session is closed.
 boolean isFlashClient()
          Returns true if the connected client is a flash client.
 boolean isSecure()
          Returns true if this connection is secure.
 Object registerCloseListener(ConnectionCloseListener listener, Object handbackMessage)
          Registers a listener for close event notification.
 Object removeCloseListener(ConnectionCloseListener listener)
          Removes a registered close event listener.
 void setFlashClient(boolean flashClient)
          Sets whether the connected client is a flash client.
 void setLanaguage(String language)
          Sets the language code that should be used for this connection (e.g.
 void setXMPPVersion(int majorVersion, int minorVersion)
          Sets the XMPP version information.
 String toString()
           
 boolean validate()
          Verifies that the connection is still live.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHARSET

public static final String CHARSET
The utf-8 charset for decoding and encoding XMPP packet streams.

See Also:
Constant Field Values
Constructor Detail

SocketConnection

public SocketConnection(PacketDeliverer deliverer,
                        Socket socket,
                        boolean isSecure)
                 throws IOException
Create a new session using the supplied socket.

Parameters:
deliverer - the packet deliverer this connection will use.
socket - the socket to represent.
isSecure - true if this is a secure connection.
Throws:
NullPointerException - if the socket is null.
IOException
Method Detail

validate

public boolean validate()
Description copied from interface: Connection
Verifies that the connection is still live. Typically this is done by sending a whitespace character between packets.

Specified by:
validate in interface Connection
Returns:
true if the socket remains valid, false otherwise.

init

public void init(Session owner)
Description copied from interface: Connection
Initializes the connection with it's owning session. Allows the connection class to configure itself with session related information (e.g. stream ID).

Specified by:
init in interface Connection
Parameters:
owner - the session that owns this connection

registerCloseListener

public Object registerCloseListener(ConnectionCloseListener listener,
                                    Object handbackMessage)
Description copied from interface: Connection
Registers a listener for close event notification. Registrations after the Session is closed will be immediately notified before the registration call returns (within the context of the registration call). An optional handback object can be associated with the registration if the same listener is registered to listen for multiple connection closures.

Specified by:
registerCloseListener in interface Connection
Parameters:
listener - the listener to register for events.
handbackMessage - the object to send in the event notification.
Returns:
the message previously registered for this channel or null if no registration existed

removeCloseListener

public Object removeCloseListener(ConnectionCloseListener listener)
Description copied from interface: Connection
Removes a registered close event listener. Registered listeners must be able to receive close events up until the time this method returns. (i.e. it is possible to call unregister, receive a close event registration, and then have the unregister call return.)

Specified by:
removeCloseListener in interface Connection
Parameters:
listener - the listener to deregister for close events.
Returns:
the Message registered with this listener or null if the channel was never registered.

getInetAddress

public InetAddress getInetAddress()
Description copied from interface: Connection
Returns the InetAddress describing the connection.

Specified by:
getInetAddress in interface Connection
Returns:
the InetAddress describing the underlying connection properties.

getWriter

public Writer getWriter()
Description copied from interface: Connection
Returns the Writer used to send data to the connection. The writer should be used with caution. In the majority of cases, the Connection.deliver(Packet) method should be used to send data instead of using the writer directly. You must synchronize on the writer before writing data to it to ensure data consistency:
 Writer writer = connection.getWriter();
 synchronized(writer) {
     // write data....
 }

Specified by:
getWriter in interface Connection
Returns:
the Writer for this connection.

isClosed

public boolean isClosed()
Description copied from interface: Connection
Returns true if the connection/session is closed.

Specified by:
isClosed in interface Connection
Returns:
true if the connection is closed.

isSecure

public boolean isSecure()
Description copied from interface: Connection
Returns true if this connection is secure.

Specified by:
isSecure in interface Connection
Returns:
true if the connection is secure (e.g. SSL/TLS)

getMajorXMPPVersion

public int getMajorXMPPVersion()
Description copied from interface: Connection
Returns the major version of XMPP being used by this connection (major_version.minor_version. In most cases, the version should be "1.0". However, older clients using the "Jabber" protocol do not set a version. In that case, the version is "0.0".

Specified by:
getMajorXMPPVersion in interface Connection
Returns:
the major XMPP version being used by this connection.

getMinorXMPPVersion

public int getMinorXMPPVersion()
Description copied from interface: Connection
Returns the minor version of XMPP being used by this connection (major_version.minor_version. In most cases, the version should be "1.0". However, older clients using the "Jabber" protocol do not set a version. In that case, the version is "0.0".

Specified by:
getMinorXMPPVersion in interface Connection
Returns:
the minor XMPP version being used by this connection.

setXMPPVersion

public void setXMPPVersion(int majorVersion,
                           int minorVersion)
Sets the XMPP version information. In most cases, the version should be "1.0". However, older clients using the "Jabber" protocol do not set a version. In that case, the version is "0.0".

Parameters:
majorVersion - the major version.
minorVersion - the minor version.

getLanguage

public String getLanguage()
Description copied from interface: Connection
Returns the language code that should be used for this connection (e.g. "en").

Specified by:
getLanguage in interface Connection
Returns:
the language code for the connection.

setLanaguage

public void setLanaguage(String language)
Sets the language code that should be used for this connection (e.g. "en").

Parameters:
language - the language code.

isFlashClient

public boolean isFlashClient()
Description copied from interface: Connection
Returns true if the connected client is a flash client. Flash clients need to receive a special character (i.e. \0) at the end of each xml packet. Flash clients may send the character \0 in incoming packets and may start a connection using another openning tag such as: "flash:client".

Specified by:
isFlashClient in interface Connection
Returns:
true if the connected client is a flash client.

setFlashClient

public void setFlashClient(boolean flashClient)
Sets whether the connected client is a flash client. Flash clients need to receive a special character (i.e. \0) at the end of each xml packet. Flash clients may send the character \0 in incoming packets and may start a connection using another openning tag such as: "flash:client".

Parameters:
flashClient - true if the if the connection is a flash client.

close

public void close()
Description copied from interface: Connection
Close this session including associated socket connection. The order of events for closing the session is:

Specified by:
close in interface Connection

deliver

public void deliver(Packet packet)
             throws UnauthorizedException,
                    PacketException
Description copied from interface: Connection
Delivers the packet to this connection without checking the recipient. The method essentially calls socket.send(packet.getWriteBuffer()).

Specified by:
deliver in interface Connection
Parameters:
packet - the packet to deliver.
Throws:
UnauthorizedException
PacketException

deliverRawText

public void deliverRawText(String text)
Description copied from interface: Connection
Delivers raw text to this connection. This is a very low level way for sending XML stanzas to the client. This method should not be used unless you have very good reasons for not using Connection.deliver(org.xmpp.packet.Packet).

This method avoids having to get the writer of this connection and mess directly with the writer. Therefore, this method ensures a correct delivery of the stanza even if other threads were sending data concurrently.

Specified by:
deliverRawText in interface Connection
Parameters:
text - the XML stanzas represented kept in a String.

toString

public String toString()
Overrides:
toString in class Object

Jive Messenger 2.2.2 Javadoc

Copyright © 1999-2004 Jive Software.