Package org.jivesoftware.openfire.net
Class AbstractConnection
- java.lang.Object
-
- org.jivesoftware.openfire.net.AbstractConnection
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Connection
- Direct Known Subclasses:
NettyConnection,SocketConnection,VirtualConnection
public abstract class AbstractConnection extends Object implements Connection
A partial implementation of theConnectioninterface, implementing functionality that's commonly shared by Connection implementations.- Author:
- Guus der Kinderen, guus@goodbytes.nl
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.Connection
Connection.ClientAuth, Connection.CompressionPolicy, Connection.State, Connection.TLSPolicy
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<ConnectionCloseListener,Object>closeListenersContains all registered listener for close event notification.protected LocalSessionsessionThe session that owns this connection.
-
Constructor Summary
Constructors Constructor Description AbstractConnection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<org.dom4j.Namespace>getAdditionalNamespaces()When a connection is used to transmit an XML data, the root element of that data can define XML namespaces other than the ones that are default (eg: 'jabber:client', 'jabber:server', etc).intgetMajorXMPPVersion()Returns the major version of XMPP being used by this connection (major_version.minor_version.intgetMinorXMPPVersion()Returns the minor version of XMPP being used by this connection (major_version.minor_version.LocalSessiongetSession()Returns the session that owns this connection, if the connection has been initialized.voidinit(LocalSession owner)Initializes the connection with it's owning session.protected voidnotifyCloseListeners()Notifies all close listeners that the connection has been closed.voidregisterCloseListener(ConnectionCloseListener listener, Object callback)Registers a listener for close event notification.voidreinit(LocalSession owner)Reinitializes the connection to switch to a different session.voidremoveCloseListener(ConnectionCloseListener listener)Removes a registered close event listener.voidsetAdditionalNamespaces(Set<org.dom4j.Namespace> additionalNamespaces)When a connection is used to transmit an XML data, the root element of that data can define XML namespaces other than the ones that are default (eg: 'jabber:client', 'jabber:server', etc).voidsetXMPPVersion(int majorVersion, int minorVersion)Sets the XMPP version information.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.openfire.Connection
addCompression, close, close, deliver, deliverRawText, getAddress, getCipherSuiteName, getConfiguration, getHostAddress, getHostName, getLocalCertificates, getPacketDeliverer, getPeerCertificates, getTLSProtocolName, isClosed, isCompressed, isEncrypted, isInitialized, isSecure, isUsingSelfSignedCertificate, onUnexpectedDisconnect, setUsingSelfSignedCertificate, startCompression, startTLS, systemShutdown, validate
-
-
-
-
Field Detail
-
closeListeners
protected final Map<ConnectionCloseListener,Object> closeListeners
Contains all registered 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.
-
session
protected LocalSession session
The session that owns this connection.
-
-
Method Detail
-
init
public void init(LocalSession owner)
Description copied from interface:ConnectionInitializes the connection with it's owning session. Allows the connection class to configure itself with session related information (e.g. stream ID).- Specified by:
initin interfaceConnection- Parameters:
owner- the session that owns this connection
-
reinit
public void reinit(LocalSession owner)
Description copied from interface:ConnectionReinitializes the connection to switch to a different session. This allows for XEP-0198 resumption and transport-switching.- Specified by:
reinitin interfaceConnection- Parameters:
owner- The new session now owning the connection.
-
getSession
public LocalSession getSession()
Returns the session that owns this connection, if the connection has been initialized.- Returns:
- session that owns this connection.
-
getMajorXMPPVersion
public int getMajorXMPPVersion()
Description copied from interface:ConnectionReturns 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:
getMajorXMPPVersionin interfaceConnection- Returns:
- the major XMPP version being used by this connection.
-
getMinorXMPPVersion
public int getMinorXMPPVersion()
Description copied from interface:ConnectionReturns 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:
getMinorXMPPVersionin interfaceConnection- Returns:
- the minor XMPP version being used by this connection.
-
setXMPPVersion
public void setXMPPVersion(int majorVersion, int minorVersion)Description copied from interface:ConnectionSets 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:
setXMPPVersionin interfaceConnection- Parameters:
majorVersion- the major version.minorVersion- the minor version.
-
getAdditionalNamespaces
@Nonnull public Set<org.dom4j.Namespace> getAdditionalNamespaces()
Description copied from interface:ConnectionWhen a connection is used to transmit an XML data, the root element of that data can define XML namespaces other than the ones that are default (eg: 'jabber:client', 'jabber:server', etc). For an XML parser to be able to parse stanzas or other elements that are defined in that namespace (eg: are prefixed), these namespaces are recorded here.- Specified by:
getAdditionalNamespacesin interfaceConnection- Returns:
- A collection that contains all non-default namespaces that the peer defined when last opening a new stream.
-
setAdditionalNamespaces
public void setAdditionalNamespaces(@Nonnull Set<org.dom4j.Namespace> additionalNamespaces)Description copied from interface:ConnectionWhen a connection is used to transmit an XML data, the root element of that data can define XML namespaces other than the ones that are default (eg: 'jabber:client', 'jabber:server', etc). For an XML parser to be able to parse stanzas or other elements that are defined in that namespace (eg: are prefixed), these namespaces are recorded here.- Specified by:
setAdditionalNamespacesin interfaceConnection- Parameters:
additionalNamespaces- A collection that contains all non-default namespaces that the peer defined when last opening a new stream.
-
registerCloseListener
public void registerCloseListener(ConnectionCloseListener listener, Object callback)
Description copied from interface:ConnectionRegisters 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:
registerCloseListenerin interfaceConnection- Parameters:
listener- the listener to register for events.callback- the object to send in the event notification.
-
removeCloseListener
public void removeCloseListener(ConnectionCloseListener listener)
Description copied from interface:ConnectionRemoves 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:
removeCloseListenerin interfaceConnection- Parameters:
listener- the listener to deregister for close events.
-
notifyCloseListeners
protected void notifyCloseListeners()
Notifies all close listeners that the connection has been closed. Used by subclasses to properly finish closing the connection.
-
-