Openfire 3.5.2 Javadoc

org.jivesoftware.openfire.nio
Class NIOConnection

java.lang.Object
  extended by org.jivesoftware.openfire.nio.NIOConnection
All Implemented Interfaces:
Connection

public class NIOConnection
extends Object
implements Connection

Implementation of Connection inteface specific for NIO connections when using the MINA framework.

MINA project can be found at here.

Author:
Gaston Dombiak

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.Connection
Connection.ClientAuth, Connection.CompressionPolicy, Connection.TLSPolicy
 
Field Summary
static String CHARSET
          The utf-8 charset for decoding and encoding XMPP packet streams.
 
Constructor Summary
NIOConnection(org.apache.mina.common.IoSession session, PacketDeliverer packetDeliverer)
           
 
Method Summary
 void addCompression()
          Adds the compression filter to the connection but only filter incoming traffic.
 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.
 byte[] getAddress()
          Returns the raw IP address of this InetAddress object.
 Connection.CompressionPolicy getCompressionPolicy()
          Returns whether compression is optional or is disabled.
 String getHostAddress()
          Returns the IP address string in textual presentation.
 String getHostName()
          Gets the host name for this IP address.
 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.
 SSLSession getSSLSession()
          Returns the underlying SSLSession for the connection.
 Connection.TLSPolicy getTlsPolicy()
          Returns whether TLS is mandatory, optional or is disabled.
 void init(LocalSession owner)
          Initializes the connection with it's owning 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, Object ignore)
          Registers a listener for close event notification.
 void removeCloseListener(ConnectionCloseListener listener)
          Removes a registered close event listener.
 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 setLanaguage(String language)
          Sets the language code that should be used for this connection (e.g.
 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 compressing outgoing traffic for this connection.
 void startTLS(boolean clientMode, String remoteServer, Connection.ClientAuth authentication)
          Secures the plain connection by negotiating TLS with the other peer.
 void systemShutdown()
          Notification message indicating that the server is being shutdown.
 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

NIOConnection

public NIOConnection(org.apache.mina.common.IoSession session,
                     PacketDeliverer packetDeliverer)
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.

registerCloseListener

public void registerCloseListener(ConnectionCloseListener listener,
                                  Object ignore)
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.
ignore - the object to send in the event notification.

removeCloseListener

public void 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.

getAddress

public byte[] getAddress()
                  throws UnknownHostException
Description copied from interface: Connection
Returns the raw IP address of this InetAddress object. The result is in network byte order: the highest order byte of the address is in getAddress()[0].

Specified by:
getAddress in interface Connection
Returns:
the raw IP address of this object.
Throws:
UnknownHostException - if IP address of host could not be determined.

getHostAddress

public String getHostAddress()
                      throws UnknownHostException
Description copied from interface: Connection
Returns the IP address string in textual presentation.

Specified by:
getHostAddress in interface Connection
Returns:
the raw IP address in a string format.
Throws:
UnknownHostException - if IP address of host could not be determined.

getHostName

public String getHostName()
                   throws UnknownHostException
Description copied from interface: Connection
Gets the host name for this IP address.

If this InetAddress was created with a host name, this host name will be remembered and returned; otherwise, a reverse name lookup will be performed and the result will be returned based on the system configured name lookup service. If a lookup of the name service is required, call getCanonicalHostName.

If there is a security manager, its checkConnect method is first called with the hostname and -1 as its arguments to see if the operation is allowed. If the operation is not allowed, it will return the textual representation of the IP address.

Specified by:
getHostName in interface Connection
Returns:
the host name for this IP address, or if the operation is not allowed by the security check, the textual representation of the IP address.
Throws:
UnknownHostException - if IP address of host could not be determined.
See Also:
InetAddress.getCanonicalHostName(), SecurityManager.checkConnect(java.lang.String, int)

getSSLSession

public SSLSession getSSLSession()
Description copied from interface: Connection
Returns the underlying SSLSession for the connection.

Specified by:
getSSLSession in interface Connection
Returns:
null if no SSLSession is initialized yet.

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

init

public void init(LocalSession 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

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)

deliver

public void deliver(Packet packet)
             throws UnauthorizedException
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 - if a permission error was detected.

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.

startTLS

public void startTLS(boolean clientMode,
                     String remoteServer,
                     Connection.ClientAuth authentication)
              throws Exception
Description copied from interface: Connection
Secures the plain connection by negotiating TLS with the other peer. In a server-2-server connection the server requesting the TLS negotiation will be the client and the other server will be the server during the TLS negotiation. Therefore, the server requesting the TLS negotiation must pass true in the clientMode parameter and the server receiving the TLS request must pass false in the clientMode parameter. Both servers should specify the xmpp domain of the other server in the remoteServer parameter.

In the case of client-2-server the XMPP server must pass false in the clientMode parameter since it will behave as the server in the TLS negotiation. The remoteServer parameter will always be null.

Specified by:
startTLS in interface Connection
Parameters:
clientMode - boolean indicating if this entity is a client or a server in the TLS negotiation.
remoteServer - xmpp domain of the remote server or null. When null a ClientTrustManager will be used for verifying certificates otherwise a ServerTrustManager will be used.
authentication - policy to use for authenticating the remote peer.
Throws:
Exception - if an error occured while securing the connection.

addCompression

public void addCompression()
Description copied from interface: Connection
Adds the compression filter to the connection but only filter incoming traffic. Do not filter outgoing traffic since we still need to send an uncompressed stanza to the client indicating that he can start compressing the traffic. After we sent the uncompresses stanza we can start compression outgoing traffic as well.

Specified by:
addCompression in interface Connection

startCompression

public void startCompression()
Description copied from interface: Connection
Start compressing outgoing traffic 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

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)
Description copied from interface: Connection
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.

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)
Description copied from interface: Connection
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 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)
Description copied from interface: Connection
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.

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.

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)
Description copied from interface: Connection
Sets whether compression is enabled or is disabled.

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

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)
Description copied from interface: Connection
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.

toString

public String toString()
Overrides:
toString in class Object

Openfire 3.5.2 Javadoc

Copyright © 2003-2007 Jive Software.