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 theConnection
interface, 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>
closeListeners
Contains all registered listener for close event notification.protected LocalSession
session
The 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).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.LocalSession
getSession()
Returns the session that owns this connection, if the connection has been initialized.void
init(LocalSession owner)
Initializes the connection with it's owning session.protected void
notifyCloseListeners()
Notifies all close listeners that the connection has been closed.void
registerCloseListener(ConnectionCloseListener listener, Object callback)
Registers a listener for close event notification.void
reinit(LocalSession owner)
Reinitializes the connection to switch to a different session.void
removeCloseListener(ConnectionCloseListener listener)
Removes a registered close event listener.void
setAdditionalNamespaces(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).void
setXMPPVersion(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, close, deliver, deliverRawText, getAddress, getCipherSuiteName, getConfiguration, getHostAddress, getHostName, getLocalCertificates, getPacketDeliverer, getPeerCertificates, getTLSProtocolName, isClosed, isCompressed, isEncrypted, isInitialized, isSecure, isUsingSelfSignedCertificate, 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: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 interfaceConnection
- Parameters:
owner
- the session that owns this connection
-
reinit
public void reinit(LocalSession owner)
Description copied from interface:Connection
Reinitializes the connection to switch to a different session. This allows for XEP-0198 resumption and transport-switching.- Specified by:
reinit
in 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: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 interfaceConnection
- 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 interfaceConnection
- 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 interfaceConnection
- Parameters:
majorVersion
- the major version.minorVersion
- the minor version.
-
getAdditionalNamespaces
@Nonnull public Set<org.dom4j.Namespace> getAdditionalNamespaces()
Description copied from interface:Connection
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). 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:
getAdditionalNamespaces
in 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:Connection
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). 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:
setAdditionalNamespaces
in 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: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 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: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 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.
-
-