Class XMPPTCPConnection
- All Implemented Interfaces:
XMPPConnection
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected classNested classes/interfaces inherited from class org.jivesoftware.smack.AbstractXMPPConnection
AbstractXMPPConnection.InterceptorWrapper, AbstractXMPPConnection.ListenerWrapper, AbstractXMPPConnection.SyncPointStateNested classes/interfaces inherited from interface org.jivesoftware.smack.XMPPConnection
XMPPConnection.FromMode -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final XMPPTCPConnection.PacketReaderProtected access level because of unit test purposesprotected final XMPPTCPConnection.PacketWriterProtected access level because of unit test purposesFields inherited from class org.jivesoftware.smack.AbstractXMPPConnection
ASYNC_BUT_ORDERED, authenticated, authenticatedConnectionInitiallyEstablishedTimestamp, closingStreamReceived, compressionHandler, connected, connectionCounterValue, connectionListeners, connectionLock, debugger, host, lastFeaturesReceived, outgoingStreamXmlEnvironment, port, reader, saslFeatureReceived, SMACK_REACTOR, streamFeatures, streamId, tlsHandled, user, wasAuthenticated, writer -
Constructor Summary
ConstructorsConstructorDescriptionXMPPTCPConnection(CharSequence jid, String password) Creates a new XMPP connection over TCP.XMPPTCPConnection(CharSequence username, String password, String serviceName) Creates a new XMPP connection over TCP.Creates a new XMPP connection over TCP (optionally using proxies). -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddRequestAckPredicate(StanzaFilter predicate) Add a predicate for Stream Management acknowledgment requests.voidaddStanzaAcknowledgedListener(StanzaListener listener) Add a Stanza acknowledged listener.voidaddStanzaDroppedListener(StanzaListener listener) Add a Stanza dropped listener.addStanzaIdAcknowledgedListener(String id, StanzaListener listener) Add a new Stanza ID acknowledged listener for the given ID.protected voidprotected voidafterSuccessfulLogin(boolean resumed) protected voidEstablishes a connection to the XMPP server.Returns the local address currently in use for this connection.intGet the maximum resumption time in seconds after which a managed stream can be resumed.voidPerforms an unclean disconnect and shutdown of the connection.booleanReturns true if the connection is disconnected by a Stream resumption via Stream Management is possible.booleanReturns true if the connection to the server has successfully negotiated encryption.booleanReturns true if Stream Management is supported by the server.booleanReturns true if Stream Management was successfully negotiated with the server.booleanReturns true if the stream is resumable.booleanReturns true if network traffic is being compressed.protected voidloginInternal(String username, String password, Resourcepart resource) voidRemove all predicates for Stream Management acknowledgment requests.voidRemove all stanza acknowledged listeners.voidRemoves all Stanza ID acknowledged listeners.booleanremoveRequestAckPredicate(StanzaFilter predicate) Remove the given predicate for Stream Management acknowledgment request.booleanRemove the given Stanza acknowledged listener.booleanremoveStanzaDroppedListener(StanzaListener listener) Remove the given Stanza dropped listener.Remove the Stanza ID acknowledged listener for the given ID.voidSend an unconditional Stream Management acknowledgement request to the server.protected voidsendInternal(TopLevelStreamElement element) protected voidvoidSend a unconditional Stream Management acknowledgment to the server.voidsetBundleandDeferCallback(BundleAndDeferCallback bundleAndDeferCallback) Set the bundle and defer callback used for this connection.static voidsetDefaultBundleAndDeferCallback(BundleAndDeferCallback defaultBundleAndDeferCallback) Set the default bundle and defer callback used for new connections.voidsetPreferredResumptionTime(int resumptionTime) Set the preferred resumption time in seconds.voidsetUseStreamManagement(boolean useSm) Set if Stream Management should be used if supported by the server.static voidsetUseStreamManagementDefault(boolean useSmDefault) Set if Stream Management should be used by default for new connections.static voidsetUseStreamManagementResumptiodDefault(boolean useSmResumptionDefault) Deprecated.voidsetUseStreamManagementResumption(boolean useSmResumption) Set if Stream Management resumption should be used if supported by the server.static voidsetUseStreamManagementResumptionDefault(boolean useSmResumptionDefault) Set if Stream Management resumption should be used by default for new connections.protected voidFor unit testing purposesprotected voidshutdown()Shuts the current connection down.booleanReturns true if the stream was successfully resumed with help of Stream Management.protected voidprotected voidprotected voidMethods inherited from class org.jivesoftware.smack.AbstractXMPPConnection
addAsyncStanzaListener, addConnectionListener, addMessageInterceptor, addOneTimeSyncCallback, addPresenceInterceptor, addStanzaListener, addStanzaSendingListener, addStreamFeature, addSyncStanzaListener, afterSaslAuthenticationSuccess, asyncGo, asyncGoLimited, authenticate, bindResourceAndEstablishSession, buildNonzaCallback, callConnectionAuthenticatedListener, callConnectionConnectedListener, callConnectionConnectingListener, connect, createStanzaCollector, createStanzaCollector, createStanzaCollectorAndSend, createStanzaCollectorAndSend, disconnect, disconnect, firePacketSendingListeners, getAuthenticatedConnectionInitiallyEstablishedTimestamp, getConfiguration, getConnectionCounter, getConnectionLock, getFeature, getFromMode, getHost, getLastStanzaReceived, getParsingExceptionCallback, getPort, getReactor, getReplyTimeout, getSmackTlsContext, getStanzaFactory, getStreamId, getStreamOpen, 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, removeStanzaListener, removeStanzaSendingListener, removeSyncStanzaListener, schedule, sendAndWaitForResponse, sendAsync, sendAsync, sendIqRequestAndWaitForResponse, sendIqRequestAsync, sendIqRequestAsync, sendNonza, sendNonzaNonBlocking, sendStanza, sendStanzaNonBlocking, sendStreamOpen, setCurrentConnectionExceptionAndNotify, setFromMode, setMaxAsyncOperations, setParsingExceptionCallback, setReplyTimeout, setUnknownIqRequestReplyMode, setWasAuthenticated, throwNotConnectedExceptionIfAppropriate, toString, trySendStanza, trySendStanza, unregisterIQRequestHandler, unregisterIQRequestHandler, updateOutgoingStreamXmlEnvironmentOnStreamOpen, waitFor, waitForClosingStreamTagFromServer, waitForConditionOrThrowConnectionExceptionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jivesoftware.smack.XMPPConnection
getFeature, hasFeature
-
Field Details
-
packetWriter
Protected access level because of unit test purposes -
packetReader
Protected access level because of unit test purposes
-
-
Constructor Details
-
XMPPTCPConnection
Creates a new XMPP connection over TCP (optionally using proxies).Note that XMPPTCPConnection constructors do not establish a connection to the server and you must call
AbstractXMPPConnection.connect().- Parameters:
config- the connection configuration.
-
XMPPTCPConnection
Creates a new XMPP connection over TCP.Note that
jidmust be the bare JID, e.g. "user@example.org". More fine-grained control over the connection settings is available using theXMPPTCPConnection(XMPPTCPConnectionConfiguration)constructor.- Parameters:
jid- the bare JID used by the client.password- the password or authentication token.- Throws:
XmppStringprepException- if the provided string is invalid.
-
XMPPTCPConnection
public XMPPTCPConnection(CharSequence username, String password, String serviceName) throws XmppStringprepException Creates a new XMPP connection over TCP.This is the simplest constructor for connecting to an XMPP server. Alternatively, you can get fine-grained control over connection settings using the
XMPPTCPConnection(XMPPTCPConnectionConfiguration)constructor.- Parameters:
username- TODO javadoc me pleasepassword- TODO javadoc me pleaseserviceName- TODO javadoc me please- Throws:
XmppStringprepException- if the provided string is invalid.
-
-
Method Details
-
throwNotConnectedExceptionIfAppropriate
protected void throwNotConnectedExceptionIfAppropriate() throws SmackException.NotConnectedException- Overrides:
throwNotConnectedExceptionIfAppropriatein classAbstractXMPPConnection- Throws:
SmackException.NotConnectedException
-
throwAlreadyConnectedExceptionIfAppropriate
protected void throwAlreadyConnectedExceptionIfAppropriate() throws SmackException.AlreadyConnectedException- Overrides:
throwAlreadyConnectedExceptionIfAppropriatein classAbstractXMPPConnection- Throws:
SmackException.AlreadyConnectedException
-
throwAlreadyLoggedInExceptionIfAppropriate
protected void throwAlreadyLoggedInExceptionIfAppropriate() throws SmackException.AlreadyLoggedInException- Overrides:
throwAlreadyLoggedInExceptionIfAppropriatein classAbstractXMPPConnection- Throws:
SmackException.AlreadyLoggedInException
-
afterSuccessfulLogin
protected void afterSuccessfulLogin(boolean resumed) throws SmackException.NotConnectedException, InterruptedException - Overrides:
afterSuccessfulLoginin classAbstractXMPPConnection- Throws:
SmackException.NotConnectedExceptionInterruptedException
-
loginInternal
protected void loginInternal(String username, String password, Resourcepart resource) throws XMPPException, SmackException, IOException, InterruptedException - Specified by:
loginInternalin classAbstractXMPPConnection- Throws:
XMPPExceptionSmackExceptionIOExceptionInterruptedException
-
isSecureConnection
Description copied from interface:XMPPConnectionReturns true if the connection to the server has successfully negotiated encryption.- Specified by:
isSecureConnectionin interfaceXMPPConnection- Specified by:
isSecureConnectionin classAbstractXMPPConnection- Returns:
- true if a secure connection to the server.
-
shutdown
Shuts the current connection down. After this method returns, the connection must be ready for re-use by connect.- Specified by:
shutdownin classAbstractXMPPConnection
-
instantShutdown
Description copied from class:AbstractXMPPConnectionPerforms an unclean disconnect and shutdown of the connection. Does not send a closing stream stanza.- Specified by:
instantShutdownin classAbstractXMPPConnection
-
sendInternal
protected void sendInternal(TopLevelStreamElement element) throws SmackException.NotConnectedException, InterruptedException - Specified by:
sendInternalin classAbstractXMPPConnection- Throws:
SmackException.NotConnectedExceptionInterruptedException
-
sendNonBlockingInternal
protected void sendNonBlockingInternal(TopLevelStreamElement element) throws SmackException.NotConnectedException, SmackException.OutgoingQueueFullException - Specified by:
sendNonBlockingInternalin classAbstractXMPPConnection- Throws:
SmackException.NotConnectedExceptionSmackException.OutgoingQueueFullException
-
isUsingCompression
Description copied from interface:XMPPConnectionReturns 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:
isUsingCompressionin interfaceXMPPConnection- Specified by:
isUsingCompressionin classAbstractXMPPConnection- Returns:
- true if network traffic is being compressed.
-
connectInternal
protected void connectInternal() throws SmackException, IOException, XMPPException, InterruptedExceptionEstablishes a connection to the XMPP server. It basically creates and maintains a socket connection to the server.Listeners will be preserved from a previous connection if the reconnection occurs after an abrupt termination.
- Specified by:
connectInternalin classAbstractXMPPConnection- Throws:
XMPPException- if an error occurs while trying to establish the connection.SmackException- if Smack detected an exceptional situation.IOException- if an I/O error occurred.InterruptedException- if the calling thread was interrupted.
-
setWriter
For unit testing purposes- Parameters:
writer- TODO javadoc me please
-
afterFeaturesReceived
-
setUseStreamManagementDefault
Set if Stream Management should be used by default for new connections.- Parameters:
useSmDefault- true to use Stream Management for new connections.
-
setUseStreamManagementResumptiodDefault
@Deprecated public static void setUseStreamManagementResumptiodDefault(boolean useSmResumptionDefault) Deprecated.usesetUseStreamManagementResumptionDefault(boolean)instead.Set if Stream Management resumption should be used by default for new connections.- Parameters:
useSmResumptionDefault- true to use Stream Management resumption for new connections.
-
setUseStreamManagementResumptionDefault
Set if Stream Management resumption should be used by default for new connections.- Parameters:
useSmResumptionDefault- true to use Stream Management resumption for new connections.
-
setUseStreamManagement
Set if Stream Management should be used if supported by the server.- Parameters:
useSm- true to use Stream Management.
-
setUseStreamManagementResumption
Set if Stream Management resumption should be used if supported by the server.- Parameters:
useSmResumption- true to use Stream Management resumption.
-
setPreferredResumptionTime
Set the preferred resumption time in seconds.- Parameters:
resumptionTime- the preferred resumption time in seconds
-
addRequestAckPredicate
Add a predicate for Stream Management acknowledgment requests.Those predicates are used to determine when a Stream Management acknowledgement request is send to the server. Some pre-defined predicates are found in the
org.jivesoftware.smack.sm.predicatespackage.If not predicate is configured, the
Predicate.forMessagesOrAfter5Stanzas()will be used.- Parameters:
predicate- the predicate to add.- Returns:
- if the predicate was not already active.
-
removeRequestAckPredicate
Remove the given predicate for Stream Management acknowledgment request.- Parameters:
predicate- the predicate to remove.- Returns:
- true if the predicate was removed.
-
removeAllRequestAckPredicates
Remove all predicates for Stream Management acknowledgment requests. -
requestSmAcknowledgement
public void requestSmAcknowledgement() throws StreamManagementException.StreamManagementNotEnabledException, SmackException.NotConnectedException, InterruptedExceptionSend an unconditional Stream Management acknowledgement request to the server.- Throws:
StreamManagementException.StreamManagementNotEnabledException- if Stream Management is not enabled.SmackException.NotConnectedException- if the connection is not connected.InterruptedException- if the calling thread was interrupted.
-
sendSmAcknowledgement
public void sendSmAcknowledgement() throws StreamManagementException.StreamManagementNotEnabledException, SmackException.NotConnectedException, InterruptedExceptionSend a unconditional Stream Management acknowledgment to the server.See XEP-198: Stream Management ยง 4. Acks: "Either party MAY send an <a/> element at any time (e.g., after it has received a certain number of stanzas, or after a certain period of time), even if it has not received an <r/> element from the other party."
- Throws:
StreamManagementException.StreamManagementNotEnabledException- if Stream Management is not enabled.SmackException.NotConnectedException- if the connection is not connected.InterruptedException- if the calling thread was interrupted.
-
addStanzaAcknowledgedListener
Add a Stanza acknowledged listener.Those listeners will be invoked every time a Stanza has been acknowledged by the server. The will not get automatically removed. Consider using
addStanzaIdAcknowledgedListener(String, StanzaListener)when possible.- Parameters:
listener- the listener to add.
-
removeStanzaAcknowledgedListener
Remove the given Stanza acknowledged listener.- Parameters:
listener- the listener.- Returns:
- true if the listener was removed.
-
removeAllStanzaAcknowledgedListeners
Remove all stanza acknowledged listeners. -
addStanzaDroppedListener
Add a Stanza dropped listener.Those listeners will be invoked every time a Stanza has been dropped due to a failed SM resume. They will not get automatically removed. If at least one StanzaDroppedListener is configured, no attempt will be made to retransmit the Stanzas.
- Parameters:
listener- the listener to add.- Since:
- 4.3.3
-
removeStanzaDroppedListener
Remove the given Stanza dropped listener.- Parameters:
listener- the listener.- Returns:
- true if the listener was removed.
- Since:
- 4.3.3
-
addStanzaIdAcknowledgedListener
public StanzaListener addStanzaIdAcknowledgedListener(String id, StanzaListener listener) throws StreamManagementException.StreamManagementNotEnabledException Add a new Stanza ID acknowledged listener for the given ID.The listener will be invoked if the stanza with the given ID was acknowledged by the server. It will automatically be removed after the listener was run.
- Parameters:
id- the stanza ID.listener- the listener to invoke.- Returns:
- the previous listener for this stanza ID or null.
- Throws:
StreamManagementException.StreamManagementNotEnabledException- if Stream Management is not enabled.
-
removeStanzaIdAcknowledgedListener
Remove the Stanza ID acknowledged listener for the given ID.- Parameters:
id- the stanza ID.- Returns:
- true if the listener was found and removed, false otherwise.
-
removeAllStanzaIdAcknowledgedListeners
Removes all Stanza ID acknowledged listeners. -
isSmAvailable
Returns true if Stream Management is supported by the server.- Returns:
- true if Stream Management is supported by the server.
-
isSmEnabled
Returns true if Stream Management was successfully negotiated with the server.- Returns:
- true if Stream Management was negotiated.
-
streamWasResumed
Returns true if the stream was successfully resumed with help of Stream Management.- Returns:
- true if the stream was resumed.
-
isDisconnectedButSmResumptionPossible
Returns true if the connection is disconnected by a Stream resumption via Stream Management is possible.- Returns:
- true if disconnected but resumption possible.
-
isSmResumptionPossible
Returns true if the stream is resumable.- Returns:
- true if the stream is resumable.
-
getMaxSmResumptionTime
Get the maximum resumption time in seconds after which a managed stream can be resumed.This method will return
Integer.MAX_VALUEif neither the client nor the server specify a maximum resumption time. Be aware of integer overflows when using this value, e.g. do not add arbitrary values to it without checking for overflows before.- Returns:
- the maximum resumption time in seconds or
Integer.MAX_VALUEif none set.
-
setDefaultBundleAndDeferCallback
public static void setDefaultBundleAndDeferCallback(BundleAndDeferCallback defaultBundleAndDeferCallback) Set the default bundle and defer callback used for new connections.- Parameters:
defaultBundleAndDeferCallback- TODO javadoc me please- Since:
- 4.1
- See Also:
-
setBundleandDeferCallback
Set the bundle and defer callback used for this connection.You can use
nullas argument to reset the callback. Outgoing stanzas will then no longer get deferred.- Parameters:
bundleAndDeferCallback- the callback ornull.- Since:
- 4.1
- See Also:
-
getLocalAddress
Returns the local address currently in use for this connection.- Returns:
- the local address
-
setUseStreamManagementResumptionDefault(boolean)instead.