Package rocks.xmpp.core.net
Class AbstractConnection
- java.lang.Object
-
- rocks.xmpp.core.net.AbstractConnection
-
- All Implemented Interfaces:
AutoCloseable
,Connection
,StreamHandler
- Direct Known Subclasses:
BoshConnection
,TcpConnection
,WebSocketConnection
public abstract class AbstractConnection extends Object implements Connection, StreamHandler
An abstract connection implementation.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the connection.CompletionStage<Void>
closeAsync()
Asynchronously closes the connection.CompletionStage<Void>
closeAsync(StreamError streamError)
Asynchronously closes the connection with a stream error.ConnectionConfiguration
getConfiguration()
Gets the configuration used to create this connection.String
getStreamId()
Gets the stream id of this connection.boolean
handleElement(Object streamElement)
Handles an inbound stream element.boolean
isClosed()
If the connection is closed.boolean
isUsingAcknowledgements()
Indicates whether this connection uses acknowledgements, e.g. by means of stream management or BOSH acks.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface rocks.xmpp.core.net.Connection
closeFuture, flush, getRemoteAddress, isSecure, open, send, write
-
-
-
-
Method Detail
-
getConfiguration
public final ConnectionConfiguration getConfiguration()
Description copied from interface:Connection
Gets the configuration used to create this connection.- Specified by:
getConfiguration
in interfaceConnection
- Returns:
- The
-
isUsingAcknowledgements
public boolean isUsingAcknowledgements()
Description copied from interface:Connection
Indicates whether this connection uses acknowledgements, e.g. by means of stream management or BOSH acks.- Specified by:
isUsingAcknowledgements
in interfaceConnection
- Returns:
- If this connection uses acknowledgements.
-
handleElement
public boolean handleElement(Object streamElement)
Description copied from interface:StreamHandler
Handles an inbound stream element.- Specified by:
handleElement
in interfaceStreamHandler
- Parameters:
streamElement
- The stream element.- Returns:
- True, if the stream must be restarted.
-
getStreamId
public final String getStreamId()
Description copied from interface:Connection
Gets the stream id of this connection.- Specified by:
getStreamId
in interfaceConnection
- Returns:
- The stream id.
-
closeAsync
public final CompletionStage<Void> closeAsync()
Description copied from interface:Connection
Asynchronously closes the connection.Closing usually involves a round-trip with the peer on the XMPP layer first by sending a closing stream element, then waiting on the response and then closing the underlying transport layer.
Implementations wait a maximum of 500ms for the XMPP level close.
- Specified by:
closeAsync
in interfaceConnection
- Returns:
- The future, which is complete, when the connection is closed.
- See Also:
Connection.close()
-
closeAsync
public final CompletionStage<Void> closeAsync(StreamError streamError)
Description copied from interface:Connection
Asynchronously closes the connection with a stream error.- Specified by:
closeAsync
in interfaceConnection
- Parameters:
streamError
- The stream error, which is sent before closing the stream.- Returns:
- The completion stage, which is complete, when the connection is closed.
- See Also:
Connection.closeAsync()
-
close
public final void close() throws Exception
Closes the connection. This method blocks until everything is closed (max. 1s).- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Throws:
Exception
- If the close failed.- See Also:
closeAsync()
-
isClosed
public final boolean isClosed()
If the connection is closed.- Returns:
- True, if closed.
-
-