Class AbstractXMPPConnection
- java.lang.Object
-
- org.jivesoftware.smack.AbstractXMPPConnection
-
- All Implemented Interfaces:
XMPPConnection
- Direct Known Subclasses:
ModularXmppClientToServerConnection
,XMPPBOSHConnection
,XMPPTCPConnection
public abstract class AbstractXMPPConnection extends Object implements XMPPConnection
This abstract class is commonly used as super class for XMPP connection mechanisms like TCP and BOSH. Hence it provides the methods for connection state management, likeconnect()
,login()
anddisconnect()
(which are deliberately not provided by theXMPPConnection
interface).Note: The default entry point to Smack's documentation is
XMPPConnection
. If you are getting started with Smack, then head over toXMPPConnection
and the come back here.Parsing Exceptions
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.
Managing the parsing exception callback
The "fail-hard per default" behavior is achieved by using the
ExceptionThrowingCallbackWithHint
as default parsing exception callback. You can change the behavior usingsetParsingExceptionCallback(ParsingExceptionCallback)
to set a new callback. UseSmackConfiguration.setDefaultParsingExceptionCallback(ParsingExceptionCallback)
to set the default callback.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractXMPPConnection.InterceptorWrapper
Deprecated.protected static class
AbstractXMPPConnection.ListenerWrapper
A wrapper class to associate a stanza filter with a listener.protected static class
AbstractXMPPConnection.SyncPointState
-
Nested classes/interfaces inherited from interface org.jivesoftware.smack.XMPPConnection
XMPPConnection.FromMode
-
-
Field Summary
Fields Modifier and Type Field 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 boolean
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 Set<ConnectionListener>
connectionListeners
A collection of ConnectionListeners which listen for connection closing and reconnection events.protected Lock
connectionLock
protected SmackException
currentSmackException
protected XMPPException
currentXmppException
protected SmackDebugger
debugger
The SmackDebugger allows to log and debug XML traffic.protected String
host
The used host to establish the connection toprotected boolean
lastFeaturesReceived
Set totrue
if the last features stanza from the server has been parsed.protected XmlEnvironment
outgoingStreamXmlEnvironment
protected UInt16
port
The used port to establish the connection toprotected Reader
reader
The Reader which is used for the debugger.protected boolean
saslFeatureReceived
Set totrue
if the SASL feature has been received.protected static SmackReactor
SMACK_REACTOR
protected Map<QName,XmlElement>
streamFeatures
protected String
streamId
The stream ID, see RFC 6120 § 4.7.3protected boolean
tlsHandled
protected 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 Writer
writer
The Writer which is used for the debugger.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractXMPPConnection(ConnectionConfiguration configuration)
Create a new XMPPConnection to an XMPP server.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method 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
addMessageInterceptor(Consumer<MessageBuilder> messageInterceptor, Predicate<Message> messageFilter)
Registers a stanza interceptor with this connection.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
addPresenceInterceptor(Consumer<PresenceBuilder> presenceInterceptor, Predicate<Presence> presenceFilter)
Registers a stanza interceptor with this connection.void
addStanzaInterceptor(StanzaListener packetInterceptor, StanzaFilter packetFilter)
Deprecated.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(XmlElement feature)
void
addSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter)
Registers a synchronous stanza listener with this connection.protected void
afterFeaturesReceived()
protected void
afterSaslAuthenticationSuccess()
Hook for subclasses right after successful SASL authentication.protected void
afterSuccessfulLogin(boolean resumed)
protected static void
asyncGo(Runnable runnable)
protected void
asyncGoLimited(Runnable runnable)
protected SASLMechanism
authenticate(String username, String password, EntityBareJid authzid, SSLSession sslSession)
Authenticate a connection.protected Resourcepart
bindResourceAndEstablishSession(Resourcepart resource)
protected NonzaCallback.Builder
buildNonzaCallback()
protected void
callConnectionAuthenticatedListener(boolean resumed)
protected void
callConnectionConnectedListener()
protected void
callConnectionConnectingListener()
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(StanzaFilter packetFilter)
Creates a new stanza collector for this connection.StanzaCollector
createStanzaCollector(StanzaCollector.Configuration configuration)
Create a new stanza collector with the given stanza collector configuration.StanzaCollector
createStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
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 IQrequest
.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 Lock
getConnectionLock()
<F extends XmlElement>
FgetFeature(QName qname)
Get the feature stanza extensions for a given stream feature of the server, ornull
if the server doesn't support that feature.XMPPConnection.FromMode
getFromMode()
Get the currently active FromMode.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.protected SmackReactor
getReactor()
long
getReplyTimeout()
Returns the current value of the reply timeout in milliseconds for request for this XMPPConnection instance.protected SmackTlsContext
getSmackTlsContext()
StanzaFactory
getStanzaFactory()
String
getStreamId()
Returns the stream ID for this connection, which is the value set by the server when opening an XMPP stream.protected AbstractStreamOpen
getStreamOpen(DomainBareJid to, CharSequence from, String id, String lang)
String
getUsedSaslMechansism()
Get the name of the SASL mechanism that was used to authenticate this connection.EntityFullJid
getUser()
Returns the full XMPP address of the user that is logged in to the connection ornull
if not logged in yet.DomainBareJid
getXMPPServiceDomain()
Returns the XMPP Domain of the service provided by the XMPP server and used for this connection.protected boolean
hasCurrentConnectionException()
boolean
hasFeature(QName qname)
Return true if the server supports the given stream feature.protected void
initDebugger()
Initialize thedebugger
.protected void
initState()
abstract void
instantShutdown()
Performs an unclean disconnect and shutdown of the connection.protected void
invokeStanzaCollectorsAndNotifyRecvListeners(Stanza packet)
InvokeStanzaCollector.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.protected boolean
isSaslAuthenticated()
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(CharSequence username, String password)
Same aslogin(CharSequence, String, Resourcepart)
, but takes the resource from the connection configuration.void
login(CharSequence username, String password, Resourcepart resource)
Login with the given username (authorization identity).protected abstract void
loginInternal(String username, String password, Resourcepart resource)
protected void
notifyConnectionError(Exception exception)
Sends out a notification that there was an error with the connection and closes the connection.protected void
notifyWaitingThreads()
protected String
onStreamOpen(XmlPullParser parser)
Must be called when a XMPP stream open tag is encountered.protected void
parseAndProcessNonza(XmlPullParser parser)
protected void
parseAndProcessStanza(XmlPullParser parser)
protected void
parseFeatures(XmlPullParser parser)
protected void
parseFeaturesAndNotify(XmlPullParser parser)
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
removeMessageInterceptor(Consumer<MessageBuilder> messageInterceptor)
Removes a message interceptor.void
removePresenceInterceptor(Consumer<PresenceBuilder> presenceInterceptor)
Removes a presence interceptor.void
removeStanzaCollector(StanzaCollector collector)
Remove a stanza collector of this connection.void
removeStanzaInterceptor(StanzaListener packetInterceptor)
Deprecated.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(Runnable runnable, long delay, TimeUnit unit)
protected <SN extends Nonza,FN extends Nonza>
SNsendAndWaitForResponse(Nonza nonza, Class<SN> successNonzaClass, Class<FN> failedNonzaClass)
<S extends Stanza>
SmackFuture<S,Exception>sendAsync(S stanza, StanzaFilter replyFilter)
Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter.<S extends Stanza>
SmackFuture<S,Exception>sendAsync(S stanza, StanzaFilter replyFilter, long timeout)
Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter.protected abstract void
sendInternal(TopLevelStreamElement element)
<I extends IQ>
IsendIqRequestAndWaitForResponse(IQ request)
Send an IQ request and wait for the response.SmackFuture<IQ,Exception>
sendIqRequestAsync(IQ request)
Send an IQ request asynchronously.SmackFuture<IQ,Exception>
sendIqRequestAsync(IQ request, long timeout)
Send an IQ request asynchronously.protected abstract void
sendNonBlockingInternal(TopLevelStreamElement element)
void
sendNonza(Nonza nonza)
Send a Nonza.void
sendNonzaNonBlocking(Nonza nonza)
void
sendStanza(Stanza stanza)
Sends the specified stanza to the server.void
sendStanzaNonBlocking(Stanza stanza)
protected void
sendStreamOpen()
protected void
setCurrentConnectionExceptionAndNotify(Exception exception)
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
throwCurrentConnectionException()
protected void
throwNotConnectedExceptionIfAppropriate()
protected void
throwNotConnectedExceptionIfAppropriate(String optionalHint)
String
toString()
boolean
trySendStanza(Stanza stanza)
Try to send the given stanza.boolean
trySendStanza(Stanza stanza, long timeout, TimeUnit unit)
Try to send the given stanza.IQRequestHandler
unregisterIQRequestHandler(String element, String namespace, IQ.Type type)
Unregister an IQ request handler with this connection.IQRequestHandler
unregisterIQRequestHandler(IQRequestHandler iqRequestHandler)
Convenience method forXMPPConnection.unregisterIQRequestHandler(String, String, org.jivesoftware.smack.packet.IQ.Type)
.protected void
updateOutgoingStreamXmlEnvironmentOnStreamOpen(AbstractStreamOpen streamOpen)
protected boolean
waitFor(Supplier<Boolean> condition)
protected boolean
waitForClosingStreamTagFromServer()
protected void
waitForConditionOrThrowConnectionException(Supplier<Boolean> condition, String waitFor)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.XMPPConnection
getFeature, getFeature, getLocalAddress, hasFeature
-
-
-
-
Field Detail
-
SMACK_REACTOR
protected static final SmackReactor SMACK_REACTOR
-
connectionListeners
protected final Set<ConnectionListener> connectionListeners
A collection of ConnectionListeners which listen for connection closing and reconnection events.
-
outgoingStreamXmlEnvironment
protected XmlEnvironment outgoingStreamXmlEnvironment
-
connectionLock
protected final Lock connectionLock
-
streamFeatures
protected final Map<QName,XmlElement> streamFeatures
-
user
protected EntityFullJid user
The full JID of the authenticated user, as returned by the resource binding response of the server.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.
-
connected
protected boolean connected
-
debugger
protected final SmackDebugger debugger
The SmackDebugger allows to log and debug XML traffic.
-
currentSmackException
protected SmackException currentSmackException
-
currentXmppException
protected XMPPException currentXmppException
-
tlsHandled
protected boolean tlsHandled
-
lastFeaturesReceived
protected boolean lastFeaturesReceived
Set totrue
if the last features stanza from the server has been parsed. A XMPP connection handshake can invoke multiple features stanzas, e.g. when TLS is activated a second feature stanza is send by the server. This is set to true once the last feature stanza has been parsed.
-
saslFeatureReceived
protected boolean saslFeatureReceived
Set totrue
if the SASL feature has been received.
-
closingStreamReceived
protected boolean closingStreamReceived
A synchronization point which is successful if this connection has received the closing stream element from the remote end-point, i.e. the server.
-
connectionCounterValue
protected final int connectionCounterValue
A number to uniquely identify connections that are created. This is distinct from the connection ID, which is a value sent by the server once a connection is made.
-
config
protected final ConnectionConfiguration config
Holds the initial configuration used while creating the connection.
-
compressionHandler
protected XMPPInputOutputStream compressionHandler
-
ASYNC_BUT_ORDERED
protected static final AsyncButOrdered<AbstractXMPPConnection> ASYNC_BUT_ORDERED
-
authenticated
protected boolean authenticated
Flag that indicates if the user is currently authenticated with the server.
-
authenticatedConnectionInitiallyEstablishedTimestamp
protected long authenticatedConnectionInitiallyEstablishedTimestamp
-
wasAuthenticated
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).
-
-
Constructor Detail
-
AbstractXMPPConnection
protected AbstractXMPPConnection(ConnectionConfiguration configuration)
Create a new XMPPConnection to an XMPP server.- Parameters:
configuration
- The configuration which is used to establish the connection.
-
-
Method Detail
-
getConfiguration
public ConnectionConfiguration getConfiguration()
Get the connection configuration used by this connection.- Returns:
- the connection configuration.
-
getXMPPServiceDomain
public DomainBareJid getXMPPServiceDomain()
Description copied from interface:XMPPConnection
Returns the XMPP Domain of the service provided by the XMPP server and used for this connection. After authenticating with the server the returned value may be different.- Specified by:
getXMPPServiceDomain
in interfaceXMPPConnection
- Returns:
- the XMPP domain of this XMPP session.
-
getHost
public String getHost()
Description copied from interface:XMPPConnection
Returns the host name of the server where the XMPP server is running. This would be the IP address of the server or a name that may be resolved by a DNS server.- Specified by:
getHost
in interfaceXMPPConnection
- Returns:
- the host name of the server where the XMPP server is running or null if not yet connected.
-
getPort
public int getPort()
Description copied from interface:XMPPConnection
Returns the port number of the XMPP server for this connection. The default port for normal connections is 5222.- Specified by:
getPort
in interfaceXMPPConnection
- Returns:
- the port number of the XMPP server or 0 if not yet connected.
-
isSecureConnection
public abstract boolean isSecureConnection()
Description copied from interface:XMPPConnection
Returns true if the connection to the server has successfully negotiated encryption.- Specified by:
isSecureConnection
in interfaceXMPPConnection
- Returns:
- true if a secure connection to the server.
-
sendInternal
protected abstract void sendInternal(TopLevelStreamElement element) throws SmackException.NotConnectedException, InterruptedException
-
sendNonBlockingInternal
protected abstract void sendNonBlockingInternal(TopLevelStreamElement element) throws SmackException.NotConnectedException, SmackException.OutgoingQueueFullException
-
trySendStanza
public boolean trySendStanza(Stanza stanza) throws SmackException.NotConnectedException
Description copied from interface:XMPPConnection
Try to send the given stanza. Returnstrue
if the stanza was successfully put into the outgoing stanza queue, otherwise, iffalse
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 iftrue
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.- Specified by:
trySendStanza
in interfaceXMPPConnection
- Parameters:
stanza
- the stanza to send.- Returns:
true
if the stanza was successfully scheduled to be send,false
otherwise.- Throws:
SmackException.NotConnectedException
- if the connection is not connected.
-
trySendStanza
public boolean trySendStanza(Stanza stanza, long timeout, TimeUnit unit) throws SmackException.NotConnectedException, InterruptedException
Description copied from interface:XMPPConnection
Try to send the given stanza. Returnstrue
if the stanza was successfully put into the outgoing stanza queue within the given timeout period, otherwise, iffalse
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 iftrue
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.- Specified by:
trySendStanza
in interfaceXMPPConnection
- Parameters:
stanza
- the stanza to send.timeout
- how long to wait before giving up, in units ofunit
.unit
- aTimeUnit
determining how to interpret thetimeout
parameter.- Returns:
true
if the stanza was successfully scheduled to be send,false
otherwise.- Throws:
SmackException.NotConnectedException
- if the connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
sendNonza
public final void sendNonza(Nonza nonza) throws SmackException.NotConnectedException, InterruptedException
Description copied from interface:XMPPConnection
Send a Nonza.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.
- Specified by:
sendNonza
in interfaceXMPPConnection
- Parameters:
nonza
- the Nonza to send.- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
sendNonzaNonBlocking
public final void sendNonzaNonBlocking(Nonza nonza) throws SmackException.NotConnectedException, SmackException.OutgoingQueueFullException
- Specified by:
sendNonzaNonBlocking
in interfaceXMPPConnection
- Throws:
SmackException.NotConnectedException
SmackException.OutgoingQueueFullException
-
isUsingCompression
public abstract boolean isUsingCompression()
Description copied from interface:XMPPConnection
Returns true if network traffic is being compressed. When using stream compression network traffic can be reduced up to 90%. Therefore, stream compression is ideal when using a slow speed network connection. However, the server will need to use more CPU time in order to un/compress network data so under high load the server performance might be affected.- Specified by:
isUsingCompression
in interfaceXMPPConnection
- Returns:
- true if network traffic is being compressed.
-
initState
protected void initState()
-
connect
public AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException, InterruptedException
Establishes a connection to the XMPP server. It basically creates and maintains a connection to the server.Listeners will be preserved from a previous connection.
- Returns:
- a reference to this object, to chain
connect()
withlogin()
. - Throws:
XMPPException
- if an error occurs on the XMPP protocol level.SmackException
- if an error occurs somewhere else besides XMPP protocol level.IOException
- if an I/O error occurred.InterruptedException
- if the calling thread was interrupted.
-
connectInternal
protected abstract void connectInternal() throws SmackException, IOException, XMPPException, InterruptedException
Abstract method that concrete subclasses of XMPPConnection need to implement to perform their way of XMPP connection establishment. Implementations are required to perform an automatic login if the previous connection state was logged (authenticated).- Throws:
SmackException
- if Smack detected an exceptional situation.IOException
- if an I/O error occurred.XMPPException
- if an XMPP protocol error was received.InterruptedException
- if the calling thread was interrupted.
-
login
public void login() throws XMPPException, SmackException, IOException, InterruptedException
Logs in to the server using the strongest SASL mechanism supported by the server. If more than the connection's default stanza timeout elapses in each step of the authentication process without a response from the server, aSmackException.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 usingConnectionConfiguration.Builder.setCallbackHandler(javax.security.auth.callback.CallbackHandler)
. For more advanced login settings seeConnectionConfiguration
.- Throws:
XMPPException
- if an error occurs on the XMPP protocol level.SmackException
- if an error occurs somewhere else besides XMPP protocol level.IOException
- if an I/O error occurs during login.InterruptedException
- if the calling thread was interrupted.
-
login
public void login(CharSequence username, String password) throws XMPPException, SmackException, IOException, InterruptedException
Same aslogin(CharSequence, String, Resourcepart)
, but takes the resource from the connection configuration.- Parameters:
username
- TODO javadoc me pleasepassword
- TODO javadoc me please- Throws:
XMPPException
- if an XMPP protocol error was received.SmackException
- if Smack detected an exceptional situation.IOException
- if an I/O error occurred.InterruptedException
- if the calling thread was interrupted.- See Also:
login()
-
login
public void login(CharSequence username, String password, Resourcepart resource) throws XMPPException, SmackException, IOException, InterruptedException
Login with the given username (authorization identity). You may omit the password if a callback handler is used. If resource is null, then the server will generate one.- Parameters:
username
- TODO javadoc me pleasepassword
- TODO javadoc me pleaseresource
- TODO javadoc me please- Throws:
XMPPException
- if an XMPP protocol error was received.SmackException
- if Smack detected an exceptional situation.IOException
- if an I/O error occurred.InterruptedException
- if the calling thread was interrupted.- See Also:
login()
-
loginInternal
protected abstract void loginInternal(String username, String password, Resourcepart resource) throws XMPPException, SmackException, IOException, InterruptedException
-
isConnected
public final boolean isConnected()
Description copied from interface:XMPPConnection
Returns true if currently connected to the XMPP server.- Specified by:
isConnected
in interfaceXMPPConnection
- Returns:
- true if connected.
-
isAuthenticated
public final boolean isAuthenticated()
Description copied from interface:XMPPConnection
Returns true if currently authenticated by successfully calling the login method.- Specified by:
isAuthenticated
in interfaceXMPPConnection
- Returns:
- true if authenticated.
-
getUser
public final EntityFullJid getUser()
Description copied from interface:XMPPConnection
Returns the full XMPP address of the user that is logged in to the connection ornull
if not logged in yet. An XMPP address is in the form username@server/resource.- Specified by:
getUser
in interfaceXMPPConnection
- Returns:
- the full XMPP address of the user logged in.
-
getStreamId
public String getStreamId()
Description copied from interface:XMPPConnection
Returns the stream ID for this connection, which is the value set by the server when opening an XMPP stream. This value will benull
if not connected to the server.- Specified by:
getStreamId
in interfaceXMPPConnection
- Returns:
- the ID of this connection returned from the XMPP server or
null
if not connected to the server. - See Also:
- RFC 6120 § 4.7.3. id
-
throwCurrentConnectionException
protected final void throwCurrentConnectionException() throws SmackException, XMPPException
- Throws:
SmackException
XMPPException
-
hasCurrentConnectionException
protected final boolean hasCurrentConnectionException()
-
setCurrentConnectionExceptionAndNotify
protected final void setCurrentConnectionExceptionAndNotify(Exception exception)
-
notifyWaitingThreads
protected final void notifyWaitingThreads()
-
waitFor
protected final boolean waitFor(Supplier<Boolean> condition) throws InterruptedException
- Throws:
InterruptedException
-
waitForConditionOrThrowConnectionException
protected final void waitForConditionOrThrowConnectionException(Supplier<Boolean> condition, String waitFor) throws InterruptedException, SmackException, XMPPException
-
bindResourceAndEstablishSession
protected Resourcepart bindResourceAndEstablishSession(Resourcepart resource) throws SmackException, InterruptedException, XMPPException
-
afterSuccessfulLogin
protected void afterSuccessfulLogin(boolean resumed) throws SmackException.NotConnectedException, InterruptedException
-
isAnonymous
public final boolean isAnonymous()
Description copied from interface:XMPPConnection
Returns true if currently authenticated anonymously.- Specified by:
isAnonymous
in interfaceXMPPConnection
- Returns:
- true if authenticated anonymously.
-
getUsedSaslMechansism
public final String getUsedSaslMechansism()
Get the name of the SASL mechanism that was used to authenticate this connection. This returns the name of mechanism which was used the last time this connection was authenticated, and will returnnull
if this connection was not authenticated before.- Returns:
- the name of the used SASL mechanism.
- Since:
- 4.2
-
getConnectionLock
protected Lock getConnectionLock()
-
throwNotConnectedExceptionIfAppropriate
protected void throwNotConnectedExceptionIfAppropriate() throws SmackException.NotConnectedException
-
throwNotConnectedExceptionIfAppropriate
protected void throwNotConnectedExceptionIfAppropriate(String optionalHint) throws SmackException.NotConnectedException
-
throwAlreadyConnectedExceptionIfAppropriate
protected void throwAlreadyConnectedExceptionIfAppropriate() throws SmackException.AlreadyConnectedException
-
throwAlreadyLoggedInExceptionIfAppropriate
protected void throwAlreadyLoggedInExceptionIfAppropriate() throws SmackException.AlreadyLoggedInException
-
getStanzaFactory
public final StanzaFactory getStanzaFactory()
- Specified by:
getStanzaFactory
in interfaceXMPPConnection
-
sendStanza
public final void sendStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException
Description copied from interface:XMPPConnection
Sends the specified stanza to the server.- Specified by:
sendStanza
in interfaceXMPPConnection
- Parameters:
stanza
- the stanza to send.- Throws:
SmackException.NotConnectedException
- if the connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
sendStanzaNonBlocking
public final void sendStanzaNonBlocking(Stanza stanza) throws SmackException.NotConnectedException, SmackException.OutgoingQueueFullException
- Specified by:
sendStanzaNonBlocking
in interfaceXMPPConnection
- Throws:
SmackException.NotConnectedException
SmackException.OutgoingQueueFullException
-
authenticate
protected final SASLMechanism authenticate(String username, String password, EntityBareJid authzid, SSLSession sslSession) throws XMPPException.XMPPErrorException, SASLErrorException, SmackException.SmackSaslException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException, InterruptedException, SmackException.SmackWrappedException
Authenticate a connection.- Parameters:
username
- the username that is authenticating with the server.password
- the password to send to the server.authzid
- the authorization identifier (typically null).sslSession
- the optional SSL/TLS session (if one was established)- Returns:
- the used SASLMechanism.
- Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SASLErrorException
- if a SASL protocol error was returned.IOException
- if an I/O error occurred.InterruptedException
- if the calling thread was interrupted.SmackException.SmackSaslException
- if a SASL specific error occurred.SmackException.NotConnectedException
- if the XMPP connection is not connected.SmackException.NoResponseException
- if there was no response from the remote entity.SmackException.SmackWrappedException
- in case of an exception.- See Also:
SASLAuthentication.authenticate(String, String, EntityBareJid, SSLSession)
-
afterSaslAuthenticationSuccess
protected void afterSaslAuthenticationSuccess() throws SmackException.NotConnectedException, InterruptedException, SmackException.SmackWrappedException
Hook for subclasses right after successful SASL authentication. RFC 6120 § 6.4.6. specifies a that the initiating entity, needs to initiate a new stream in this case. But some transports, like BOSH, requires a special handling.Note that we can not reset XMPPTCPConnection's parser here, because this method is invoked by the thread calling
login()
, but the parser reset has to be done within the reader thread.- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.SmackException.SmackWrappedException
- in case of an exception.
-
isSaslAuthenticated
protected final boolean isSaslAuthenticated()
-
disconnect
public void disconnect()
Closes the connection by setting presence to unavailable then closing the connection to the XMPP server. The XMPPConnection can still be used for connecting to the server again.
-
disconnect
public void disconnect(Presence unavailablePresence) throws SmackException.NotConnectedException
Closes the connection. A custom unavailable presence is sent to the server, followed by closing the stream. The XMPPConnection can still be used for connecting to the server again. A custom unavailable presence is useful for communicating offline presence information such as "On vacation". Typically, just the status text of the presence stanza is set with online information, but most XMPP servers will deliver the full presence stanza with whatever data is set.- Parameters:
unavailablePresence
- the optional presence stanza to send during shutdown.- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.
-
notifyConnectionError
protected final void notifyConnectionError(Exception exception)
Sends out a notification that there was an error with the connection and closes the connection.- Parameters:
exception
- the exception that causes the connection close event.
-
instantShutdown
public abstract void instantShutdown()
Performs an unclean disconnect and shutdown of the connection. Does not send a closing stream stanza.
-
shutdown
protected abstract void shutdown()
Shuts the current connection down.
-
waitForClosingStreamTagFromServer
protected final boolean waitForClosingStreamTagFromServer()
-
addConnectionListener
public void addConnectionListener(ConnectionListener connectionListener)
Description copied from interface:XMPPConnection
Adds a connection listener to this connection that will be notified when the connection closes or fails.- Specified by:
addConnectionListener
in interfaceXMPPConnection
- Parameters:
connectionListener
- a connection listener.
-
removeConnectionListener
public void removeConnectionListener(ConnectionListener connectionListener)
Description copied from interface:XMPPConnection
Removes a connection listener from this connection.- Specified by:
removeConnectionListener
in interfaceXMPPConnection
- Parameters:
connectionListener
- a connection listener.
-
sendIqRequestAndWaitForResponse
public <I extends IQ> I sendIqRequestAndWaitForResponse(IQ request) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
Description copied from interface:XMPPConnection
Send an IQ request and wait for the response.- Specified by:
sendIqRequestAndWaitForResponse
in interfaceXMPPConnection
- Type Parameters:
I
- the type of the expected result IQ.- Parameters:
request
- the IQ request- Returns:
- an IQ with type 'result'
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
createStanzaCollectorAndSend
public StanzaCollector createStanzaCollectorAndSend(IQ packet) throws SmackException.NotConnectedException, InterruptedException
Description copied from interface:XMPPConnection
Creates a new stanza collector collecting IQ responses that are replies to the IQrequest
. Does also send therequest
IQ. The stanza filter for the collector is anIQReplyFilter
, guaranteeing that stanza id and JID in the 'from' address have expected values.- Specified by:
createStanzaCollectorAndSend
in interfaceXMPPConnection
- Parameters:
packet
- the IQ request to filter responses from- Returns:
- a new stanza collector.
- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
createStanzaCollectorAndSend
public StanzaCollector createStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet) throws SmackException.NotConnectedException, InterruptedException
Description copied from interface:XMPPConnection
Creates a new stanza collector for this connection. A stanza filter determines which stanzas will be accumulated by the collector. A StanzaCollector is more suitable to use than aStanzaListener
when you need to wait for a specific result.- Specified by:
createStanzaCollectorAndSend
in interfaceXMPPConnection
- Parameters:
packetFilter
- the stanza filter to use.packet
- the stanza to send right after the collector got created- Returns:
- a new stanza collector.
- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
createStanzaCollector
public StanzaCollector createStanzaCollector(StanzaFilter packetFilter)
Description copied from interface:XMPPConnection
Creates a new stanza collector for this connection. A stanza filter determines which stanzas will be accumulated by the collector. A StanzaCollector is more suitable to use than aStanzaListener
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.- Specified by:
createStanzaCollector
in interfaceXMPPConnection
- Parameters:
packetFilter
- the stanza filter to use.- Returns:
- a new stanza collector.
-
createStanzaCollector
public StanzaCollector createStanzaCollector(StanzaCollector.Configuration configuration)
Description copied from interface:XMPPConnection
Create a new stanza collector with the given stanza collector configuration.Please make sure to cancel the collector when it is no longer required. See also
XMPPConnection.createStanzaCollector(StanzaFilter)
.- Specified by:
createStanzaCollector
in interfaceXMPPConnection
- Parameters:
configuration
- the stanza collector configuration.- Returns:
- a new stanza collector.
-
removeStanzaCollector
public void removeStanzaCollector(StanzaCollector collector)
Description copied from interface:XMPPConnection
Remove a stanza collector of this connection.- Specified by:
removeStanzaCollector
in interfaceXMPPConnection
- Parameters:
collector
- a stanza collectors which was created for this connection.
-
addStanzaListener
public final void addStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter)
Description copied from interface:XMPPConnection
Registers a stanza listener with this connection. The listener will be invoked when a (matching) incoming stanza is received. The stanza filter determines which stanzas will be delivered to the listener. It is guaranteed that the same listener will not be invoked concurrently and the order of invocation will reflect the order in which the stanzas have been received. If the same stanza listener is added again with a different filter, only the new filter will be used.- Specified by:
addStanzaListener
in interfaceXMPPConnection
- Parameters:
stanzaListener
- the stanza listener to notify of new received stanzas.stanzaFilter
- the stanza filter to use.
-
removeStanzaListener
public final boolean removeStanzaListener(StanzaListener stanzaListener)
Description copied from interface:XMPPConnection
Removes a stanza listener for received stanzas from this connection.- Specified by:
removeStanzaListener
in interfaceXMPPConnection
- Parameters:
stanzaListener
- the stanza listener to remove.- Returns:
- true if the stanza listener was removed.
-
addSyncStanzaListener
public void addSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter)
Description copied from interface:XMPPConnection
Registers a synchronous stanza listener with this connection. A stanza listener will be invoked only when an incoming stanza is received. A stanza filter determines which stanzas will be delivered to the listener. If the same stanza listener is added again with a different filter, only the new filter will be used.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 aStanzaCollector
when possible.- Specified by:
addSyncStanzaListener
in interfaceXMPPConnection
- Parameters:
packetListener
- the stanza listener to notify of new received stanzas.packetFilter
- the stanza filter to use.- See Also:
XMPPConnection.addStanzaInterceptor(StanzaListener, StanzaFilter)
-
removeSyncStanzaListener
public boolean removeSyncStanzaListener(StanzaListener packetListener)
Description copied from interface:XMPPConnection
Removes a stanza listener for received stanzas from this connection.- Specified by:
removeSyncStanzaListener
in interfaceXMPPConnection
- Parameters:
packetListener
- the stanza listener to remove.- Returns:
- true if the stanza listener was removed
-
addAsyncStanzaListener
public void addAsyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter)
Description copied from interface:XMPPConnection
Registers an asynchronous stanza listener with this connection. A stanza listener will be invoked only when an incoming stanza is received. A stanza filter determines which stanzas will be delivered to the listener. If the same stanza listener is added again with a different filter, only the new filter will be used.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.- Specified by:
addAsyncStanzaListener
in interfaceXMPPConnection
- Parameters:
packetListener
- the stanza listener to notify of new received stanzas.packetFilter
- the stanza filter to use.- See Also:
XMPPConnection.addStanzaInterceptor(StanzaListener, StanzaFilter)
-
removeAsyncStanzaListener
public boolean removeAsyncStanzaListener(StanzaListener packetListener)
Description copied from interface:XMPPConnection
Removes an asynchronous stanza listener for received stanzas from this connection.- Specified by:
removeAsyncStanzaListener
in interfaceXMPPConnection
- Parameters:
packetListener
- the stanza listener to remove.- Returns:
- true if the stanza listener was removed
-
addStanzaSendingListener
public void addStanzaSendingListener(StanzaListener packetListener, StanzaFilter packetFilter)
Description copied from interface:XMPPConnection
Registers a stanza listener with this connection. The listener will be notified of every stanza that this connection sends. A stanza filter determines which stanzas will be delivered to the listener. Note that the thread that writes stanzas will be used to invoke the listeners. Therefore, each stanza listener should complete all operations quickly or use a different thread for processing.- Specified by:
addStanzaSendingListener
in interfaceXMPPConnection
- Parameters:
packetListener
- the stanza listener to notify of sent stanzas.packetFilter
- the stanza filter to use.
-
removeStanzaSendingListener
public void removeStanzaSendingListener(StanzaListener packetListener)
Description copied from interface:XMPPConnection
Removes a stanza listener for sending stanzas from this connection.- Specified by:
removeStanzaSendingListener
in interfaceXMPPConnection
- Parameters:
packetListener
- the stanza listener to remove.
-
firePacketSendingListeners
protected void firePacketSendingListeners(TopLevelStreamElement sendTopLevelStreamElement)
Process all stanza listeners for sending stanzas.Compared to
firePacketInterceptors(Stanza)
, the listeners will be invoked in a new thread.- Parameters:
sendTopLevelStreamElement
- the top level stream element which just got send.
-
addStanzaInterceptor
@Deprecated public void addStanzaInterceptor(StanzaListener packetInterceptor, StanzaFilter packetFilter)
Deprecated.Description copied from interface:XMPPConnection
Registers a stanza interceptor with this connection. The interceptor will be invoked every time a stanza is about to be sent by this connection. Interceptors may modify the stanza to be sent. A stanza filter determines which stanzas will be delivered to the interceptor.NOTE: For a similar functionality on incoming stanzas, see
XMPPConnection.addAsyncStanzaListener(StanzaListener, StanzaFilter)
.- Specified by:
addStanzaInterceptor
in interfaceXMPPConnection
- Parameters:
packetInterceptor
- the stanza interceptor to notify of stanzas about to be sent.packetFilter
- the stanza filter to use.
-
removeStanzaInterceptor
@Deprecated public void removeStanzaInterceptor(StanzaListener packetInterceptor)
Deprecated.Description copied from interface:XMPPConnection
Removes a stanza interceptor.- Specified by:
removeStanzaInterceptor
in interfaceXMPPConnection
- Parameters:
packetInterceptor
- the stanza interceptor to remove.
-
addMessageInterceptor
public void addMessageInterceptor(Consumer<MessageBuilder> messageInterceptor, Predicate<Message> messageFilter)
Description copied from interface:XMPPConnection
Registers a stanza interceptor with this connection. The interceptor will be invoked every time a stanza is about to be sent by this connection. Interceptors may modify the stanza to be sent. A stanza filter determines which stanzas will be delivered to the interceptor.NOTE: For a similar functionality on incoming stanzas, see
XMPPConnection.addAsyncStanzaListener(StanzaListener, StanzaFilter)
.- Specified by:
addMessageInterceptor
in interfaceXMPPConnection
- Parameters:
messageInterceptor
- the stanza interceptor to notify of stanzas about to be sent.messageFilter
- the stanza filter to use.
-
removeMessageInterceptor
public void removeMessageInterceptor(Consumer<MessageBuilder> messageInterceptor)
Description copied from interface:XMPPConnection
Removes a message interceptor.- Specified by:
removeMessageInterceptor
in interfaceXMPPConnection
- Parameters:
messageInterceptor
- the message interceptor to remove.
-
addPresenceInterceptor
public void addPresenceInterceptor(Consumer<PresenceBuilder> presenceInterceptor, Predicate<Presence> presenceFilter)
Description copied from interface:XMPPConnection
Registers a stanza interceptor with this connection. The interceptor will be invoked every time a stanza is about to be sent by this connection. Interceptors may modify the stanza to be sent. A stanza filter determines which stanzas will be delivered to the interceptor.NOTE: For a similar functionality on incoming stanzas, see
XMPPConnection.addAsyncStanzaListener(StanzaListener, StanzaFilter)
.- Specified by:
addPresenceInterceptor
in interfaceXMPPConnection
- Parameters:
presenceInterceptor
- the stanza interceptor to notify of stanzas about to be sent.presenceFilter
- the stanza filter to use.
-
removePresenceInterceptor
public void removePresenceInterceptor(Consumer<PresenceBuilder> presenceInterceptor)
Description copied from interface:XMPPConnection
Removes a presence interceptor.- Specified by:
removePresenceInterceptor
in interfaceXMPPConnection
- Parameters:
presenceInterceptor
- the stanza interceptor to remove.
-
initDebugger
protected void initDebugger()
Initialize thedebugger
. You can specify a customizedSmackDebugger
by setup the system propertysmack.debuggerClass
to the implementation.- Throws:
IllegalStateException
- if the reader or writer isn't yet initialized.IllegalArgumentException
- if the SmackDebugger can't be loaded.
-
getReplyTimeout
public long getReplyTimeout()
Description copied from interface:XMPPConnection
Returns the current value of the reply timeout in milliseconds for request for this XMPPConnection instance.- Specified by:
getReplyTimeout
in interfaceXMPPConnection
- Returns:
- the reply timeout in milliseconds
-
setReplyTimeout
public void setReplyTimeout(long timeout)
Description copied from interface:XMPPConnection
Set the stanza reply timeout in milliseconds. In most cases, Smack will throw aSmackException.NoResponseException
if no reply to a request was received within the timeout period.- Specified by:
setReplyTimeout
in interfaceXMPPConnection
- Parameters:
timeout
- for a reply in milliseconds
-
setUnknownIqRequestReplyMode
public void setUnknownIqRequestReplyMode(SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode)
Set how Smack behaves when an unknown IQ request has been received.- Parameters:
unknownIqRequestReplyMode
- reply mode.
-
buildNonzaCallback
protected final NonzaCallback.Builder buildNonzaCallback()
-
sendAndWaitForResponse
protected <SN extends Nonza,FN extends Nonza> SN sendAndWaitForResponse(Nonza nonza, Class<SN> successNonzaClass, Class<FN> failedNonzaClass) throws SmackException.NoResponseException, SmackException.NotConnectedException, InterruptedException, XMPPException.FailedNonzaException
-
parseAndProcessNonza
protected final void parseAndProcessNonza(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException
-
parseAndProcessStanza
protected void parseAndProcessStanza(XmlPullParser parser) throws XmlPullParserException, IOException, InterruptedException
-
processStanza
protected void processStanza(Stanza stanza) throws InterruptedException
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.- Parameters:
stanza
- the stanza to process.- Throws:
InterruptedException
- if the calling thread was interrupted.
-
invokeStanzaCollectorsAndNotifyRecvListeners
protected void invokeStanzaCollectorsAndNotifyRecvListeners(Stanza packet)
InvokeStanzaCollector.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.
- Parameters:
packet
- the stanza to notify the StanzaCollectors and receive listeners about.
-
setWasAuthenticated
protected void setWasAuthenticated()
Sets whether the connection has already logged in the server. This method assures that thewasAuthenticated
flag is never reset once it has ever been set.
-
callConnectionConnectingListener
protected void callConnectionConnectingListener()
-
callConnectionConnectedListener
protected void callConnectionConnectedListener()
-
callConnectionAuthenticatedListener
protected void callConnectionAuthenticatedListener(boolean resumed)
-
getConnectionCounter
public int getConnectionCounter()
Description copied from interface:XMPPConnection
Get the connection counter of this XMPPConnection instance. Those can be used as ID to identify the connection, but beware that the ID may not be unique if you create more then2*Integer.MAX_VALUE
instances as the counter could wrap.- Specified by:
getConnectionCounter
in interfaceXMPPConnection
- Returns:
- the connection counter of this XMPPConnection
-
setFromMode
public void setFromMode(XMPPConnection.FromMode fromMode)
Description copied from interface:XMPPConnection
Set the FromMode for this connection instance. Defines how the 'from' attribute of outgoing stanzas should be populated by Smack.- Specified by:
setFromMode
in interfaceXMPPConnection
- Parameters:
fromMode
- TODO javadoc me please
-
getFromMode
public XMPPConnection.FromMode getFromMode()
Description copied from interface:XMPPConnection
Get the currently active FromMode.- Specified by:
getFromMode
in interfaceXMPPConnection
- Returns:
- the currently active
XMPPConnection.FromMode
-
parseFeatures
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException
-
parseFeaturesAndNotify
protected final void parseFeaturesAndNotify(XmlPullParser parser) throws Exception
- Throws:
Exception
-
afterFeaturesReceived
protected void afterFeaturesReceived() throws SmackException.SecurityRequiredException, SmackException.NotConnectedException, InterruptedException
-
getFeature
public <F extends XmlElement> F getFeature(QName qname)
Description copied from interface:XMPPConnection
Get the feature stanza extensions for a given stream feature of the server, ornull
if the server doesn't support that feature.- Specified by:
getFeature
in interfaceXMPPConnection
- Type Parameters:
F
-ExtensionElement
type of the feature.- Parameters:
qname
- the qualified name of the XML element of feature.- Returns:
- a stanza extensions of the feature or
null
-
hasFeature
public boolean hasFeature(QName qname)
Description copied from interface:XMPPConnection
Return true if the server supports the given stream feature.- Specified by:
hasFeature
in interfaceXMPPConnection
- Parameters:
qname
- the qualified name of the XML element of feature.- Returns:
- true if the server supports the stream feature.
-
addStreamFeature
protected void addStreamFeature(XmlElement feature)
-
sendIqRequestAsync
public SmackFuture<IQ,Exception> sendIqRequestAsync(IQ request)
Description copied from interface:XMPPConnection
Send an IQ request asynchronously. The connection's default reply timeout will be used.- Specified by:
sendIqRequestAsync
in interfaceXMPPConnection
- Parameters:
request
- the IQ request to send.- Returns:
- a SmackFuture for the response.
-
sendIqRequestAsync
public SmackFuture<IQ,Exception> sendIqRequestAsync(IQ request, long timeout)
Description copied from interface:XMPPConnection
Send an IQ request asynchronously.- Specified by:
sendIqRequestAsync
in interfaceXMPPConnection
- Parameters:
request
- the IQ request to send.timeout
- the reply timeout in milliseconds.- Returns:
- a SmackFuture for the response.
-
sendAsync
public <S extends Stanza> SmackFuture<S,Exception> sendAsync(S stanza, StanzaFilter replyFilter)
Description copied from interface:XMPPConnection
Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter. The connection's default reply timeout will be used.- Specified by:
sendAsync
in interfaceXMPPConnection
- Type Parameters:
S
- the type of the stanza to send.- Parameters:
stanza
- the stanza to send.replyFilter
- the filter used for the response stanza.- Returns:
- a SmackFuture for the response.
-
sendAsync
public <S extends Stanza> SmackFuture<S,Exception> sendAsync(S stanza, StanzaFilter replyFilter, long timeout)
Description copied from interface:XMPPConnection
Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter.- Specified by:
sendAsync
in interfaceXMPPConnection
- Type Parameters:
S
- the type of the stanza to send.- Parameters:
stanza
- the stanza to send.replyFilter
- the filter used for the response stanza.timeout
- the reply timeout in milliseconds.- Returns:
- a SmackFuture for the response.
-
addOneTimeSyncCallback
public void addOneTimeSyncCallback(StanzaListener callback, StanzaFilter packetFilter)
Description copied from interface:XMPPConnection
Add a callback that is called exactly once and synchronously with the incoming stanza that matches the given stanza filter.- Specified by:
addOneTimeSyncCallback
in interfaceXMPPConnection
- Parameters:
callback
- the callback invoked once the stanza filter matches a stanza.packetFilter
- the filter to match stanzas or null to match all.
-
registerIQRequestHandler
public IQRequestHandler registerIQRequestHandler(IQRequestHandler iqRequestHandler)
Description copied from interface:XMPPConnection
Register an IQ request handler with this connection.IQ request handler process incoming IQ requests, i.e. incoming IQ stanzas of type 'get' or 'set', and return a result.
- Specified by:
registerIQRequestHandler
in interfaceXMPPConnection
- Parameters:
iqRequestHandler
- the IQ request handler to register.- Returns:
- the previously registered IQ request handler or null.
-
unregisterIQRequestHandler
public final IQRequestHandler unregisterIQRequestHandler(IQRequestHandler iqRequestHandler)
Description copied from interface:XMPPConnection
Convenience method forXMPPConnection.unregisterIQRequestHandler(String, String, org.jivesoftware.smack.packet.IQ.Type)
.- Specified by:
unregisterIQRequestHandler
in interfaceXMPPConnection
- Parameters:
iqRequestHandler
- TODO javadoc me please- Returns:
- the previously registered IQ request handler or null.
-
unregisterIQRequestHandler
public IQRequestHandler unregisterIQRequestHandler(String element, String namespace, IQ.Type type)
Description copied from interface:XMPPConnection
Unregister an IQ request handler with this connection.- Specified by:
unregisterIQRequestHandler
in interfaceXMPPConnection
- Parameters:
element
- 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.- Returns:
- the previously registered IQ request handler or null.
-
getLastStanzaReceived
public long getLastStanzaReceived()
Description copied from interface:XMPPConnection
Returns the timestamp in milliseconds when the last stanza was received.- Specified by:
getLastStanzaReceived
in interfaceXMPPConnection
- Returns:
- the timestamp in milliseconds
-
getAuthenticatedConnectionInitiallyEstablishedTimestamp
public final long getAuthenticatedConnectionInitiallyEstablishedTimestamp()
Get the timestamp when the connection was the first time authenticated, i.e., when the first successful login was performed. Note that this value is not reset on disconnect, so it represents the timestamp from the last authenticated connection. The value is also not reset on stream resumption.- Returns:
- the timestamp or
null
. - Since:
- 4.3.3
-
setParsingExceptionCallback
public void setParsingExceptionCallback(ParsingExceptionCallback callback)
Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a stanza.- Parameters:
callback
- the callback to install
-
getParsingExceptionCallback
public ParsingExceptionCallback getParsingExceptionCallback()
Get the current active parsing exception callback.- Returns:
- the active exception callback or null if there is none
-
asyncGoLimited
protected void asyncGoLimited(Runnable runnable)
-
setMaxAsyncOperations
public void setMaxAsyncOperations(int maxAsyncOperations)
-
getReactor
protected final SmackReactor getReactor()
-
schedule
protected static ScheduledAction schedule(Runnable runnable, long delay, TimeUnit unit)
-
onStreamOpen
protected String onStreamOpen(XmlPullParser parser)
Must be called when a XMPP stream open tag is encountered. Sets values like the stream ID and the incoming stream XML environment.This method also returns a matching stream close tag. For example if the stream open is
<stream …>
, then</stream>
is returned. But if it is<stream:stream>
, then</stream:stream>
is returned. Or if it is<foo:stream>
, then</foo:stream>
is returned.- Parameters:
parser
- an XML parser that is positioned at the start of the stream open.- Returns:
- a String representing the corresponding stream end tag.
-
sendStreamOpen
protected final void sendStreamOpen() throws SmackException.NotConnectedException, InterruptedException
-
getStreamOpen
protected AbstractStreamOpen getStreamOpen(DomainBareJid to, CharSequence from, String id, String lang)
-
updateOutgoingStreamXmlEnvironmentOnStreamOpen
protected void updateOutgoingStreamXmlEnvironmentOnStreamOpen(AbstractStreamOpen streamOpen)
-
getSmackTlsContext
protected final SmackTlsContext getSmackTlsContext()
-
-