Connection Manager 3.5.1 Javadoc

org.jivesoftware.multiplexer.net
Class SocketConnection

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

public class SocketConnection
extends java.lang.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.

This class was copied from Openfire. PacketInterceptors were removed. Session concept was removed. ConnectionCloseListeners were removed.

Author:
Gaston Dombiak

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jivesoftware.multiplexer.Connection
Connection.CompressionPolicy, Connection.TLSPolicy
 
Field Summary
static java.lang.String CHARSET
          The utf-8 charset for decoding and encoding XMPP packet streams.
 
Constructor Summary
SocketConnection(PacketDeliverer backupDeliverer, java.net.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(java.lang.String stanza)
          Delivers the packet to this connection without checking the recipient.
 void deliverRawText(java.lang.String text)
          Delivers raw text to this connection.
 Connection.CompressionPolicy getCompressionPolicy()
          Returns whether compression is optional or is disabled.
 long getIdleTimeout()
           
 java.net.InetAddress getInetAddress()
          Returns the InetAddress describing the connection.
static java.util.Collection<SocketConnection> getInstances()
           
 java.lang.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.
 PacketDeliverer getPacketDeliverer()
          Returns the packet deliverer to use when delivering a packet over the socket fails.
 int getPort()
          Returns the port that the connection uses.
 javax.net.ssl.SSLSession getSSLSession()
           
 Connection.TLSPolicy getTlsPolicy()
          Returns whether TLS is mandatory, optional or is disabled.
 TLSStreamHandler getTLSStreamHandler()
          Returns the stream handler responsible for securing the plain connection and providing the corresponding input and output streams.
 void init(Session owner)
          Initializes the connection that is related to the specified session.
 boolean isClosed()
          Returns true if the connection/session is closed.
 boolean isCompressed()
          Returns true if the connection is using compression.
 boolean isFlashClient()
          Returns true if the connected client is a flash client.
 boolean isSecure()
          Returns true if this connection is secure.
 void registerCloseListener(ConnectionCloseListener listener, java.lang.Object handbackMessage)
          Registers a new listener that will react when this connection is closed.
 void removeCloseListener(ConnectionCloseListener listener)
          Removes a listener that was reacting when this connection was closed.
 void setCompressionPolicy(Connection.CompressionPolicy compressionPolicy)
          Sets whether compression is enabled or is disabled.
 void setFlashClient(boolean flashClient)
          Sets whether the connected client is a flash client.
 void setIdleTimeout(long timeout)
          Sets the number of milliseconds a connection has to be idle to be closed.
 void setLanaguage(java.lang.String language)
          Sets the language code that should be used for this connection (e.g.
 void setSocketStatistic(SocketStatistic socketStatistic)
           
 void setTlsPolicy(Connection.TLSPolicy tlsPolicy)
          Sets whether TLS is mandatory, optional or is disabled.
 void setXMPPVersion(int majorVersion, int minorVersion)
          Sets the XMPP version information.
 void startCompression()
          Start using compression for this connection.
 void startTLS(boolean clientMode, java.lang.String remoteServer)
          Secures the plain connection by negotiating TLS with the client.
 void systemShutdown()
          Notification message indicating that the server is being shutdown.
 java.lang.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 java.lang.String CHARSET
The utf-8 charset for decoding and encoding XMPP packet streams.

See Also:
Constant Field Values
Constructor Detail

SocketConnection

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

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

getInstances

public static java.util.Collection<SocketConnection> getInstances()

getTLSStreamHandler

public TLSStreamHandler getTLSStreamHandler()
Returns the stream handler responsible for securing the plain connection and providing the corresponding input and output streams.

Returns:
the stream handler responsible for securing the plain connection and providing the corresponding input and output streams.

startTLS

public void startTLS(boolean clientMode,
                     java.lang.String remoteServer)
              throws java.io.IOException
Description copied from interface: Connection
Secures the plain connection by negotiating TLS with the client. When connecting to a remote server then clientMode will be true and remoteServer is the server name of the remote server. Otherwise clientMode will be false and remoteServer null.

Specified by:
startTLS in interface Connection
Parameters:
clientMode - boolean indicating if this entity is a client or a server.
remoteServer - server name of the remote server we are connecting to or null when not in client mode.
Throws:
java.io.IOException

startCompression

public void startCompression()
Description copied from interface: Connection
Start using compression for this connection. Compression will only be available after TLS has been negotiated. This means that a connection can never be using compression before TLS. However, it is possible to use compression without TLS.

Specified by:
startCompression in interface Connection

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 that is related to the specified session. The session is the only owner of this connection.

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

registerCloseListener

public void registerCloseListener(ConnectionCloseListener listener,
                                  java.lang.Object handbackMessage)
Description copied from interface: Connection
Registers a new listener that will react when this connection is closed.

Specified by:
registerCloseListener in interface Connection
Parameters:
listener - the new listener.
handbackMessage - the object to send back when notifying that the connection was closed.

removeCloseListener

public void removeCloseListener(ConnectionCloseListener listener)
Description copied from interface: Connection
Removes a listener that was reacting when this connection was closed.

Specified by:
removeCloseListener in interface Connection
Parameters:
listener - the listener to remove.

getInetAddress

public java.net.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.

getPort

public int getPort()
Returns the port that the connection uses.

Returns:
the port that the connection uses.

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)

isCompressed

public boolean isCompressed()
Description copied from interface: Connection
Returns true if the connection is using compression.

Specified by:
isCompressed in interface Connection
Returns:
true if the connection is using compression.

getTlsPolicy

public Connection.TLSPolicy getTlsPolicy()
Description copied from interface: Connection
Returns whether TLS is mandatory, optional or is disabled. When TLS is mandatory clients are required to secure their connections or otherwise their connections will be closed. On the other hand, when TLS is disabled clients are not allowed to secure their connections using TLS. Their connections will be closed if they try to secure the connection. in this last case.

Specified by:
getTlsPolicy in interface Connection
Returns:
whether TLS is mandatory, optional or is disabled.

setTlsPolicy

public void setTlsPolicy(Connection.TLSPolicy tlsPolicy)
Sets whether TLS is mandatory, optional or is disabled. When TLS is mandatory clients are required to secure their connections or otherwise their connections will be closed. On the other hand, when TLS is disabled clients are not allowed to secure their connections using TLS. Their connections will be closed if they try to secure the connection. in this last case.

Specified by:
setTlsPolicy in interface Connection
Parameters:
tlsPolicy - whether TLS is mandatory, optional or is disabled.

getCompressionPolicy

public Connection.CompressionPolicy getCompressionPolicy()
Description copied from interface: Connection
Returns whether compression is optional or is disabled.

Specified by:
getCompressionPolicy in interface Connection
Returns:
whether compression is optional or is disabled.

setCompressionPolicy

public void setCompressionPolicy(Connection.CompressionPolicy compressionPolicy)
Sets whether compression is enabled or is disabled.

Specified by:
setCompressionPolicy in interface Connection
Parameters:
compressionPolicy - whether Compression is enabled or is disabled.

getIdleTimeout

public long getIdleTimeout()

setIdleTimeout

public void setIdleTimeout(long timeout)
Sets the number of milliseconds a connection has to be idle to be closed. Sending stanzas to the client is not considered as activity. We are only considering the connection active when the client sends some data or hearbeats (i.e. whitespaces) to the server.

Parameters:
timeout - the number of milliseconds a connection has to be idle to be closed.

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".

Specified by:
setXMPPVersion in interface Connection
Parameters:
majorVersion - the major version.
minorVersion - the minor version.

getLanguage

public java.lang.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(java.lang.String language)
Sets the language code that should be used for this connection (e.g. "en").

Specified by:
setLanaguage in interface Connection
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".

Specified by:
setFlashClient in interface Connection
Parameters:
flashClient - true if the if the connection is a flash client.

getSSLSession

public javax.net.ssl.SSLSession getSSLSession()

getPacketDeliverer

public PacketDeliverer getPacketDeliverer()
Description copied from interface: Connection
Returns the packet deliverer to use when delivering a packet over the socket fails. The packet deliverer will retry to send the packet using some other connection, will store the packet offline for later retrieval or will just drop it.

Specified by:
getPacketDeliverer in interface Connection
Returns:
the packet deliverer to use when delivering a packet over the socket fails.

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

systemShutdown

public void systemShutdown()
Description copied from interface: Connection
Notification message indicating that the server is being shutdown. Implementors should send a stream error whose condition is system-shutdown before closing the connection.

Specified by:
systemShutdown in interface Connection

deliver

public void deliver(java.lang.String stanza)
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:
stanza - the stanza to deliver.

deliverRawText

public void deliverRawText(java.lang.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(String).

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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

setSocketStatistic

public void setSocketStatistic(SocketStatistic socketStatistic)

Connection Manager 3.5.1 Javadoc

Copyright © 2003-2006 Jive Software.