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 the Connection interface, implementing functionality that's commonly shared by Connection implementations.
Author:
Guus der Kinderen, guus@goodbytes.nl
  • Field Details

    • closeListeners

      protected final LinkedHashMap<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.
  • Constructor Details

    • AbstractConnection

      public AbstractConnection()
  • Method Details

    • 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
    • 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 interface Connection
      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 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.
    • 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 interface Connection
      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 interface Connection
      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 interface Connection
      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 interface Connection
      Parameters:
      listener - the listener to deregister for close events.
    • notifyCloseListeners

      protected CompletableFuture<?> notifyCloseListeners()
      Notifies all registered ConnectionCloseListeners that the connection is being closed. Listener invocation is performed asynchronously and is explicitly offloaded from the thread that initiates the close operation. This prevents blocking or long-running listener implementations (for example, those performing database or network I/O) from interfering with connection shutdown or I/O processing performed by subclasses. Listeners are executed in order of their priority, with higher priority values being executed first. Built-in listeners (such as those for client, server, or component sessions) use high priority values to ensure they are executed before third-party listeners. This guarantees that critical cleanup logic (e.g., session removal from routing tables) occurs before any other listeners are invoked. Execution Order: Listeners are executed sequentially, in priority order. Each listener is only invoked after all higher-priority listeners have completed. This ensures that lower-priority listeners always observe a consistent, post-cleanup state. Each listener may return a CompletableFuture to represent asynchronous work that continues after the listener is invoked. 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 during completion of their returned Future, are captured and propagated via the returned Future. When the ConnectionManager instance or its event executor is not available, this method skips invocation of registered listeners and returns a failed Future. It is assumed that this happens only when the server is shutting down.
      Returns:
      A Future that completes when all close listeners have been invoked and all listener-provided asynchronous work has completed.
      See Also: