Class ModularXmppClientToServerConnection
- java.lang.Object
-
- org.jivesoftware.smack.AbstractXMPPConnection
-
- org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection
-
- All Implemented Interfaces:
XMPPConnection
public final class ModularXmppClientToServerConnection extends AbstractXMPPConnection
The superclass of Smack's Modular Connection Architecture.Note: Everything related to the modular connection architecture is currently considered experimental and should not be used in production. Use the mature
XMPPTCPConnection
if you do not feel adventurous.Smack's modular connection architecture allows to extend a XMPP c2s (client-to-server) connection with additional functionality by adding modules. Those modules extend the Finite State Machine (FSM) within the connection with new states. Connection modules can either be
- Transports
- Extensions
Transports bind the XMPP XML stream to an underlying transport like TCP, WebSockets, BOSH, and allow for the different particularities of transports like DirectTLS (XEP-0368). This eventually means that a single transport module can implement multiple transport mechanisms. For example the TCP transport module implements the RFC6120 TCP and the XEP-0368 direct TLS TCP transport bindings.
Extensions allow for a richer functionality of the connection. Those include
- Compression
- zlib ([XEP-0138](https://xmpp.org/extensions/xep-0138.html))
- [Efficient XML Interchange (EXI)](https://www.w3.org/TR/exi/)
- Instant Stream Resumption ([XEP-0397](https://xmpp.org/extensions/xep-0397.html)
- Bind2
- Stream Management
Connection modules are plugged into the the modular connection via their constructor. and they usually declare backwards edges to some common, generic connection state of the FSM.
Modules and states always have an accompanying *descriptor* type. `ModuleDescriptor` and `StateDescriptor` exist without an connection instance. They describe the module and state metadata, while their modules and states are Instantiated once a modular connection is instantiated.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ModularXmppClientToServerConnection.AuthenticatedAndResourceBoundStateDescriptor
static class
ModularXmppClientToServerConnection.AuthenticatedButUnboundStateDescriptor
static class
ModularXmppClientToServerConnection.ConnectedButUnauthenticatedStateDescriptor
static class
ModularXmppClientToServerConnection.DisconnectedStateDescriptor
static class
ModularXmppClientToServerConnection.LookupRemoteConnectionEndpointsStateDescriptor
static class
ModularXmppClientToServerConnection.ResourceBindingStateDescriptor
static class
ModularXmppClientToServerConnection.ResourceBoundResult
static class
ModularXmppClientToServerConnection.SaslAuthenticationStateDescriptor
static class
ModularXmppClientToServerConnection.SaslAuthenticationSuccessResult
static class
ModularXmppClientToServerConnection.Stats
-
Nested classes/interfaces inherited from class org.jivesoftware.smack.AbstractXMPPConnection
AbstractXMPPConnection.InterceptorWrapper, AbstractXMPPConnection.ListenerWrapper, AbstractXMPPConnection.SyncPointState
-
Nested classes/interfaces inherited from interface org.jivesoftware.smack.XMPPConnection
XMPPConnection.FromMode
-
-
Field Summary
-
Fields inherited from class org.jivesoftware.smack.AbstractXMPPConnection
ASYNC_BUT_ORDERED, authenticated, authenticatedConnectionInitiallyEstablishedTimestamp, closingStreamReceived, compressionHandler, config, connected, connectionCounterValue, connectionListeners, connectionLock, currentSmackException, currentXmppException, debugger, host, lastFeaturesReceived, outgoingStreamXmlEnvironment, port, reader, saslFeatureReceived, SMACK_REACTOR, streamFeatures, streamId, tlsHandled, user, wasAuthenticated, writer
-
-
Constructor Summary
Constructors Constructor Description ModularXmppClientToServerConnection(ModularXmppClientToServerConnectionConfiguration configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConnectionStateMachineListener(ConnectionStateMachineListener connectionStateMachineListener)
protected void
afterFeaturesReceived()
protected void
connectInternal()
Abstract method that concrete subclasses of XMPPConnection need to implement to perform their way of XMPP connection establishment.ModularXmppClientToServerConnectionConfiguration
getConfiguration()
Get the connection configuration used by this connection.<CM extends ModularXmppClientToServerConnectionModule<? extends ModularXmppClientToServerConnectionModuleDescriptor>>
CMgetConnectionModuleFor(Class<? extends ModularXmppClientToServerConnectionModuleDescriptor> descriptorClass)
InetAddress
getLocalAddress()
Returns the local address currently in use for this connection, ornull
if this is invalid for the type of underlying connection.ModularXmppClientToServerConnection.Stats
getStats()
protected AbstractStreamOpen
getStreamOpen(DomainBareJid to, CharSequence from, String id, String lang)
void
instantShutdown()
Performs an unclean disconnect and shutdown of the connection.boolean
isSecureConnection()
Returns true if the connection to the server has successfully negotiated encryption.boolean
isUsingCompression()
Returns true if network traffic is being compressed.protected void
loginInternal(String username, String password, Resourcepart resource)
boolean
removeConnectionStateMachineListener(ConnectionStateMachineListener connectionStateMachineListener)
protected void
sendInternal(TopLevelStreamElement element)
protected void
sendNonBlockingInternal(TopLevelStreamElement element)
protected void
shutdown()
Shuts the current connection down.-
Methods inherited from class org.jivesoftware.smack.AbstractXMPPConnection
addAsyncStanzaListener, addConnectionListener, addMessageInterceptor, addOneTimeSyncCallback, addPresenceInterceptor, addStanzaInterceptor, addStanzaListener, addStanzaSendingListener, addStreamFeature, addSyncStanzaListener, afterSaslAuthenticationSuccess, afterSuccessfulLogin, asyncGo, asyncGoLimited, authenticate, bindResourceAndEstablishSession, buildNonzaCallback, callConnectionAuthenticatedListener, callConnectionConnectedListener, callConnectionConnectingListener, connect, createStanzaCollector, createStanzaCollector, createStanzaCollectorAndSend, createStanzaCollectorAndSend, disconnect, disconnect, firePacketSendingListeners, getAuthenticatedConnectionInitiallyEstablishedTimestamp, getConnectionCounter, getConnectionLock, getFeature, getFromMode, getHost, getLastStanzaReceived, getParsingExceptionCallback, getPort, getReactor, getReplyTimeout, getSmackTlsContext, getStanzaFactory, getStreamId, getUsedSaslMechansism, getUser, getXMPPServiceDomain, hasCurrentConnectionException, hasFeature, initDebugger, initState, invokeStanzaCollectorsAndNotifyRecvListeners, isAnonymous, isAuthenticated, isConnected, isSaslAuthenticated, login, login, login, notifyConnectionError, notifyWaitingThreads, onStreamOpen, parseAndProcessNonza, parseAndProcessStanza, parseFeatures, parseFeaturesAndNotify, processStanza, registerIQRequestHandler, removeAsyncStanzaListener, removeConnectionListener, removeMessageInterceptor, removePresenceInterceptor, removeStanzaCollector, removeStanzaInterceptor, removeStanzaListener, removeStanzaSendingListener, removeSyncStanzaListener, schedule, sendAndWaitForResponse, sendAsync, sendAsync, sendIqRequestAndWaitForResponse, sendIqRequestAsync, sendIqRequestAsync, sendNonza, sendNonzaNonBlocking, sendStanza, sendStanzaNonBlocking, sendStreamOpen, setCurrentConnectionExceptionAndNotify, setFromMode, setMaxAsyncOperations, setParsingExceptionCallback, setReplyTimeout, setUnknownIqRequestReplyMode, setWasAuthenticated, throwAlreadyConnectedExceptionIfAppropriate, throwAlreadyLoggedInExceptionIfAppropriate, throwCurrentConnectionException, throwNotConnectedExceptionIfAppropriate, throwNotConnectedExceptionIfAppropriate, toString, trySendStanza, trySendStanza, unregisterIQRequestHandler, unregisterIQRequestHandler, updateOutgoingStreamXmlEnvironmentOnStreamOpen, waitFor, waitForClosingStreamTagFromServer, waitForConditionOrThrowConnectionException
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.XMPPConnection
getFeature, getFeature, hasFeature
-
-
-
-
Constructor Detail
-
ModularXmppClientToServerConnection
public ModularXmppClientToServerConnection(ModularXmppClientToServerConnectionConfiguration configuration)
-
-
Method Detail
-
getConnectionModuleFor
public <CM extends ModularXmppClientToServerConnectionModule<? extends ModularXmppClientToServerConnectionModuleDescriptor>> CM getConnectionModuleFor(Class<? extends ModularXmppClientToServerConnectionModuleDescriptor> descriptorClass)
-
loginInternal
protected void loginInternal(String username, String password, Resourcepart resource) throws XMPPException, SmackException, IOException, InterruptedException
- Specified by:
loginInternal
in classAbstractXMPPConnection
- Throws:
XMPPException
SmackException
IOException
InterruptedException
-
sendInternal
protected void sendInternal(TopLevelStreamElement element) throws SmackException.NotConnectedException, InterruptedException
- Specified by:
sendInternal
in classAbstractXMPPConnection
- Throws:
SmackException.NotConnectedException
InterruptedException
-
sendNonBlockingInternal
protected void sendNonBlockingInternal(TopLevelStreamElement element) throws SmackException.NotConnectedException, SmackException.OutgoingQueueFullException
- Specified by:
sendNonBlockingInternal
in classAbstractXMPPConnection
- Throws:
SmackException.NotConnectedException
SmackException.OutgoingQueueFullException
-
shutdown
protected void shutdown()
Description copied from class:AbstractXMPPConnection
Shuts the current connection down.- Specified by:
shutdown
in classAbstractXMPPConnection
-
instantShutdown
public void instantShutdown()
Description copied from class:AbstractXMPPConnection
Performs an unclean disconnect and shutdown of the connection. Does not send a closing stream stanza.- Specified by:
instantShutdown
in classAbstractXMPPConnection
-
getConfiguration
public ModularXmppClientToServerConnectionConfiguration getConfiguration()
Description copied from class:AbstractXMPPConnection
Get the connection configuration used by this connection.- Overrides:
getConfiguration
in classAbstractXMPPConnection
- Returns:
- the connection configuration.
-
afterFeaturesReceived
protected void afterFeaturesReceived()
- Overrides:
afterFeaturesReceived
in classAbstractXMPPConnection
-
getStreamOpen
protected AbstractStreamOpen getStreamOpen(DomainBareJid to, CharSequence from, String id, String lang)
- Overrides:
getStreamOpen
in classAbstractXMPPConnection
-
isUsingCompression
public boolean isUsingCompression()
Description copied from interface:XMPPConnection
Returns true if network traffic is being compressed. When using stream compression network traffic can be reduced up to 90%. Therefore, stream compression is ideal when using a slow speed network connection. However, the server will need to use more CPU time in order to un/compress network data so under high load the server performance might be affected.- Specified by:
isUsingCompression
in interfaceXMPPConnection
- Specified by:
isUsingCompression
in classAbstractXMPPConnection
- Returns:
- true if network traffic is being compressed.
-
addConnectionStateMachineListener
public void addConnectionStateMachineListener(ConnectionStateMachineListener connectionStateMachineListener)
-
removeConnectionStateMachineListener
public boolean removeConnectionStateMachineListener(ConnectionStateMachineListener connectionStateMachineListener)
-
isSecureConnection
public boolean isSecureConnection()
Description copied from interface:XMPPConnection
Returns true if the connection to the server has successfully negotiated encryption.- Specified by:
isSecureConnection
in interfaceXMPPConnection
- Specified by:
isSecureConnection
in classAbstractXMPPConnection
- Returns:
- true if a secure connection to the server.
-
connectInternal
protected void connectInternal() throws SmackException, IOException, XMPPException, InterruptedException
Description copied from class:AbstractXMPPConnection
Abstract method that concrete subclasses of XMPPConnection need to implement to perform their way of XMPP connection establishment. Implementations are required to perform an automatic login if the previous connection state was logged (authenticated).- Specified by:
connectInternal
in classAbstractXMPPConnection
- Throws:
SmackException
- if Smack detected an exceptional situation.IOException
- if an I/O error occurred.XMPPException
- if an XMPP protocol error was received.InterruptedException
- if the calling thread was interrupted.
-
getLocalAddress
public InetAddress getLocalAddress()
Description copied from interface:XMPPConnection
Returns the local address currently in use for this connection, ornull
if this is invalid for the type of underlying connection.- Returns:
- the local address currently in use for this connection
-
getStats
public ModularXmppClientToServerConnection.Stats getStats()
-
-