public class XMPPTCPConnection extends AbstractXMPPConnection
XMPPConnection| Modifier and Type | Class and Description |
|---|---|
protected class |
XMPPTCPConnection.PacketReader |
protected class |
XMPPTCPConnection.PacketWriter |
AbstractXMPPConnection.InterceptorWrapper, AbstractXMPPConnection.ListenerWrapperXMPPConnection.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, streamFeatures, streamId, 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 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()
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 |
isSocketClosed() |
boolean |
isUsingCompression()
Returns true if network traffic is being compressed.
|
void |
loginAnonymously() |
protected void |
loginNonAnonymously(String username,
String password,
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(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 |
send(PlainStreamElement element)
Send a PlainStreamElement.
|
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, 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(CharSequence jid, 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(CharSequence username, String password, 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 SmackException.NotConnectedException
throwNotConnectedExceptionIfAppropriate in class AbstractXMPPConnectionSmackException.NotConnectedExceptionprotected void throwAlreadyConnectedExceptionIfAppropriate() throws SmackException.AlreadyConnectedException
throwAlreadyConnectedExceptionIfAppropriate in class AbstractXMPPConnectionSmackException.AlreadyConnectedExceptionprotected void throwAlreadyLoggedInExceptionIfAppropriate() throws SmackException.AlreadyLoggedInException
throwAlreadyLoggedInExceptionIfAppropriate in class AbstractXMPPConnectionSmackException.AlreadyLoggedInExceptionprotected void afterSuccessfulLogin(boolean resumed) throws SmackException.NotConnectedException
afterSuccessfulLogin in class AbstractXMPPConnectionSmackException.NotConnectedExceptionprotected void loginNonAnonymously(String username, String password, String resource) throws XMPPException, SmackException, IOException
loginNonAnonymously in class AbstractXMPPConnectionXMPPExceptionSmackExceptionIOExceptionpublic void loginAnonymously() throws XMPPException, SmackException, IOException
loginAnonymously in class AbstractXMPPConnectionXMPPExceptionSmackExceptionIOExceptionpublic boolean isSecureConnection()
XMPPConnectionisSecureConnection in interface XMPPConnectionisSecureConnection in class AbstractXMPPConnectionpublic boolean isSocketClosed()
protected void shutdown()
shutdown in class AbstractXMPPConnectionpublic void instantShutdown()
public void send(PlainStreamElement element) throws SmackException.NotConnectedException
XMPPConnectionThis 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.
send in interface XMPPConnectionsend in class AbstractXMPPConnectionSmackException.NotConnectedExceptionprotected void sendStanzaInternal(Stanza packet) throws SmackException.NotConnectedException
sendStanzaInternal in class AbstractXMPPConnectionSmackException.NotConnectedExceptionpublic boolean isUsingCompression()
XMPPConnectionisUsingCompression in interface XMPPConnectionisUsingCompression in class AbstractXMPPConnectionprotected void connectInternal() throws SmackException, IOException, XMPPException
Listeners will be preserved from a previous connection if the reconnection occurs after an abrupt termination.
connectInternal in class AbstractXMPPConnectionXMPPException - if an error occurs while trying to establish the connection.SmackExceptionIOExceptionprotected void afterFeaturesReceived() throws SmackException.SecurityRequiredException, SmackException.NotConnectedException
afterFeaturesReceived in class AbstractXMPPConnectionSmackException.SecurityRequiredExceptionSmackException.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(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
StreamManagementException.StreamManagementNotEnabledException - if Stream Mangement is not enabled.SmackException.NotConnectedException - if the connection is not connected.public void sendSmAcknowledgement() throws StreamManagementException.StreamManagementNotEnabledException, 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.SmackException.NotConnectedException - if the connection is not connected.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 - 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