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
A partial implementation of the
Connection 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
FieldsModifier and TypeFieldDescriptionprotected final LinkedHashMap<ConnectionCloseListener,Object> Contains all registered listener for close event notification.protected LocalSessionThe session that owns this connection. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidSignals that all close operations for this connection have finished, completing the stage returned bygetCloseFuture().Set<org.dom4j.Namespace>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).Returns a stage that completes when ALL close operations for this connection have finished, including the physical transport closure and the invocation of all registeredConnectionCloseListenerinstances.intReturns the major version of XMPP being used by this connection (major_version.minor_version.intReturns the minor version of XMPP being used by this connection (major_version.minor_version.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 CompletableFuture<?>Notifies all registered close listeners that this 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, waitMethods inherited from interface org.jivesoftware.openfire.Connection
addCompression, close, close, deliver, deliverRawText, getAddress, getChannelBindingData, getCipherSuiteName, getConfiguration, getHostAddress, getHostName, getLocalCertificates, getPacketDeliverer, getPeerCertificates, getSupportedChannelBindingTypes, getTLSProtocolName, isClosed, isCompressed, isEncrypted, isInitialized, isUsingSelfSignedCertificate, setUsingSelfSignedCertificate, startCompression, startTLS, systemShutdown, validate
-
Field Details
-
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
The session that owns this connection.
-
-
Constructor Details
-
AbstractConnection
public AbstractConnection()
-
-
Method Details
-
init
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
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
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
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
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
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
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
Notifies all registered close listeners that this connection has been closed. Listeners are executed sequentially in descending priority order. Built-in listeners (such as those for client, server, or component sessions) use high-priority values to ensure critical cleanup logic (e.g. session removal from routing tables) occurs before any lower-priority or third-party listeners are invoked. For listeners sharing the same priority, the registration order is preserved. Each listener may return aCompletableFuturerepresenting asynchronous work. The next listener is not invoked until the previous listener's future has completed. The future returned by this method completes only after all listeners have been invoked and all listener-provided futures have completed. Exceptions thrown by listeners, whether synchronously during invocation or asynchronously via their returned future, are aggregated and propagated through the returned future rather than being swallowed or thrown directly. Subclasses must callcompleteCloseFuture()within thewhenCompletehandler of the future returned by this method, after all remaining teardown work for that connection type has finished. It must be called unconditionally — regardless of whether listeners completed normally or exceptionally.- Returns:
- a future that completes when all close listeners and their asynchronous work have finished.
- See Also:
-
getCloseFuture
Description copied from interface:ConnectionReturns a stage that completes when ALL close operations for this connection have finished, including the physical transport closure and the invocation of all registeredConnectionCloseListenerinstances. The stage completes normally withnullregardless of whether individual close listeners encountered errors. Listener errors are logged but do not cause the stage to complete exceptionally. Callers that must not establish a replacement connection until this one is fully torn down (e.g. to prevent duplicate session conflicts in server-to-server scenarios) should chain on this stage rather than relying onConnection.isClosed()alone.isClosed()returningtrueonly indicates that the intent to close has been recorded; teardown may still be in progress. The stage will only complete ifConnection.close()orConnection.close(StreamError)is eventually invoked. Callers that choose to await this stage should account for the possibility that close is never called on abandoned connections.- Specified by:
getCloseFuturein interfaceConnection- Returns:
- a
CompletionStagethat completes once all close processing is done. The returned stage is read-only; it cannot be used to externally trigger or cancel the close sequence.
-
completeCloseFuture
protected void completeCloseFuture()Signals that all close operations for this connection have finished, completing the stage returned bygetCloseFuture(). Must be called by subclasses at the very end of their close sequence, after the physical transport has been closed and allConnectionCloseListenerinstances have been notified. Calling this method more than once is safe. Subsequent calls have no effect. Subclasses that fail to call this method will leave any callers awaitinggetCloseFuture()suspended indefinitely.
-