public abstract class AbstractXMPPConnection extends java.lang.Object implements XMPPConnection
connect(), login() and
disconnect() (which are deliberately not provided by the XMPPConnection interface).
Note: The default entry point to Smack's documentation is XMPPConnection. If you are getting started
with Smack, then head over to XMPPConnection and the come back here.
In case a Smack parser (Provider) throws those exceptions are handled over to the ParsingExceptionCallback. A
common cause for a provider throwing is illegal input, for example a non-numeric String where only Integers are
allowed. Smack's default behavior follows the "fail-hard per default" principle leading to a
termination of the connection on parsing exceptions. This default was chosen to make users eventually aware that they
should configure their own callback and handle those exceptions to prevent the disconnect. Handle a parsing exception
could be as simple as using a non-throwing no-op callback, which would cause the faulty stream element to be taken
out of the stream, i.e., Smack behaves like that element was never received.
If the parsing exception is because Smack received illegal input, then please consider informing the authors of the originating entity about that. If it was thrown because of an bug in a Smack parser, then please consider filling a bug with Smack.
The "fail-hard per default" behavior is achieved by using the
ExceptionThrowingCallbackWithHint as default parsing exception callback. You
can change the behavior using setParsingExceptionCallback(ParsingExceptionCallback) to set a new callback.
Use SmackConfiguration.setDefaultParsingExceptionCallback(ParsingExceptionCallback) to
set the default callback.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractXMPPConnection.InterceptorWrapper
A wrapper class to associate a stanza filter with an interceptor.
|
protected static class |
AbstractXMPPConnection.ListenerWrapper
A wrapper class to associate a stanza filter with a listener.
|
static class |
AbstractXMPPConnection.SmackTlsContext |
XMPPConnection.FromMode| Modifier and Type | Field and Description |
|---|---|
protected static AsyncButOrdered<AbstractXMPPConnection> |
ASYNC_BUT_ORDERED |
protected boolean |
authenticated
Flag that indicates if the user is currently authenticated with the server.
|
protected long |
authenticatedConnectionInitiallyEstablishedTimestamp |
protected SynchronizationPoint<java.lang.Exception> |
closingStreamReceived
A synchronization point which is successful if this connection has received the closing
stream element from the remote end-point, i.e.
|
protected XMPPInputOutputStream |
compressionHandler |
protected ConnectionConfiguration |
config
Holds the initial configuration used while creating the connection.
|
protected boolean |
connected |
protected int |
connectionCounterValue
A number to uniquely identify connections that are created.
|
protected java.util.Set<ConnectionListener> |
connectionListeners
A collection of ConnectionListeners which listen for connection closing
and reconnection events.
|
protected java.util.concurrent.locks.Lock |
connectionLock |
protected java.lang.Exception |
currentConnectionException |
protected SmackDebugger |
debugger
The SmackDebugger allows to log and debug XML traffic.
|
protected java.lang.String |
host
The used host to establish the connection to
|
protected java.util.List<HostAddress> |
hostAddresses |
protected AsyncButOrdered<StanzaListener> |
inOrderListeners |
protected SynchronizationPoint<SmackException> |
lastFeaturesReceived
Set to success if the last features stanza from the server has been parsed.
|
protected int |
port
The used port to establish the connection to
|
protected java.io.Reader |
reader
The Reader which is used for the debugger.
|
protected SASLAuthentication |
saslAuthentication
The SASLAuthentication manager that is responsible for authenticating with the server.
|
protected SynchronizationPoint<XMPPException> |
saslFeatureReceived
Set to success if the SASL feature has been received.
|
protected static SmackReactor |
SMACK_REACTOR |
protected java.util.Map<javax.xml.namespace.QName,FullyQualifiedElement> |
streamFeatures |
protected java.lang.String |
streamId
The stream ID, see RFC 6120 ยง 4.7.3
|
protected SynchronizationPoint<SmackException> |
tlsHandled |
protected org.jxmpp.jid.EntityFullJid |
user
The full JID of the authenticated user, as returned by the resource binding response of the server.
|
protected boolean |
wasAuthenticated
Flag that indicates if the user was authenticated with the server when the connection
to the server was closed (abruptly or not).
|
protected java.io.Writer |
writer
The Writer which is used for the debugger.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractXMPPConnection(ConnectionConfiguration configuration)
Create a new XMPPConnection to an XMPP server.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAsyncStanzaListener(StanzaListener packetListener,
StanzaFilter packetFilter)
Registers an asynchronous stanza listener with this connection.
|
void |
addConnectionListener(ConnectionListener connectionListener)
Adds a connection listener to this connection that will be notified when
the connection closes or fails.
|
void |
addOneTimeSyncCallback(StanzaListener callback,
StanzaFilter packetFilter)
Add a callback that is called exactly once and synchronously with the incoming stanza that matches the given
stanza filter.
|
void |
addStanzaInterceptor(StanzaListener packetInterceptor,
StanzaFilter packetFilter)
Registers a stanza interceptor with this connection.
|
void |
addStanzaListener(StanzaListener stanzaListener,
StanzaFilter stanzaFilter)
Registers a stanza listener with this connection.
|
void |
addStanzaSendingListener(StanzaListener packetListener,
StanzaFilter packetFilter)
Registers a stanza listener with this connection.
|
protected void |
addStreamFeature(FullyQualifiedElement feature) |
void |
addSyncStanzaListener(StanzaListener packetListener,
StanzaFilter packetFilter)
Registers a synchronous stanza listener with this connection.
|
protected void |
afterFeaturesReceived() |
protected void |
afterSuccessfulLogin(boolean resumed) |
protected static void |
asyncGo(java.lang.Runnable runnable) |
protected void |
asyncGoLimited(java.lang.Runnable runnable) |
protected org.jxmpp.jid.parts.Resourcepart |
bindResourceAndEstablishSession(org.jxmpp.jid.parts.Resourcepart resource) |
protected NonzaCallback.Builder |
buildNonzaCallback() |
protected void |
callConnectionAuthenticatedListener(boolean resumed) |
protected void |
callConnectionConnectedListener() |
AbstractXMPPConnection |
connect()
Establishes a connection to the XMPP server.
|
protected abstract void |
connectInternal()
Abstract method that concrete subclasses of XMPPConnection need to implement to perform their
way of XMPP connection establishment.
|
StanzaCollector |
createStanzaCollector(StanzaCollector.Configuration configuration)
Create a new stanza collector with the given stanza collector configuration.
|
StanzaCollector |
createStanzaCollector(StanzaFilter packetFilter)
Creates a new stanza collector for this connection.
|
StanzaCollector |
createStanzaCollectorAndSend(IQ packet)
Creates a new stanza collector collecting IQ responses that are replies to the IQ
request. |
StanzaCollector |
createStanzaCollectorAndSend(StanzaFilter packetFilter,
Stanza packet)
Creates a new stanza collector for this connection.
|
void |
disconnect()
Closes the connection by setting presence to unavailable then closing the connection to
the XMPP server.
|
void |
disconnect(Presence unavailablePresence)
Closes the connection.
|
protected void |
firePacketSendingListeners(TopLevelStreamElement sendTopLevelStreamElement)
Process all stanza listeners for sending stanzas.
|
long |
getAuthenticatedConnectionInitiallyEstablishedTimestamp()
Get the timestamp when the connection was the first time authenticated, i.e., when the first successful login was
performed.
|
ConnectionConfiguration |
getConfiguration()
Get the connection configuration used by this connection.
|
int |
getConnectionCounter()
Get the connection counter of this XMPPConnection instance.
|
protected java.util.concurrent.locks.Lock |
getConnectionLock() |
<F extends FullyQualifiedElement> |
getFeature(java.lang.String element,
java.lang.String namespace)
Get the feature stanza extensions for a given stream feature of the
server, or
null if the server doesn't support that feature. |
XMPPConnection.FromMode |
getFromMode()
Get the currently active FromMode.
|
java.lang.String |
getHost()
Returns the host name of the server where the XMPP server is running.
|
long |
getLastStanzaReceived()
Returns the timestamp in milliseconds when the last stanza was received.
|
ParsingExceptionCallback |
getParsingExceptionCallback()
Get the current active parsing exception callback.
|
int |
getPort()
Returns the port number of the XMPP server for this connection.
|
long |
getReplyTimeout()
Returns the current value of the reply timeout in milliseconds for request for this
XMPPConnection instance.
|
protected SASLAuthentication |
getSASLAuthentication()
Returns the SASLAuthentication manager that is responsible for authenticating with
the server.
|
protected AbstractXMPPConnection.SmackTlsContext |
getSmackTlsContext() |
java.lang.String |
getStreamId()
Returns the stream ID for this connection, which is the value set by the server
when opening an XMPP stream.
|
java.lang.String |
getUsedSaslMechansism()
Get the name of the SASL mechanism that was used to authenticate this connection.
|
org.jxmpp.jid.EntityFullJid |
getUser()
Returns the full XMPP address of the user that is logged in to the connection or
null if not logged in yet. |
org.jxmpp.jid.DomainBareJid |
getXMPPServiceDomain()
Returns the XMPP Domain of the service provided by the XMPP server and used for this connection.
|
boolean |
hasFeature(java.lang.String element,
java.lang.String namespace)
Return true if the server supports the given stream feature.
|
protected void |
initDebugger()
Initialize the
debugger. |
protected void |
initState() |
abstract void |
instantShutdown()
Performs an unclean disconnect and shutdown of the connection.
|
protected void |
invokeStanzaCollectorsAndNotifyRecvListeners(Stanza packet)
Invoke
StanzaCollector.processStanza(Stanza) for every
StanzaCollector with the given packet. |
boolean |
isAnonymous()
Returns true if currently authenticated anonymously.
|
boolean |
isAuthenticated()
Returns true if currently authenticated by successfully calling the login method.
|
boolean |
isConnected()
Returns true if currently connected to the XMPP server.
|
abstract boolean |
isSecureConnection()
Returns true if the connection to the server has successfully negotiated encryption.
|
abstract boolean |
isUsingCompression()
Returns true if network traffic is being compressed.
|
void |
login()
Logs in to the server using the strongest SASL mechanism supported by
the server.
|
void |
login(java.lang.CharSequence username,
java.lang.String password)
Same as
login(CharSequence, String, Resourcepart), but takes the resource from the connection
configuration. |
void |
login(java.lang.CharSequence username,
java.lang.String password,
org.jxmpp.jid.parts.Resourcepart resource)
Login with the given username (authorization identity).
|
protected abstract void |
loginInternal(java.lang.String username,
java.lang.String password,
org.jxmpp.jid.parts.Resourcepart resource) |
protected void |
notifyConnectionError(java.lang.Exception exception)
Sends out a notification that there was an error with the connection
and closes the connection.
|
protected void |
onStreamOpen(org.jivesoftware.smack.xml.XmlPullParser parser) |
protected void |
parseAndProcessNonza(org.jivesoftware.smack.xml.XmlPullParser parser) |
protected void |
parseAndProcessStanza(org.jivesoftware.smack.xml.XmlPullParser parser) |
protected void |
parseFeatures(org.jivesoftware.smack.xml.XmlPullParser parser) |
protected void |
parseFeaturesAndNotify(org.jivesoftware.smack.xml.XmlPullParser parser) |
protected java.util.List<HostAddress> |
populateHostAddresses()
Populates
hostAddresses with the resolved addresses or with the configured host address. |
protected void |
processStanza(Stanza stanza)
Processes a stanza after it's been fully parsed by looping through the installed
stanza collectors and listeners and letting them examine the stanza to see if
they are a match with the filter.
|
IQRequestHandler |
registerIQRequestHandler(IQRequestHandler iqRequestHandler)
Register an IQ request handler with this connection.
|
boolean |
removeAsyncStanzaListener(StanzaListener packetListener)
Removes an asynchronous stanza listener for received stanzas from this connection.
|
void |
removeConnectionListener(ConnectionListener connectionListener)
Removes a connection listener from this connection.
|
void |
removeStanzaCollector(StanzaCollector collector)
Remove a stanza collector of this connection.
|
void |
removeStanzaInterceptor(StanzaListener packetInterceptor)
Removes a stanza interceptor.
|
boolean |
removeStanzaListener(StanzaListener stanzaListener)
Removes a stanza listener for received stanzas from this connection.
|
void |
removeStanzaSendingListener(StanzaListener packetListener)
Removes a stanza listener for sending stanzas from this connection.
|
boolean |
removeSyncStanzaListener(StanzaListener packetListener)
Removes a stanza listener for received stanzas from this connection.
|
protected static ScheduledAction |
schedule(java.lang.Runnable runnable,
long delay,
java.util.concurrent.TimeUnit unit) |
protected <SN extends Nonza,FN extends Nonza> |
sendAndWaitForResponse(Nonza nonza,
java.lang.Class<SN> successNonzaClass,
java.lang.Class<FN> failedNonzaClass) |
<S extends Stanza> |
sendAsync(S stanza,
StanzaFilter replyFilter)
Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter.
|
<S extends Stanza> |
sendAsync(S stanza,
StanzaFilter replyFilter,
long timeout)
Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter.
|
<I extends IQ> |
sendIqRequestAndWaitForResponse(IQ request)
Send an IQ request and wait for the response.
|
SmackFuture<IQ,java.lang.Exception> |
sendIqRequestAsync(IQ request)
Send an IQ request asynchronously.
|
SmackFuture<IQ,java.lang.Exception> |
sendIqRequestAsync(IQ request,
long timeout)
Send an IQ request asynchronously.
|
abstract void |
sendNonza(Nonza element)
Send a Nonza.
|
void |
sendStanza(Stanza stanza)
Sends the specified stanza to the server.
|
protected abstract void |
sendStanzaInternal(Stanza packet) |
protected void |
sendStreamOpen() |
void |
setFromMode(XMPPConnection.FromMode fromMode)
Set the FromMode for this connection instance.
|
void |
setMaxAsyncOperations(int maxAsyncOperations) |
void |
setParsingExceptionCallback(ParsingExceptionCallback callback)
Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a
stanza.
|
void |
setReplyTimeout(long timeout)
Set the stanza reply timeout in milliseconds.
|
void |
setUnknownIqRequestReplyMode(SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode)
Set how Smack behaves when an unknown IQ request has been received.
|
protected void |
setWasAuthenticated()
Sets whether the connection has already logged in the server.
|
protected abstract void |
shutdown()
Shuts the current connection down.
|
protected void |
throwAlreadyConnectedExceptionIfAppropriate() |
protected void |
throwAlreadyLoggedInExceptionIfAppropriate() |
protected void |
throwNotConnectedExceptionIfAppropriate() |
protected void |
throwNotConnectedExceptionIfAppropriate(java.lang.String optionalHint) |
java.lang.String |
toString() |
boolean |
trySendStanza(Stanza stanza)
Try to send the given stanza.
|
boolean |
trySendStanza(Stanza stanza,
long timeout,
java.util.concurrent.TimeUnit unit)
Try to send the given stanza.
|
IQRequestHandler |
unregisterIQRequestHandler(IQRequestHandler iqRequestHandler)
Convenience method for
XMPPConnection.unregisterIQRequestHandler(String, String, org.jivesoftware.smack.packet.IQ.Type). |
IQRequestHandler |
unregisterIQRequestHandler(java.lang.String element,
java.lang.String namespace,
IQ.Type type)
Unregister an IQ request handler with this connection.
|
protected boolean |
waitForClosingStreamTagFromServer() |
protected static final SmackReactor SMACK_REACTOR
protected final java.util.Set<ConnectionListener> connectionListeners
protected final java.util.concurrent.locks.Lock connectionLock
protected final java.util.Map<javax.xml.namespace.QName,FullyQualifiedElement> streamFeatures
protected org.jxmpp.jid.EntityFullJid user
It is important that we don't infer the user from the login() arguments and the configurations service name, as, for example, when SASL External is used, the username is not given to login but taken from the 'external' certificate.
protected boolean connected
protected java.lang.String streamId
protected final SmackDebugger debugger
protected java.io.Reader reader
protected java.io.Writer writer
protected final SynchronizationPoint<SmackException> tlsHandled
protected final SynchronizationPoint<SmackException> lastFeaturesReceived
protected final SynchronizationPoint<XMPPException> saslFeatureReceived
protected final SynchronizationPoint<java.lang.Exception> closingStreamReceived
protected final SASLAuthentication saslAuthentication
protected final int connectionCounterValue
protected final ConnectionConfiguration config
protected XMPPInputOutputStream compressionHandler
protected static final AsyncButOrdered<AbstractXMPPConnection> ASYNC_BUT_ORDERED
protected final AsyncButOrdered<StanzaListener> inOrderListeners
protected java.lang.String host
protected int port
protected boolean authenticated
protected long authenticatedConnectionInitiallyEstablishedTimestamp
protected boolean wasAuthenticated
protected java.lang.Exception currentConnectionException
protected java.util.List<HostAddress> hostAddresses
protected AbstractXMPPConnection(ConnectionConfiguration configuration)
configuration - The configuration which is used to establish the connection.public ConnectionConfiguration getConfiguration()
public org.jxmpp.jid.DomainBareJid getXMPPServiceDomain()
XMPPConnectiongetXMPPServiceDomain in interface XMPPConnectionpublic java.lang.String getHost()
XMPPConnectiongetHost in interface XMPPConnectionpublic int getPort()
XMPPConnectiongetPort in interface XMPPConnectionpublic abstract boolean isSecureConnection()
XMPPConnectionisSecureConnection in interface XMPPConnectionprotected abstract void sendStanzaInternal(Stanza packet) throws SmackException.NotConnectedException, java.lang.InterruptedException
SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic boolean trySendStanza(Stanza stanza) throws SmackException.NotConnectedException
XMPPConnectiontrue if the stanza was successfully put into the outgoing stanza
queue, otherwise, if false is returned, the stanza could not be scheduled for sending (for example
because the outgoing element queue is full). Note that this means that the stanza possibly was not put onto the
wire, even if true is returned, it just has been successfully scheduled for sending.
Note: Implementations are not required to provide that functionality. In that case this method is mapped
to XMPPConnection.sendStanza(Stanza) and will possibly block until the stanza could be scheduled for sending.
trySendStanza in interface XMPPConnectionstanza - the stanza to send.true if the stanza was successfully scheduled to be send, false otherwise.SmackException.NotConnectedException - if the connection is not connected.public boolean trySendStanza(Stanza stanza, long timeout, java.util.concurrent.TimeUnit unit) throws SmackException.NotConnectedException, java.lang.InterruptedException
XMPPConnectiontrue if the stanza was successfully put into the outgoing stanza
queue within the given timeout period, otherwise, if false is returned, the stanza could not be scheduled
for sending (for example because the outgoing element queue is full). Note that this means that the stanza
possibly was not put onto the wire, even if true is returned, it just has been successfully scheduled for
sending.
Note: Implementations are not required to provide that functionality. In that case this method is mapped
to XMPPConnection.sendStanza(Stanza) and will possibly block until the stanza could be scheduled for sending.
trySendStanza in interface XMPPConnectionstanza - the stanza to send.timeout - how long to wait before giving up, in units of unit.unit - a TimeUnit determining how to interpret the timeout parameter.true if the stanza was successfully scheduled to be send, false otherwise.SmackException.NotConnectedException - if the connection is not connected.java.lang.InterruptedException - if the calling thread was interrupted.public abstract void sendNonza(Nonza element) throws SmackException.NotConnectedException, java.lang.InterruptedException
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.
sendNonza in interface XMPPConnectionelement - the Nonza to send.SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic abstract boolean isUsingCompression()
XMPPConnectionisUsingCompression in interface XMPPConnectionprotected void initState()
public AbstractXMPPConnection connect() throws SmackException, java.io.IOException, XMPPException, java.lang.InterruptedException
Listeners will be preserved from a previous connection.
connect() with login().XMPPException - if an error occurs on the XMPP protocol level.SmackException - if an error occurs somewhere else besides XMPP protocol level.java.io.IOExceptionjava.lang.InterruptedExceptionprotected abstract void connectInternal()
throws SmackException,
java.io.IOException,
XMPPException,
java.lang.InterruptedException
SmackExceptionjava.io.IOExceptionXMPPExceptionjava.lang.InterruptedExceptionpublic void login()
throws XMPPException,
SmackException,
java.io.IOException,
java.lang.InterruptedException
SmackException.NoResponseException will be thrown.
Before logging in (i.e. authenticate) to the server the connection must be connected
by calling connect().
It is possible to log in without sending an initial available presence by using
ConnectionConfiguration.Builder.setSendPresence(boolean).
Finally, if you want to not pass a password and instead use a more advanced mechanism
while using SASL then you may be interested in using
ConnectionConfiguration.Builder.setCallbackHandler(javax.security.auth.callback.CallbackHandler).
For more advanced login settings see ConnectionConfiguration.
XMPPException - if an error occurs on the XMPP protocol level.SmackException - if an error occurs somewhere else besides XMPP protocol level.java.io.IOException - if an I/O error occurs during login.java.lang.InterruptedExceptionpublic void login(java.lang.CharSequence username,
java.lang.String password)
throws XMPPException,
SmackException,
java.io.IOException,
java.lang.InterruptedException
login(CharSequence, String, Resourcepart), but takes the resource from the connection
configuration.username - password - XMPPExceptionSmackExceptionjava.io.IOExceptionjava.lang.InterruptedExceptionlogin()public void login(java.lang.CharSequence username,
java.lang.String password,
org.jxmpp.jid.parts.Resourcepart resource)
throws XMPPException,
SmackException,
java.io.IOException,
java.lang.InterruptedException
username - password - resource - XMPPExceptionSmackExceptionjava.io.IOExceptionjava.lang.InterruptedExceptionlogin()protected abstract void loginInternal(java.lang.String username,
java.lang.String password,
org.jxmpp.jid.parts.Resourcepart resource)
throws XMPPException,
SmackException,
java.io.IOException,
java.lang.InterruptedException
XMPPExceptionSmackExceptionjava.io.IOExceptionjava.lang.InterruptedExceptionpublic final boolean isConnected()
XMPPConnectionisConnected in interface XMPPConnectionpublic final boolean isAuthenticated()
XMPPConnectionisAuthenticated in interface XMPPConnectionpublic final org.jxmpp.jid.EntityFullJid getUser()
XMPPConnectionnull if not logged in yet. An XMPP address is in the form
username@server/resource.getUser in interface XMPPConnectionpublic java.lang.String getStreamId()
XMPPConnectionnull if not connected to the server.getStreamId in interface XMPPConnectionnull if
not connected to the server.protected org.jxmpp.jid.parts.Resourcepart bindResourceAndEstablishSession(org.jxmpp.jid.parts.Resourcepart resource)
throws XMPPException.XMPPErrorException,
SmackException,
java.lang.InterruptedException
XMPPException.XMPPErrorExceptionSmackExceptionjava.lang.InterruptedExceptionprotected void afterSuccessfulLogin(boolean resumed)
throws SmackException.NotConnectedException,
java.lang.InterruptedException
SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic final boolean isAnonymous()
XMPPConnectionisAnonymous in interface XMPPConnectionpublic final java.lang.String getUsedSaslMechansism()
null if
this connection was not authenticated before.protected java.util.List<HostAddress> populateHostAddresses()
hostAddresses with the resolved addresses or with the configured host address. If no host
address was configured and all lookups failed, for example with NX_DOMAIN, then hostAddresses will be
populated with the empty list.protected java.util.concurrent.locks.Lock getConnectionLock()
protected void throwNotConnectedExceptionIfAppropriate()
throws SmackException.NotConnectedException
protected void throwNotConnectedExceptionIfAppropriate(java.lang.String optionalHint)
throws SmackException.NotConnectedException
protected void throwAlreadyConnectedExceptionIfAppropriate()
throws SmackException.AlreadyConnectedException
protected void throwAlreadyLoggedInExceptionIfAppropriate()
throws SmackException.AlreadyLoggedInException
public final void sendStanza(Stanza stanza) throws SmackException.NotConnectedException, java.lang.InterruptedException
XMPPConnectionsendStanza in interface XMPPConnectionstanza - the stanza to send.SmackException.NotConnectedException - if the connection is not connected.java.lang.InterruptedExceptionprotected SASLAuthentication getSASLAuthentication()
public void disconnect()
public void disconnect(Presence unavailablePresence) throws SmackException.NotConnectedException
unavailablePresence - the optional presence stanza to send during shutdown.SmackException.NotConnectedExceptionprotected final void notifyConnectionError(java.lang.Exception exception)
exception - the exception that causes the connection close event.public abstract void instantShutdown()
protected abstract void shutdown()
protected final boolean waitForClosingStreamTagFromServer()
public void addConnectionListener(ConnectionListener connectionListener)
XMPPConnectionaddConnectionListener in interface XMPPConnectionconnectionListener - a connection listener.public void removeConnectionListener(ConnectionListener connectionListener)
XMPPConnectionremoveConnectionListener in interface XMPPConnectionconnectionListener - a connection listener.public <I extends IQ> I sendIqRequestAndWaitForResponse(IQ request) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
XMPPConnectionsendIqRequestAndWaitForResponse in interface XMPPConnectionrequest - the IQ requestSmackException.NoResponseExceptionXMPPException.XMPPErrorExceptionSmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic StanzaCollector createStanzaCollectorAndSend(IQ packet) throws SmackException.NotConnectedException, java.lang.InterruptedException
XMPPConnectionrequest.
Does also send the request IQ. The stanza filter for the collector is an
IQReplyFilter, guaranteeing that stanza id and JID in the 'from' address have
expected values.createStanzaCollectorAndSend in interface XMPPConnectionpacket - the IQ request to filter responses fromSmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic StanzaCollector createStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet) throws SmackException.NotConnectedException, java.lang.InterruptedException
XMPPConnectionStanzaListener when you need to wait for
a specific result.createStanzaCollectorAndSend in interface XMPPConnectionpacketFilter - the stanza filter to use.packet - the stanza to send right after the collector got createdSmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic StanzaCollector createStanzaCollector(StanzaFilter packetFilter)
XMPPConnectionStanzaListener
when you need to wait for a specific result.
Note: If you send a Stanza right after using this method, then
consider using
XMPPConnection.createStanzaCollectorAndSend(StanzaFilter, Stanza) instead.
Otherwise make sure cancel the StanzaCollector in every case, e.g. even
if an exception is thrown, or otherwise you may leak the StanzaCollector.
createStanzaCollector in interface XMPPConnectionpacketFilter - the stanza filter to use.public StanzaCollector createStanzaCollector(StanzaCollector.Configuration configuration)
XMPPConnection
Please make sure to cancel the collector when it is no longer required. See also
XMPPConnection.createStanzaCollector(StanzaFilter).
createStanzaCollector in interface XMPPConnectionconfiguration - the stanza collector configuration.public void removeStanzaCollector(StanzaCollector collector)
XMPPConnectionremoveStanzaCollector in interface XMPPConnectioncollector - a stanza collectors which was created for this connection.public final void addStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter)
XMPPConnectionaddStanzaListener in interface XMPPConnectionstanzaListener - the stanza listener to notify of new received stanzas.stanzaFilter - the stanza filter to use.public final boolean removeStanzaListener(StanzaListener stanzaListener)
XMPPConnectionremoveStanzaListener in interface XMPPConnectionstanzaListener - the stanza listener to remove.public void addSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter)
XMPPConnection
Important: This stanza listeners will be called in the same single thread that processes all
incoming stanzas. Only use this kind of stanza filter if it does not perform any XMPP activity that waits for a
response. Consider using XMPPConnection.addAsyncStanzaListener(StanzaListener, StanzaFilter) when possible, i.e. when
the invocation order doesn't have to be the same as the order of the arriving stanzas. If the order of the
arriving stanzas, consider using a StanzaCollector when possible.
addSyncStanzaListener in interface XMPPConnectionpacketListener - the stanza listener to notify of new received stanzas.packetFilter - the stanza filter to use.XMPPConnection.addStanzaInterceptor(StanzaListener, StanzaFilter)public boolean removeSyncStanzaListener(StanzaListener packetListener)
XMPPConnectionremoveSyncStanzaListener in interface XMPPConnectionpacketListener - the stanza listener to remove.public void addAsyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter)
XMPPConnection
Unlike XMPPConnection.addAsyncStanzaListener(StanzaListener, StanzaFilter) stanza listeners added with this method will be
invoked asynchronously in their own thread. Use this method if the order of the stanza listeners must not depend
on the order how the stanzas where received.
addAsyncStanzaListener in interface XMPPConnectionpacketListener - the stanza listener to notify of new received stanzas.packetFilter - the stanza filter to use.XMPPConnection.addStanzaInterceptor(StanzaListener, StanzaFilter)public boolean removeAsyncStanzaListener(StanzaListener packetListener)
XMPPConnectionremoveAsyncStanzaListener in interface XMPPConnectionpacketListener - the stanza listener to remove.public void addStanzaSendingListener(StanzaListener packetListener, StanzaFilter packetFilter)
XMPPConnectionaddStanzaSendingListener in interface XMPPConnectionpacketListener - the stanza listener to notify of sent stanzas.packetFilter - the stanza filter to use.public void removeStanzaSendingListener(StanzaListener packetListener)
XMPPConnectionremoveStanzaSendingListener in interface XMPPConnectionpacketListener - the stanza listener to remove.protected void firePacketSendingListeners(TopLevelStreamElement sendTopLevelStreamElement)
Compared to firePacketInterceptors(Stanza), the listeners will be invoked in a new thread.
sendTopLevelStreamElement - the top level stream element which just got send.public void addStanzaInterceptor(StanzaListener packetInterceptor, StanzaFilter packetFilter)
XMPPConnection
NOTE: For a similar functionality on incoming stanzas, see XMPPConnection.addAsyncStanzaListener(StanzaListener, StanzaFilter).
addStanzaInterceptor in interface XMPPConnectionpacketInterceptor - the stanza interceptor to notify of stanzas about to be sent.packetFilter - the stanza filter to use.public void removeStanzaInterceptor(StanzaListener packetInterceptor)
XMPPConnectionremoveStanzaInterceptor in interface XMPPConnectionpacketInterceptor - the stanza interceptor to remove.protected void initDebugger()
debugger. You can specify a customized SmackDebugger
by setup the system property smack.debuggerClass to the implementation.java.lang.IllegalStateException - if the reader or writer isn't yet initialized.java.lang.IllegalArgumentException - if the SmackDebugger can't be loaded.public long getReplyTimeout()
XMPPConnectiongetReplyTimeout in interface XMPPConnectionpublic void setReplyTimeout(long timeout)
XMPPConnectionSmackException.NoResponseException if no reply to a request was received within the timeout period.setReplyTimeout in interface XMPPConnectiontimeout - for a reply in millisecondspublic void setUnknownIqRequestReplyMode(SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode)
unknownIqRequestReplyMode - reply mode.protected final NonzaCallback.Builder buildNonzaCallback()
protected <SN extends Nonza,FN extends Nonza> SN sendAndWaitForResponse(Nonza nonza, java.lang.Class<SN> successNonzaClass, java.lang.Class<FN> failedNonzaClass) throws SmackException.NoResponseException, SmackException.NotConnectedException, java.lang.InterruptedException, XMPPException.FailedNonzaException
SmackException.NoResponseExceptionSmackException.NotConnectedExceptionjava.lang.InterruptedExceptionXMPPException.FailedNonzaExceptionprotected final void parseAndProcessNonza(org.jivesoftware.smack.xml.XmlPullParser parser)
throws java.io.IOException,
org.jivesoftware.smack.xml.XmlPullParserException,
SmackParsingException
java.io.IOExceptionorg.jivesoftware.smack.xml.XmlPullParserExceptionSmackParsingExceptionprotected void parseAndProcessStanza(org.jivesoftware.smack.xml.XmlPullParser parser)
throws org.jivesoftware.smack.xml.XmlPullParserException,
java.io.IOException,
java.lang.InterruptedException
org.jivesoftware.smack.xml.XmlPullParserExceptionjava.io.IOExceptionjava.lang.InterruptedExceptionprotected void processStanza(Stanza stanza) throws java.lang.InterruptedException
stanza - the stanza to process.java.lang.InterruptedExceptionprotected void invokeStanzaCollectorsAndNotifyRecvListeners(Stanza packet)
StanzaCollector.processStanza(Stanza) for every
StanzaCollector with the given packet. Also notify the receive listeners with a matching stanza filter about the packet.
This method will be invoked by the connections incoming processing thread which may be shared across multiple connections and thus it is important that no user code, e.g. in form of a callback, is invoked by this method. For the same reason, this method must not block for an extended period of time.
packet - the stanza to notify the StanzaCollectors and receive listeners about.protected void setWasAuthenticated()
wasAuthenticated flag is never reset once it has ever been set.protected void callConnectionConnectedListener()
protected void callConnectionAuthenticatedListener(boolean resumed)
public int getConnectionCounter()
XMPPConnection2*Integer.MAX_VALUE instances as the counter could wrap.getConnectionCounter in interface XMPPConnectionpublic void setFromMode(XMPPConnection.FromMode fromMode)
XMPPConnectionsetFromMode in interface XMPPConnectionpublic XMPPConnection.FromMode getFromMode()
XMPPConnectiongetFromMode in interface XMPPConnectionXMPPConnection.FromModeprotected final void parseFeatures(org.jivesoftware.smack.xml.XmlPullParser parser)
throws org.jivesoftware.smack.xml.XmlPullParserException,
java.io.IOException,
SmackParsingException
org.jivesoftware.smack.xml.XmlPullParserExceptionjava.io.IOExceptionSmackParsingExceptionprotected final void parseFeaturesAndNotify(org.jivesoftware.smack.xml.XmlPullParser parser)
throws java.lang.Exception
java.lang.Exceptionprotected void afterFeaturesReceived()
throws SmackException.SecurityRequiredException,
SmackException.NotConnectedException,
java.lang.InterruptedException
SmackException.SecurityRequiredExceptionSmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic <F extends FullyQualifiedElement> F getFeature(java.lang.String element, java.lang.String namespace)
XMPPConnectionnull if the server doesn't support that feature.getFeature in interface XMPPConnectionF - ExtensionElement type of the feature.nullpublic boolean hasFeature(java.lang.String element,
java.lang.String namespace)
XMPPConnectionhasFeature in interface XMPPConnectionprotected void addStreamFeature(FullyQualifiedElement feature)
public SmackFuture<IQ,java.lang.Exception> sendIqRequestAsync(IQ request)
XMPPConnectionsendIqRequestAsync in interface XMPPConnectionrequest - the IQ request to send.public SmackFuture<IQ,java.lang.Exception> sendIqRequestAsync(IQ request, long timeout)
XMPPConnectionsendIqRequestAsync in interface XMPPConnectionrequest - the IQ request to send.timeout - the reply timeout in milliseconds.public <S extends Stanza> SmackFuture<S,java.lang.Exception> sendAsync(S stanza, StanzaFilter replyFilter)
XMPPConnectionsendAsync in interface XMPPConnectionstanza - the stanza to send.replyFilter - the filter used for the response stanza.public <S extends Stanza> SmackFuture<S,java.lang.Exception> sendAsync(S stanza, StanzaFilter replyFilter, long timeout)
XMPPConnectionsendAsync in interface XMPPConnectionstanza - the stanza to send.replyFilter - the filter used for the response stanza.timeout - the reply timeout in milliseconds.public void addOneTimeSyncCallback(StanzaListener callback, StanzaFilter packetFilter)
XMPPConnectionaddOneTimeSyncCallback in interface XMPPConnectioncallback - the callback invoked once the stanza filter matches a stanza.packetFilter - the filter to match stanzas or null to match all.public IQRequestHandler registerIQRequestHandler(IQRequestHandler iqRequestHandler)
XMPPConnectionIQ request handler process incoming IQ requests, i.e. incoming IQ stanzas of type 'get' or 'set', and return a result.
registerIQRequestHandler in interface XMPPConnectioniqRequestHandler - the IQ request handler to register.public final IQRequestHandler unregisterIQRequestHandler(IQRequestHandler iqRequestHandler)
XMPPConnectionXMPPConnection.unregisterIQRequestHandler(String, String, org.jivesoftware.smack.packet.IQ.Type).unregisterIQRequestHandler in interface XMPPConnectionpublic IQRequestHandler unregisterIQRequestHandler(java.lang.String element, java.lang.String namespace, IQ.Type type)
XMPPConnectionunregisterIQRequestHandler in interface XMPPConnectionelement - the IQ element the IQ request handler is responsible for.namespace - the IQ namespace the IQ request handler is responsible for.type - the IQ type the IQ request handler is responsible for.public long getLastStanzaReceived()
XMPPConnectiongetLastStanzaReceived in interface XMPPConnectionpublic final long getAuthenticatedConnectionInitiallyEstablishedTimestamp()
null.public void setParsingExceptionCallback(ParsingExceptionCallback callback)
callback - the callback to installpublic ParsingExceptionCallback getParsingExceptionCallback()
public final java.lang.String toString()
toString in class java.lang.Objectprotected void asyncGoLimited(java.lang.Runnable runnable)
public void setMaxAsyncOperations(int maxAsyncOperations)
protected static void asyncGo(java.lang.Runnable runnable)
protected static ScheduledAction schedule(java.lang.Runnable runnable, long delay, java.util.concurrent.TimeUnit unit)
protected void onStreamOpen(org.jivesoftware.smack.xml.XmlPullParser parser)
protected void sendStreamOpen()
throws SmackException.NotConnectedException,
java.lang.InterruptedException
SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionprotected final AbstractXMPPConnection.SmackTlsContext getSmackTlsContext() throws java.security.KeyManagementException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOException, java.security.UnrecoverableKeyException, java.security.KeyStoreException, java.security.NoSuchProviderException
java.security.KeyManagementExceptionjava.security.NoSuchAlgorithmExceptionjava.security.cert.CertificateExceptionjava.io.IOExceptionjava.security.UnrecoverableKeyExceptionjava.security.KeyStoreExceptionjava.security.NoSuchProviderException