public class XMPPTCPConnection extends AbstractXMPPConnection
XMPPConnection
Modifier and Type | Class and Description |
---|---|
protected class |
XMPPTCPConnection.PacketReader |
protected class |
XMPPTCPConnection.PacketWriter |
AbstractXMPPConnection.InterceptorWrapper, AbstractXMPPConnection.ListenerWrapper
XMPPConnection.FromMode
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
|
authenticated, compressionHandler, connected, connectionCounterValue, connectionListeners, connectionLock, debugger, host, hostAddresses, lastFeaturesReceived, port, reader, saslAuthentication, saslFeatureReceived, SCHEDULED_EXECUTOR_SERVICE, streamFeatures, streamId, tlsHandled, user, wasAuthenticated, writer
Constructor and Description |
---|
XMPPTCPConnection(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.
|
XMPPTCPConnection(XMPPTCPConnectionConfiguration config)
Creates a new XMPP connection over TCP (optionally using proxies).
|
Modifier and Type | Method and Description |
---|---|
boolean |
addRequestAckPredicate(StanzaFilter predicate)
Add a predicate for Stream Management acknowledgment requests.
|
void |
addStanzaAcknowledgedListener(StanzaListener listener)
Add a Stanza acknowledged listener.
|
StanzaListener |
addStanzaIdAcknowledgedListener(String id,
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()
Performs an unclean disconnect and shutdown of the connection.
|
boolean |
isDisconnectedButSmResumptionPossible()
Returns true if the connection is disconnected by a Stream resumption via Stream Management is possible.
|
boolean |
isSecureConnection()
Returns true if the connection to the server has successfully negotiated encryption.
|
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()
Returns true if network traffic is being compressed.
|
protected void |
loginInternal(String username,
String password,
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(StanzaFilter predicate)
Remove the given predicate for Stream Management acknowledgment request.
|
boolean |
removeStanzaAcknowledgedListener(StanzaListener listener)
Remove the given Stanza acknowledged listener.
|
StanzaListener |
removeStanzaIdAcknowledgedListener(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(Nonza element)
Send a Nonza.
|
void |
sendSmAcknowledgement()
Send a unconditional Stream Management acknowledgment to the server.
|
protected void |
sendStanzaInternal(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(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, addOneTimeSyncCallback, addPacketInterceptor, addPacketSendingListener, addStanzaInterceptor, addStanzaSendingListener, addStreamFeature, addSyncStanzaListener, asyncGo, bindResourceAndEstablishSession, callConnectionAuthenticatedListener, callConnectionClosedOnErrorListener, callConnectionConnectedListener, connect, createStanzaCollector, createStanzaCollector, createStanzaCollectorAndSend, createStanzaCollectorAndSend, disconnect, disconnect, firePacketSendingListeners, getConfiguration, getConnectionCounter, getConnectionLock, getFeature, getFromMode, getHost, getLastStanzaReceived, getParsingExceptionCallback, getPort, getReplyTimeout, getSASLAuthentication, getStreamId, getUsedSaslMechansism, getUser, getXMPPServiceDomain, hasFeature, initDebugger, invokeStanzaCollectorsAndNotifyRecvListeners, isAnonymous, isAuthenticated, isConnected, login, login, login, parseAndProcessStanza, parseFeatures, populateHostAddresses, processStanza, registerIQRequestHandler, removeAsyncStanzaListener, removeConnectionListener, removePacketInterceptor, removePacketSendingListener, removeStanzaCollector, removeStanzaInterceptor, removeStanzaSendingListener, removeSyncStanzaListener, schedule, sendAsync, sendAsync, sendIqRequestAndWaitForResponse, sendIqRequestAsync, sendIqRequestAsync, sendIqWithResponseCallback, sendIqWithResponseCallback, sendIqWithResponseCallback, sendStanza, sendStanzaWithResponseCallback, sendStanzaWithResponseCallback, sendStanzaWithResponseCallback, setFromMode, setParsingExceptionCallback, setReplyTimeout, setUnknownIqRequestReplyMode, setWasAuthenticated, throwNotConnectedExceptionIfAppropriate, toString, unregisterIQRequestHandler, unregisterIQRequestHandler
protected XMPPTCPConnection.PacketWriter packetWriter
protected 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(CharSequence jid, String password) throws 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.XmppStringprepException
public XMPPTCPConnection(CharSequence username, String password, String serviceName) throws 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
- password
- serviceName
- XmppStringprepException
protected void throwNotConnectedExceptionIfAppropriate() throws SmackException.NotConnectedException
throwNotConnectedExceptionIfAppropriate
in class AbstractXMPPConnection
SmackException.NotConnectedException
protected void throwAlreadyConnectedExceptionIfAppropriate() throws SmackException.AlreadyConnectedException
throwAlreadyConnectedExceptionIfAppropriate
in class AbstractXMPPConnection
SmackException.AlreadyConnectedException
protected void throwAlreadyLoggedInExceptionIfAppropriate() throws SmackException.AlreadyLoggedInException
throwAlreadyLoggedInExceptionIfAppropriate
in class AbstractXMPPConnection
SmackException.AlreadyLoggedInException
protected void afterSuccessfulLogin(boolean resumed) throws SmackException.NotConnectedException, InterruptedException
afterSuccessfulLogin
in class AbstractXMPPConnection
SmackException.NotConnectedException
InterruptedException
protected void loginInternal(String username, String password, Resourcepart resource) throws XMPPException, SmackException, IOException, InterruptedException
loginInternal
in class AbstractXMPPConnection
XMPPException
SmackException
IOException
InterruptedException
public boolean isSecureConnection()
XMPPConnection
isSecureConnection
in interface XMPPConnection
isSecureConnection
in class AbstractXMPPConnection
protected void shutdown()
shutdown
in class AbstractXMPPConnection
public void instantShutdown()
public void sendNonza(Nonza element) throws SmackException.NotConnectedException, InterruptedException
XMPPConnection
This method is not meant for end-user usage! It allows sending plain stream elements, which should not be done by a user manually. Doing so may result in a unstable or unusable connection. Certain Smack APIs use this method to send plain stream elements.
sendNonza
in interface XMPPConnection
sendNonza
in class AbstractXMPPConnection
element
- the Nonza to send.SmackException.NotConnectedException
InterruptedException
protected void sendStanzaInternal(Stanza packet) throws SmackException.NotConnectedException, InterruptedException
sendStanzaInternal
in class AbstractXMPPConnection
SmackException.NotConnectedException
InterruptedException
public boolean isUsingCompression()
XMPPConnection
isUsingCompression
in interface XMPPConnection
isUsingCompression
in class AbstractXMPPConnection
protected void connectInternal() throws SmackException, IOException, XMPPException, InterruptedException
Listeners will be preserved from a previous connection if the reconnection occurs after an abrupt termination.
connectInternal
in class AbstractXMPPConnection
XMPPException
- if an error occurs while trying to establish the connection.SmackException
IOException
InterruptedException
protected void afterFeaturesReceived() throws SmackException.NotConnectedException, InterruptedException
afterFeaturesReceived
in class AbstractXMPPConnection
SmackException.NotConnectedException
InterruptedException
public 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(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(StanzaFilter predicate)
predicate
- the predicate to remove.public void removeAllRequestAckPredicates()
public void requestSmAcknowledgement() throws StreamManagementException.StreamManagementNotEnabledException, SmackException.NotConnectedException, InterruptedException
StreamManagementException.StreamManagementNotEnabledException
- if Stream Management is not enabled.SmackException.NotConnectedException
- if the connection is not connected.InterruptedException
public void sendSmAcknowledgement() throws StreamManagementException.StreamManagementNotEnabledException, SmackException.NotConnectedException, 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."
StreamManagementException.StreamManagementNotEnabledException
- if Stream Management is not enabled.SmackException.NotConnectedException
- if the connection is not connected.InterruptedException
public void addStanzaAcknowledgedListener(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(StanzaListener listener)
listener
- the listener.public void removeAllStanzaAcknowledgedListeners()
public StanzaListener addStanzaIdAcknowledgedListener(String id, StanzaListener listener) throws 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.StreamManagementException.StreamManagementNotEnabledException
- if Stream Management is not enabled.public StanzaListener removeStanzaIdAcknowledgedListener(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
- BundleAndDeferCallback
public 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