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
|
authenticated, compressionHandler, connected, connectionCounterValue, connectionListeners, connectionLock, debugger, host, hostAddresses, lastFeaturesReceived, port, reader, saslAuthentication, saslFeatureReceived, streamFeatures, streamId, 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.
|
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 and performs an automatic login
only if the previous connection state was logged (authenticated).
|
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() |
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 |
isSocketClosed() |
boolean |
isUsingCompression() |
void |
loginAnonymously() |
protected void |
loginNonAnonymously(java.lang.String username,
java.lang.String password,
java.lang.String 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.
|
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 |
send(org.jivesoftware.smack.packet.PlainStreamElement 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, addOneTimeSyncCallback, addPacketInterceptor, addPacketListener, addPacketSendingListener, addSyncStanzaListener, asyncGo, bindResourceAndEstablishSession, callConnectionAuthenticatedListener, callConnectionClosedOnErrorListener, callConnectionConnectedListener, connect, createPacketCollector, createPacketCollector, createPacketCollectorAndSend, createPacketCollectorAndSend, disconnect, disconnect, finalize, firePacketSendingListeners, getConfiguration, getConnectionCounter, getConnectionCreationListeners, getConnectionLock, getFeature, getFromMode, getHost, getLastStanzaReceived, getPacketReplyTimeout, getParsingExceptionCallback, getPort, getSASLAuthentication, getServiceName, getStreamId, getUser, hasFeature, initDebugger, invokePacketCollectorsAndNotifyRecvListeners, isAnonymous, isAuthenticated, isConnected, login, login, login, notifyReconnection, parseAndProcessStanza, parseFeatures, populateHostAddresses, processPacket, registerIQRequestHandler, removeAsyncStanzaListener, removeConnectionListener, removePacketCollector, removePacketInterceptor, removePacketListener, removePacketSendingListener, removeSyncStanzaListener, schedule, sendIqWithResponseCallback, sendIqWithResponseCallback, sendIqWithResponseCallback, sendPacket, sendStanza, sendStanzaWithResponseCallback, sendStanzaWithResponseCallback, sendStanzaWithResponseCallback, setFromMode, setPacketReplyTimeout, setParsingExceptionCallback, setReplyToUnknownIq, setReplyToUnknownIqDefault, setWasAuthenticated, throwNotConnectedExceptionIfAppropriate, unregisterIQRequestHandler, unregisterIQRequestHandlerprotected 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(java.lang.CharSequence jid,
java.lang.String password)
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.public XMPPTCPConnection(java.lang.CharSequence username,
java.lang.String password,
java.lang.String serviceName)
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 - 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
afterSuccessfulLogin in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionprotected void loginNonAnonymously(java.lang.String username,
java.lang.String password,
java.lang.String resource)
throws org.jivesoftware.smack.XMPPException,
org.jivesoftware.smack.SmackException,
java.io.IOException
loginNonAnonymously in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.XMPPExceptionorg.jivesoftware.smack.SmackExceptionjava.io.IOExceptionpublic void loginAnonymously()
throws org.jivesoftware.smack.XMPPException,
org.jivesoftware.smack.SmackException,
java.io.IOException
loginAnonymously in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.XMPPExceptionorg.jivesoftware.smack.SmackExceptionjava.io.IOExceptionpublic boolean isSecureConnection()
isSecureConnection in interface org.jivesoftware.smack.XMPPConnectionisSecureConnection in class org.jivesoftware.smack.AbstractXMPPConnectionpublic boolean isSocketClosed()
protected void shutdown()
shutdown in class org.jivesoftware.smack.AbstractXMPPConnectionpublic void instantShutdown()
public void send(org.jivesoftware.smack.packet.PlainStreamElement element)
throws org.jivesoftware.smack.SmackException.NotConnectedException
send in interface org.jivesoftware.smack.XMPPConnectionsend in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionprotected void sendStanzaInternal(org.jivesoftware.smack.packet.Stanza packet)
throws org.jivesoftware.smack.SmackException.NotConnectedException
sendStanzaInternal in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionpublic 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
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.SmackExceptionjava.io.IOExceptionprotected void setWriter(java.io.Writer writer)
writer - protected void afterFeaturesReceived()
throws org.jivesoftware.smack.SmackException.SecurityRequiredException,
org.jivesoftware.smack.SmackException.NotConnectedException
afterFeaturesReceived in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.SecurityRequiredExceptionorg.jivesoftware.smack.SmackException.NotConnectedExceptionpublic 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 StreamManagementException.StreamManagementNotEnabledException,
org.jivesoftware.smack.SmackException.NotConnectedException
StreamManagementException.StreamManagementNotEnabledException - if Stream Mangement is not enabled.org.jivesoftware.smack.SmackException.NotConnectedException - if the connection is not connected.public void sendSmAcknowledgement()
throws StreamManagementException.StreamManagementNotEnabledException,
org.jivesoftware.smack.SmackException.NotConnectedException
See XEP-198: Stream Management ยง 4. Acks:
"Either party MAY send an 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
StreamManagementException.StreamManagementNotEnabledException - if Stream Management is not enabled.org.jivesoftware.smack.SmackException.NotConnectedException - if the connection is not connected.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 org.jivesoftware.smack.StanzaListener addStanzaIdAcknowledgedListener(java.lang.String id,
org.jivesoftware.smack.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 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 - BundleAndDeferCallbackpublic 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