public class XMPPTCPConnection
extends org.jivesoftware.smack.AbstractXMPPConnection
XMPPConnection| Modifier and Type | Class and Description |
|---|---|
protected class |
XMPPTCPConnection.PacketReader |
protected class |
XMPPTCPConnection.PacketWriter |
| Modifier and Type | Field and Description |
|---|---|
protected XMPPTCPConnection.PacketReader |
packetReader
Protected access level because of unit test purposes
|
protected XMPPTCPConnection.PacketWriter |
packetWriter
Protected access level because of unit test purposes
|
ASYNC_BUT_ORDERED, authenticated, authenticatedConnectionInitiallyEstablishedTimestamp, closingStreamReceived, compressionHandler, connected, connectionCounterValue, connectionListeners, connectionLock, currentSmackException, currentXmppException, debugger, host, lastFeaturesReceived, outgoingStreamXmlEnvironment, port, reader, saslFeatureReceived, SMACK_REACTOR, streamFeatures, streamId, tlsHandled, user, wasAuthenticated, writer| Constructor and Description |
|---|
XMPPTCPConnection(java.lang.CharSequence jid,
java.lang.String password)
Creates a new XMPP connection over TCP.
|
XMPPTCPConnection(java.lang.CharSequence username,
java.lang.String password,
java.lang.String serviceName)
Creates a new XMPP connection over TCP.
|
XMPPTCPConnection(XMPPTCPConnectionConfiguration config)
Creates a new XMPP connection over TCP (optionally using proxies).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addRequestAckPredicate(org.jivesoftware.smack.filter.StanzaFilter predicate)
Add a predicate for Stream Management acknowledgment requests.
|
void |
addStanzaAcknowledgedListener(org.jivesoftware.smack.StanzaListener listener)
Add a Stanza acknowledged listener.
|
void |
addStanzaDroppedListener(org.jivesoftware.smack.StanzaListener listener)
Add a Stanza dropped listener.
|
org.jivesoftware.smack.StanzaListener |
addStanzaIdAcknowledgedListener(java.lang.String id,
org.jivesoftware.smack.StanzaListener listener)
Add a new Stanza ID acknowledged listener for the given ID.
|
protected void |
afterFeaturesReceived() |
protected void |
afterSuccessfulLogin(boolean resumed) |
protected void |
connectInternal()
Establishes a connection to the XMPP server.
|
int |
getMaxSmResumptionTime()
Get the maximum resumption time in seconds after which a managed stream can be resumed.
|
void |
instantShutdown() |
boolean |
isDisconnectedButSmResumptionPossible()
Returns true if the connection is disconnected by a Stream resumption via Stream Management is possible.
|
boolean |
isSecureConnection() |
boolean |
isSmAvailable()
Returns true if Stream Management is supported by the server.
|
boolean |
isSmEnabled()
Returns true if Stream Management was successfully negotiated with the server.
|
boolean |
isSmResumptionPossible()
Returns true if the stream is resumable.
|
boolean |
isUsingCompression() |
protected void |
loginInternal(java.lang.String username,
java.lang.String password,
org.jxmpp.jid.parts.Resourcepart resource) |
void |
removeAllRequestAckPredicates()
Remove all predicates for Stream Management acknowledgment requests.
|
void |
removeAllStanzaAcknowledgedListeners()
Remove all stanza acknowledged listeners.
|
void |
removeAllStanzaIdAcknowledgedListeners()
Removes all Stanza ID acknowledged listeners.
|
boolean |
removeRequestAckPredicate(org.jivesoftware.smack.filter.StanzaFilter predicate)
Remove the given predicate for Stream Management acknowledgment request.
|
boolean |
removeStanzaAcknowledgedListener(org.jivesoftware.smack.StanzaListener listener)
Remove the given Stanza acknowledged listener.
|
boolean |
removeStanzaDroppedListener(org.jivesoftware.smack.StanzaListener listener)
Remove the given Stanza dropped listener.
|
org.jivesoftware.smack.StanzaListener |
removeStanzaIdAcknowledgedListener(java.lang.String id)
Remove the Stanza ID acknowledged listener for the given ID.
|
void |
requestSmAcknowledgement()
Send an unconditional Stream Management acknowledgement request to the server.
|
void |
sendNonza(org.jivesoftware.smack.packet.Nonza element) |
void |
sendSmAcknowledgement()
Send a unconditional Stream Management acknowledgment to the server.
|
protected void |
sendStanzaInternal(org.jivesoftware.smack.packet.Stanza packet) |
void |
setBundleandDeferCallback(BundleAndDeferCallback bundleAndDeferCallback)
Set the bundle and defer callback used for this connection.
|
static void |
setDefaultBundleAndDeferCallback(BundleAndDeferCallback defaultBundleAndDeferCallback)
Set the default bundle and defer callback used for new connections.
|
void |
setPreferredResumptionTime(int resumptionTime)
Set the preferred resumption time in seconds.
|
void |
setUseStreamManagement(boolean useSm)
Set if Stream Management should be used if supported by the server.
|
static void |
setUseStreamManagementDefault(boolean useSmDefault)
Set if Stream Management should be used by default for new connections.
|
static void |
setUseStreamManagementResumptiodDefault(boolean useSmResumptionDefault)
Deprecated.
use
setUseStreamManagementResumptionDefault(boolean) instead. |
void |
setUseStreamManagementResumption(boolean useSmResumption)
Set if Stream Management resumption should be used if supported by the server.
|
static void |
setUseStreamManagementResumptionDefault(boolean useSmResumptionDefault)
Set if Stream Management resumption should be used by default for new connections.
|
protected void |
setWriter(java.io.Writer writer)
For unit testing purposes
|
protected void |
shutdown()
Shuts the current connection down.
|
boolean |
streamWasResumed()
Returns true if the stream was successfully resumed with help of Stream Management.
|
protected void |
throwAlreadyConnectedExceptionIfAppropriate() |
protected void |
throwAlreadyLoggedInExceptionIfAppropriate() |
protected void |
throwNotConnectedExceptionIfAppropriate() |
addAsyncStanzaListener, addConnectionListener, addMessageInterceptor, addOneTimeSyncCallback, addPresenceInterceptor, addStanzaInterceptor, 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, 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, sendStanza, sendStreamOpen, setCurrentConnectionExceptionAndNotify, setFromMode, setMaxAsyncOperations, setParsingExceptionCallback, setReplyTimeout, setUnknownIqRequestReplyMode, setWasAuthenticated, throwCurrentConnectionException, throwNotConnectedExceptionIfAppropriate, toString, trySendStanza, trySendStanza, unregisterIQRequestHandler, unregisterIQRequestHandler, waitFor, waitForClosingStreamTagFromServer, waitForConditionOrThrowConnectionExceptionprotected final XMPPTCPConnection.PacketWriter packetWriter
protected final XMPPTCPConnection.PacketReader packetReader
public XMPPTCPConnection(XMPPTCPConnectionConfiguration config)
Note that XMPPTCPConnection constructors do not establish a connection to the server
and you must call AbstractXMPPConnection.connect().
config - the connection configuration.public XMPPTCPConnection(java.lang.CharSequence jid,
java.lang.String password)
throws org.jxmpp.stringprep.XmppStringprepException
Note that jid must be the bare JID, e.g. "user@example.org". More fine-grained control over the
connection settings is available using the XMPPTCPConnection(XMPPTCPConnectionConfiguration)
constructor.
jid - the bare JID used by the client.password - the password or authentication token.org.jxmpp.stringprep.XmppStringprepException - if the provided string is invalid.public XMPPTCPConnection(java.lang.CharSequence username,
java.lang.String password,
java.lang.String serviceName)
throws org.jxmpp.stringprep.XmppStringprepException
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.
username - TODO javadoc me pleasepassword - TODO javadoc me pleaseserviceName - TODO javadoc me pleaseorg.jxmpp.stringprep.XmppStringprepException - if the provided string is invalid.protected void throwNotConnectedExceptionIfAppropriate()
throws org.jivesoftware.smack.SmackException.NotConnectedException
throwNotConnectedExceptionIfAppropriate in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionprotected void throwAlreadyConnectedExceptionIfAppropriate()
throws org.jivesoftware.smack.SmackException.AlreadyConnectedException
throwAlreadyConnectedExceptionIfAppropriate in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.AlreadyConnectedExceptionprotected void throwAlreadyLoggedInExceptionIfAppropriate()
throws org.jivesoftware.smack.SmackException.AlreadyLoggedInException
throwAlreadyLoggedInExceptionIfAppropriate in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.AlreadyLoggedInExceptionprotected void afterSuccessfulLogin(boolean resumed)
throws org.jivesoftware.smack.SmackException.NotConnectedException,
java.lang.InterruptedException
afterSuccessfulLogin in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionprotected void loginInternal(java.lang.String username,
java.lang.String password,
org.jxmpp.jid.parts.Resourcepart resource)
throws org.jivesoftware.smack.XMPPException,
org.jivesoftware.smack.SmackException,
java.io.IOException,
java.lang.InterruptedException
loginInternal in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.XMPPExceptionorg.jivesoftware.smack.SmackExceptionjava.io.IOExceptionjava.lang.InterruptedExceptionpublic boolean isSecureConnection()
isSecureConnection in interface org.jivesoftware.smack.XMPPConnectionisSecureConnection in class org.jivesoftware.smack.AbstractXMPPConnectionprotected void shutdown()
shutdown in class org.jivesoftware.smack.AbstractXMPPConnectionpublic void instantShutdown()
instantShutdown in class org.jivesoftware.smack.AbstractXMPPConnectionpublic void sendNonza(org.jivesoftware.smack.packet.Nonza element)
throws org.jivesoftware.smack.SmackException.NotConnectedException,
java.lang.InterruptedException
sendNonza in interface org.jivesoftware.smack.XMPPConnectionsendNonza in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionprotected void sendStanzaInternal(org.jivesoftware.smack.packet.Stanza packet)
throws org.jivesoftware.smack.SmackException.NotConnectedException,
java.lang.InterruptedException
sendStanzaInternal in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic boolean isUsingCompression()
isUsingCompression in interface org.jivesoftware.smack.XMPPConnectionisUsingCompression in class org.jivesoftware.smack.AbstractXMPPConnectionprotected void connectInternal()
throws org.jivesoftware.smack.SmackException,
java.io.IOException,
org.jivesoftware.smack.XMPPException,
java.lang.InterruptedException
Listeners will be preserved from a previous connection if the reconnection occurs after an abrupt termination.
connectInternal in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.XMPPException - if an error occurs while trying to establish the connection.org.jivesoftware.smack.SmackException - if Smack detected an exceptional situation.java.io.IOException - if an I/O error occurred.java.lang.InterruptedException - if the calling thread was interrupted.protected void setWriter(java.io.Writer writer)
writer - TODO javadoc me pleaseprotected void afterFeaturesReceived()
throws org.jivesoftware.smack.SmackException.NotConnectedException,
java.lang.InterruptedException,
org.jivesoftware.smack.SmackException.SecurityRequiredByServerException
afterFeaturesReceived in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionorg.jivesoftware.smack.SmackException.SecurityRequiredByServerExceptionpublic static void setUseStreamManagementDefault(boolean useSmDefault)
useSmDefault - true to use Stream Management for new connections.@Deprecated public static void setUseStreamManagementResumptiodDefault(boolean useSmResumptionDefault)
setUseStreamManagementResumptionDefault(boolean) instead.useSmResumptionDefault - true to use Stream Management resumption for new connections.public static void setUseStreamManagementResumptionDefault(boolean useSmResumptionDefault)
useSmResumptionDefault - true to use Stream Management resumption for new connections.public void setUseStreamManagement(boolean useSm)
useSm - true to use Stream Management.public void setUseStreamManagementResumption(boolean useSmResumption)
useSmResumption - true to use Stream Management resumption.public void setPreferredResumptionTime(int resumptionTime)
resumptionTime - the preferred resumption time in secondspublic boolean addRequestAckPredicate(org.jivesoftware.smack.filter.StanzaFilter predicate)
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.predicates package.
If not predicate is configured, the Predicate.forMessagesOrAfter5Stanzas() will be used.
predicate - the predicate to add.public boolean removeRequestAckPredicate(org.jivesoftware.smack.filter.StanzaFilter predicate)
predicate - the predicate to remove.public void removeAllRequestAckPredicates()
public void requestSmAcknowledgement()
throws org.jivesoftware.smack.sm.StreamManagementException.StreamManagementNotEnabledException,
org.jivesoftware.smack.SmackException.NotConnectedException,
java.lang.InterruptedException
org.jivesoftware.smack.sm.StreamManagementException.StreamManagementNotEnabledException - if Stream Management is not enabled.org.jivesoftware.smack.SmackException.NotConnectedException - if the connection is not connected.java.lang.InterruptedException - if the calling thread was interrupted.public void sendSmAcknowledgement()
throws org.jivesoftware.smack.sm.StreamManagementException.StreamManagementNotEnabledException,
org.jivesoftware.smack.SmackException.NotConnectedException,
java.lang.InterruptedException
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."
org.jivesoftware.smack.sm.StreamManagementException.StreamManagementNotEnabledException - if Stream Management is not enabled.org.jivesoftware.smack.SmackException.NotConnectedException - if the connection is not connected.java.lang.InterruptedException - if the calling thread was interrupted.public void addStanzaAcknowledgedListener(org.jivesoftware.smack.StanzaListener 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.
listener - the listener to add.public boolean removeStanzaAcknowledgedListener(org.jivesoftware.smack.StanzaListener listener)
listener - the listener.public void removeAllStanzaAcknowledgedListeners()
public void addStanzaDroppedListener(org.jivesoftware.smack.StanzaListener 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.
listener - the listener to add.public boolean removeStanzaDroppedListener(org.jivesoftware.smack.StanzaListener listener)
listener - the listener.public org.jivesoftware.smack.StanzaListener addStanzaIdAcknowledgedListener(java.lang.String id,
org.jivesoftware.smack.StanzaListener listener)
throws org.jivesoftware.smack.sm.StreamManagementException.StreamManagementNotEnabledException
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.
id - the stanza ID.listener - the listener to invoke.org.jivesoftware.smack.sm.StreamManagementException.StreamManagementNotEnabledException - if Stream Management is not enabled.public org.jivesoftware.smack.StanzaListener removeStanzaIdAcknowledgedListener(java.lang.String id)
id - the stanza ID.public void removeAllStanzaIdAcknowledgedListeners()
public boolean isSmAvailable()
public boolean isSmEnabled()
public boolean streamWasResumed()
public boolean isDisconnectedButSmResumptionPossible()
public boolean isSmResumptionPossible()
public int getMaxSmResumptionTime()
This method will return Integer.MAX_VALUE if 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.
Integer.MAX_VALUE if none set.public static void setDefaultBundleAndDeferCallback(BundleAndDeferCallback defaultBundleAndDeferCallback)
defaultBundleAndDeferCallback - TODO javadoc me pleaseBundleAndDeferCallbackpublic void setBundleandDeferCallback(BundleAndDeferCallback bundleAndDeferCallback)
You can use null as argument to reset the callback. Outgoing stanzas will then
no longer get deferred.
bundleAndDeferCallback - the callback or null.BundleAndDeferCallback