Class AbstractXMPPConnection
- java.lang.Object
-
- org.jivesoftware.smack.AbstractXMPPConnection
-
- All Implemented Interfaces:
XMPPConnection
- Direct Known Subclasses:
ModularXmppClientToServerConnection,XMPPBOSHConnection,XMPPTCPConnection
public abstract class AbstractXMPPConnection extends java.lang.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 theXMPPConnectioninterface).Note: The default entry point to Smack's documentation is
XMPPConnection. If you are getting started with Smack, then head over toXMPPConnectionand 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
ExceptionThrowingCallbackWithHintas 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 classAbstractXMPPConnection.InterceptorWrapperDeprecated.protected static classAbstractXMPPConnection.ListenerWrapperA wrapper class to associate a stanza filter with a listener.protected static classAbstractXMPPConnection.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_ORDEREDprotected booleanauthenticatedFlag that indicates if the user is currently authenticated with the server.protected longauthenticatedConnectionInitiallyEstablishedTimestampprotected booleanclosingStreamReceivedA synchronization point which is successful if this connection has received the closing stream element from the remote end-point, i.e.protected XMPPInputOutputStreamcompressionHandlerprotected ConnectionConfigurationconfigHolds the initial configuration used while creating the connection.protected booleanconnectedprotected intconnectionCounterValueA number to uniquely identify connections that are created.protected java.util.Set<ConnectionListener>connectionListenersA collection of ConnectionListeners which listen for connection closing and reconnection events.protected java.util.concurrent.locks.LockconnectionLockprotected SmackExceptioncurrentSmackExceptionprotected XMPPExceptioncurrentXmppExceptionprotected SmackDebuggerdebuggerThe SmackDebugger allows to log and debug XML traffic.protected java.lang.StringhostThe used host to establish the connection toprotected booleanlastFeaturesReceivedSet totrueif the last features stanza from the server has been parsed.protected XmlEnvironmentoutgoingStreamXmlEnvironmentprotected UInt16portThe used port to establish the connection toprotected java.io.ReaderreaderThe Reader which is used for the debugger.protected booleansaslFeatureReceivedSet totrueif the SASL feature has been received.protected static SmackReactorSMACK_REACTORprotected java.util.Map<javax.xml.namespace.QName,FullyQualifiedElement>streamFeaturesprotected java.lang.StringstreamIdThe stream ID, see RFC 6120 ยง 4.7.3protected booleantlsHandledprotected EntityFullJiduserThe full JID of the authenticated user, as returned by the resource binding response of the server.protected booleanwasAuthenticatedFlag that indicates if the user was authenticated with the server when the connection to the server was closed (abruptly or not).protected java.io.WriterwriterThe Writer which is used for the debugger.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractXMPPConnection(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 voidaddAsyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter)Registers an asynchronous stanza listener with this connection.voidaddConnectionListener(ConnectionListener connectionListener)Adds a connection listener to this connection that will be notified when the connection closes or fails.voidaddMessageInterceptor(Consumer<MessageBuilder> messageInterceptor, Predicate<Message> messageFilter)Registers a stanza interceptor with this connection.voidaddOneTimeSyncCallback(StanzaListener callback, StanzaFilter packetFilter)Add a callback that is called exactly once and synchronously with the incoming stanza that matches the given stanza filter.voidaddPresenceInterceptor(Consumer<PresenceBuilder> presenceInterceptor, Predicate<Presence> presenceFilter)Registers a stanza interceptor with this connection.voidaddStanzaInterceptor(StanzaListener packetInterceptor, StanzaFilter packetFilter)Deprecated.voidaddStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter)Registers a stanza listener with this connection.voidaddStanzaSendingListener(StanzaListener packetListener, StanzaFilter packetFilter)Registers a stanza listener with this connection.protected voidaddStreamFeature(FullyQualifiedElement feature)voidaddSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter)Registers a synchronous stanza listener with this connection.protected voidafterFeaturesReceived()protected voidafterSaslAuthenticationSuccess()Hook for subclasses right after successful SASL authentication.protected voidafterSuccessfulLogin(boolean resumed)protected static voidasyncGo(java.lang.Runnable runnable)protected voidasyncGoLimited(java.lang.Runnable runnable)protected SASLMechanismauthenticate(java.lang.String username, java.lang.String password, EntityBareJid authzid, javax.net.ssl.SSLSession sslSession)Authenticate a connection.protected ResourcepartbindResourceAndEstablishSession(Resourcepart resource)protected NonzaCallback.BuilderbuildNonzaCallback()protected voidcallConnectionAuthenticatedListener(boolean resumed)protected voidcallConnectionConnectedListener()protected voidcallConnectionConnectingListener()AbstractXMPPConnectionconnect()Establishes a connection to the XMPP server.protected abstract voidconnectInternal()Abstract method that concrete subclasses of XMPPConnection need to implement to perform their way of XMPP connection establishment.StanzaCollectorcreateStanzaCollector(StanzaFilter packetFilter)Creates a new stanza collector for this connection.StanzaCollectorcreateStanzaCollector(StanzaCollector.Configuration configuration)Create a new stanza collector with the given stanza collector configuration.StanzaCollectorcreateStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet)Creates a new stanza collector for this connection.StanzaCollectorcreateStanzaCollectorAndSend(IQ packet)Creates a new stanza collector collecting IQ responses that are replies to the IQrequest.voiddisconnect()Closes the connection by setting presence to unavailable then closing the connection to the XMPP server.voiddisconnect(Presence unavailablePresence)Closes the connection.protected voidfirePacketSendingListeners(TopLevelStreamElement sendTopLevelStreamElement)Process all stanza listeners for sending stanzas.longgetAuthenticatedConnectionInitiallyEstablishedTimestamp()Get the timestamp when the connection was the first time authenticated, i.e., when the first successful login was performed.ConnectionConfigurationgetConfiguration()Get the connection configuration used by this connection.intgetConnectionCounter()Get the connection counter of this XMPPConnection instance.protected java.util.concurrent.locks.LockgetConnectionLock()<F extends FullyQualifiedElement>
FgetFeature(javax.xml.namespace.QName qname)Get the feature stanza extensions for a given stream feature of the server, ornullif the server doesn't support that feature.XMPPConnection.FromModegetFromMode()Get the currently active FromMode.java.lang.StringgetHost()Returns the host name of the server where the XMPP server is running.longgetLastStanzaReceived()Returns the timestamp in milliseconds when the last stanza was received.ParsingExceptionCallbackgetParsingExceptionCallback()Get the current active parsing exception callback.intgetPort()Returns the port number of the XMPP server for this connection.protected SmackReactorgetReactor()longgetReplyTimeout()Returns the current value of the reply timeout in milliseconds for request for this XMPPConnection instance.protected SmackTlsContextgetSmackTlsContext()StanzaFactorygetStanzaFactory()java.lang.StringgetStreamId()Returns the stream ID for this connection, which is the value set by the server when opening an XMPP stream.java.lang.StringgetUsedSaslMechansism()Get the name of the SASL mechanism that was used to authenticate this connection.EntityFullJidgetUser()Returns the full XMPP address of the user that is logged in to the connection ornullif not logged in yet.DomainBareJidgetXMPPServiceDomain()Returns the XMPP Domain of the service provided by the XMPP server and used for this connection.protected booleanhasCurrentConnectionException()booleanhasFeature(javax.xml.namespace.QName qname)Return true if the server supports the given stream feature.protected voidinitDebugger()Initialize thedebugger.protected voidinitState()abstract voidinstantShutdown()Performs an unclean disconnect and shutdown of the connection.protected voidinvokeStanzaCollectorsAndNotifyRecvListeners(Stanza packet)InvokeStanzaCollector.processStanza(Stanza)for every StanzaCollector with the given packet.booleanisAnonymous()Returns true if currently authenticated anonymously.booleanisAuthenticated()Returns true if currently authenticated by successfully calling the login method.booleanisConnected()Returns true if currently connected to the XMPP server.protected booleanisSaslAuthenticated()abstract booleanisSecureConnection()Returns true if the connection to the server has successfully negotiated encryption.abstract booleanisUsingCompression()Returns true if network traffic is being compressed.voidlogin()Logs in to the server using the strongest SASL mechanism supported by the server.voidlogin(java.lang.CharSequence username, java.lang.String password)Same aslogin(CharSequence, String, Resourcepart), but takes the resource from the connection configuration.voidlogin(java.lang.CharSequence username, java.lang.String password, Resourcepart resource)Login with the given username (authorization identity).protected abstract voidloginInternal(java.lang.String username, java.lang.String password, Resourcepart resource)protected voidnotifyConnectionError(java.lang.Exception exception)Sends out a notification that there was an error with the connection and closes the connection.protected voidnotifyWaitingThreads()protected voidonStreamOpen(XmlPullParser parser)protected voidparseAndProcessNonza(XmlPullParser parser)protected voidparseAndProcessStanza(XmlPullParser parser)protected voidparseFeatures(XmlPullParser parser)protected voidparseFeaturesAndNotify(XmlPullParser parser)protected voidprocessStanza(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.IQRequestHandlerregisterIQRequestHandler(IQRequestHandler iqRequestHandler)Register an IQ request handler with this connection.booleanremoveAsyncStanzaListener(StanzaListener packetListener)Removes an asynchronous stanza listener for received stanzas from this connection.voidremoveConnectionListener(ConnectionListener connectionListener)Removes a connection listener from this connection.voidremoveMessageInterceptor(Consumer<MessageBuilder> messageInterceptor)Removes a message interceptor.voidremovePresenceInterceptor(Consumer<PresenceBuilder> presenceInterceptor)Removes a presence interceptor.voidremoveStanzaCollector(StanzaCollector collector)Remove a stanza collector of this connection.voidremoveStanzaInterceptor(StanzaListener packetInterceptor)Deprecated.booleanremoveStanzaListener(StanzaListener stanzaListener)Removes a stanza listener for received stanzas from this connection.voidremoveStanzaSendingListener(StanzaListener packetListener)Removes a stanza listener for sending stanzas from this connection.booleanremoveSyncStanzaListener(StanzaListener packetListener)Removes a stanza listener for received stanzas from this connection.protected static ScheduledActionschedule(java.lang.Runnable runnable, long delay, java.util.concurrent.TimeUnit unit)protected <SN extends Nonza,FN extends Nonza>
SNsendAndWaitForResponse(Nonza nonza, java.lang.Class<SN> successNonzaClass, java.lang.Class<FN> failedNonzaClass)<S extends Stanza>
SmackFuture<S,java.lang.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,java.lang.Exception>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>
IsendIqRequestAndWaitForResponse(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 voidsendNonza(Nonza element)Send a Nonza.voidsendStanza(Stanza stanza)Sends the specified stanza to the server.protected abstract voidsendStanzaInternal(Stanza packet)protected voidsendStreamOpen()protected voidsetCurrentConnectionExceptionAndNotify(java.lang.Exception exception)voidsetFromMode(XMPPConnection.FromMode fromMode)Set the FromMode for this connection instance.voidsetMaxAsyncOperations(int maxAsyncOperations)voidsetParsingExceptionCallback(ParsingExceptionCallback callback)Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a stanza.voidsetReplyTimeout(long timeout)Set the stanza reply timeout in milliseconds.voidsetUnknownIqRequestReplyMode(SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode)Set how Smack behaves when an unknown IQ request has been received.protected voidsetWasAuthenticated()Sets whether the connection has already logged in the server.protected abstract voidshutdown()Shuts the current connection down.protected voidthrowAlreadyConnectedExceptionIfAppropriate()protected voidthrowAlreadyLoggedInExceptionIfAppropriate()protected voidthrowCurrentConnectionException()protected voidthrowNotConnectedExceptionIfAppropriate()protected voidthrowNotConnectedExceptionIfAppropriate(java.lang.String optionalHint)java.lang.StringtoString()booleantrySendStanza(Stanza stanza)Try to send the given stanza.booleantrySendStanza(Stanza stanza, long timeout, java.util.concurrent.TimeUnit unit)Try to send the given stanza.IQRequestHandlerunregisterIQRequestHandler(java.lang.String element, java.lang.String namespace, IQ.Type type)Unregister an IQ request handler with this connection.IQRequestHandlerunregisterIQRequestHandler(IQRequestHandler iqRequestHandler)Convenience method forXMPPConnection.unregisterIQRequestHandler(String, String, org.jivesoftware.smack.packet.IQ.Type).protected booleanwaitFor(Supplier<java.lang.Boolean> condition)protected booleanwaitForClosingStreamTagFromServer()protected voidwaitForConditionOrThrowConnectionException(Supplier<java.lang.Boolean> condition, java.lang.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, hasFeature
-
-
-
-
Field Detail
-
SMACK_REACTOR
protected static final SmackReactor SMACK_REACTOR
-
connectionListeners
protected final java.util.Set<ConnectionListener> connectionListeners
A collection of ConnectionListeners which listen for connection closing and reconnection events.
-
outgoingStreamXmlEnvironment
protected XmlEnvironment outgoingStreamXmlEnvironment
-
connectionLock
protected final java.util.concurrent.locks.Lock connectionLock
-
streamFeatures
protected final java.util.Map<javax.xml.namespace.QName,FullyQualifiedElement> 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
-
streamId
protected java.lang.String streamId
The stream ID, see RFC 6120 ยง 4.7.3
-
debugger
protected final SmackDebugger debugger
The SmackDebugger allows to log and debug XML traffic.
-
reader
protected java.io.Reader reader
The Reader which is used for the debugger.
-
writer
protected java.io.Writer writer
The Writer which is used for the debugger.
-
currentSmackException
protected SmackException currentSmackException
-
currentXmppException
protected XMPPException currentXmppException
-
tlsHandled
protected boolean tlsHandled
-
lastFeaturesReceived
protected boolean lastFeaturesReceived
Set totrueif 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 totrueif 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
-
host
protected java.lang.String host
The used host to establish the connection to
-
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:XMPPConnectionReturns 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:
getXMPPServiceDomainin interfaceXMPPConnection- Returns:
- the XMPP domain of this XMPP session.
-
getHost
public java.lang.String getHost()
Description copied from interface:XMPPConnectionReturns 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:
getHostin 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:XMPPConnectionReturns the port number of the XMPP server for this connection. The default port for normal connections is 5222.- Specified by:
getPortin interfaceXMPPConnection- Returns:
- the port number of the XMPP server or 0 if not yet connected.
-
isSecureConnection
public abstract boolean isSecureConnection()
Description copied from interface:XMPPConnectionReturns true if the connection to the server has successfully negotiated encryption.- Specified by:
isSecureConnectionin interfaceXMPPConnection- Returns:
- true if a secure connection to the server.
-
sendStanzaInternal
protected abstract void sendStanzaInternal(Stanza packet) throws SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.NotConnectedExceptionjava.lang.InterruptedException
-
trySendStanza
public boolean trySendStanza(Stanza stanza) throws SmackException.NotConnectedException
Description copied from interface:XMPPConnectionTry to send the given stanza. Returnstrueif the stanza was successfully put into the outgoing stanza queue, otherwise, iffalseis 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 iftrueis 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:
trySendStanzain interfaceXMPPConnection- Parameters:
stanza- the stanza to send.- Returns:
trueif the stanza was successfully scheduled to be send,falseotherwise.- Throws:
SmackException.NotConnectedException- if the connection is not connected.
-
trySendStanza
public boolean trySendStanza(Stanza stanza, long timeout, java.util.concurrent.TimeUnit unit) throws SmackException.NotConnectedException, java.lang.InterruptedException
Description copied from interface:XMPPConnectionTry to send the given stanza. Returnstrueif the stanza was successfully put into the outgoing stanza queue within the given timeout period, otherwise, iffalseis 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 iftrueis 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:
trySendStanzain interfaceXMPPConnection- Parameters:
stanza- the stanza to send.timeout- how long to wait before giving up, in units ofunit.unit- aTimeUnitdetermining how to interpret thetimeoutparameter.- Returns:
trueif the stanza was successfully scheduled to be send,falseotherwise.- Throws:
SmackException.NotConnectedException- if the connection is not connected.java.lang.InterruptedException- if the calling thread was interrupted.
-
sendNonza
public abstract void sendNonza(Nonza element) throws SmackException.NotConnectedException, java.lang.InterruptedException
Description copied from interface:XMPPConnectionSend 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:
sendNonzain interfaceXMPPConnection- Parameters:
element- the Nonza to send.- Throws:
SmackException.NotConnectedException- if the XMPP connection is not connected.java.lang.InterruptedException- if the calling thread was interrupted.
-
isUsingCompression
public abstract boolean isUsingCompression()
Description copied from interface:XMPPConnectionReturns 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:
isUsingCompressionin interfaceXMPPConnection- Returns:
- true if network traffic is being compressed.
-
initState
protected void initState()
-
connect
public AbstractXMPPConnection connect() throws SmackException, java.io.IOException, XMPPException, java.lang.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.java.io.IOException- if an I/O error occurred.java.lang.InterruptedException- if the calling thread was interrupted.
-
connectInternal
protected abstract void connectInternal() throws SmackException, java.io.IOException, XMPPException, java.lang.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.java.io.IOException- if an I/O error occurred.XMPPException- if an XMPP protocol error was received.java.lang.InterruptedException- if the calling thread was interrupted.
-
login
public void login() throws XMPPException, SmackException, java.io.IOException, java.lang.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.NoResponseExceptionwill 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.java.io.IOException- if an I/O error occurs during login.java.lang.InterruptedException- if the calling thread was interrupted.
-
login
public void login(java.lang.CharSequence username, java.lang.String password) throws XMPPException, SmackException, java.io.IOException, java.lang.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.java.io.IOException- if an I/O error occurred.java.lang.InterruptedException- if the calling thread was interrupted.- See Also:
login()
-
login
public void login(java.lang.CharSequence username, java.lang.String password, Resourcepart resource) throws XMPPException, SmackException, java.io.IOException, java.lang.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.java.io.IOException- if an I/O error occurred.java.lang.InterruptedException- if the calling thread was interrupted.- See Also:
login()
-
loginInternal
protected abstract void loginInternal(java.lang.String username, java.lang.String password, Resourcepart resource) throws XMPPException, SmackException, java.io.IOException, java.lang.InterruptedException
- Throws:
XMPPExceptionSmackExceptionjava.io.IOExceptionjava.lang.InterruptedException
-
isConnected
public final boolean isConnected()
Description copied from interface:XMPPConnectionReturns true if currently connected to the XMPP server.- Specified by:
isConnectedin interfaceXMPPConnection- Returns:
- true if connected.
-
isAuthenticated
public final boolean isAuthenticated()
Description copied from interface:XMPPConnectionReturns true if currently authenticated by successfully calling the login method.- Specified by:
isAuthenticatedin interfaceXMPPConnection- Returns:
- true if authenticated.
-
getUser
public final EntityFullJid getUser()
Description copied from interface:XMPPConnectionReturns the full XMPP address of the user that is logged in to the connection ornullif not logged in yet. An XMPP address is in the form username@server/resource.- Specified by:
getUserin interfaceXMPPConnection- Returns:
- the full XMPP address of the user logged in.
-
getStreamId
public java.lang.String getStreamId()
Description copied from interface:XMPPConnectionReturns the stream ID for this connection, which is the value set by the server when opening an XMPP stream. This value will benullif not connected to the server.- Specified by:
getStreamIdin interfaceXMPPConnection- Returns:
- the ID of this connection returned from the XMPP server or
nullif not connected to the server. - See Also:
- RFC 6120 ยง 4.7.3. id
-
throwCurrentConnectionException
protected final void throwCurrentConnectionException() throws SmackException, XMPPException
- Throws:
SmackExceptionXMPPException
-
hasCurrentConnectionException
protected final boolean hasCurrentConnectionException()
-
setCurrentConnectionExceptionAndNotify
protected final void setCurrentConnectionExceptionAndNotify(java.lang.Exception exception)
-
notifyWaitingThreads
protected final void notifyWaitingThreads()
-
waitFor
protected final boolean waitFor(Supplier<java.lang.Boolean> condition) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
waitForConditionOrThrowConnectionException
protected final void waitForConditionOrThrowConnectionException(Supplier<java.lang.Boolean> condition, java.lang.String waitFor) throws java.lang.InterruptedException, SmackException, XMPPException
- Throws:
java.lang.InterruptedExceptionSmackExceptionXMPPException
-
bindResourceAndEstablishSession
protected Resourcepart bindResourceAndEstablishSession(Resourcepart resource) throws SmackException, java.lang.InterruptedException, XMPPException
- Throws:
SmackExceptionjava.lang.InterruptedExceptionXMPPException
-
afterSuccessfulLogin
protected void afterSuccessfulLogin(boolean resumed) throws SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.NotConnectedExceptionjava.lang.InterruptedException
-
isAnonymous
public final boolean isAnonymous()
Description copied from interface:XMPPConnectionReturns true if currently authenticated anonymously.- Specified by:
isAnonymousin interfaceXMPPConnection- Returns:
- true if authenticated anonymously.
-
getUsedSaslMechansism
public final java.lang.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 returnnullif this connection was not authenticated before.- Returns:
- the name of the used SASL mechanism.
- Since:
- 4.2
-
getConnectionLock
protected java.util.concurrent.locks.Lock getConnectionLock()
-
throwNotConnectedExceptionIfAppropriate
protected void throwNotConnectedExceptionIfAppropriate() throws SmackException.NotConnectedException
-
throwNotConnectedExceptionIfAppropriate
protected void throwNotConnectedExceptionIfAppropriate(java.lang.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:
getStanzaFactoryin interfaceXMPPConnection
-
sendStanza
public final void sendStanza(Stanza stanza) throws SmackException.NotConnectedException, java.lang.InterruptedException
Description copied from interface:XMPPConnectionSends the specified stanza to the server.- Specified by:
sendStanzain interfaceXMPPConnection- Parameters:
stanza- the stanza to send.- Throws:
SmackException.NotConnectedException- if the connection is not connected.java.lang.InterruptedException- if the calling thread was interrupted.
-
authenticate
protected final SASLMechanism authenticate(java.lang.String username, java.lang.String password, EntityBareJid authzid, javax.net.ssl.SSLSession sslSession) throws XMPPException.XMPPErrorException, SASLErrorException, SmackException.SmackSaslException, SmackException.NotConnectedException, SmackException.NoResponseException, java.io.IOException, java.lang.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.java.io.IOException- if an I/O error occurred.java.lang.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, java.lang.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.java.lang.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(java.lang.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:XMPPConnectionAdds a connection listener to this connection that will be notified when the connection closes or fails.- Specified by:
addConnectionListenerin interfaceXMPPConnection- Parameters:
connectionListener- a connection listener.
-
removeConnectionListener
public void removeConnectionListener(ConnectionListener connectionListener)
Description copied from interface:XMPPConnectionRemoves a connection listener from this connection.- Specified by:
removeConnectionListenerin interfaceXMPPConnection- Parameters:
connectionListener- a connection listener.
-
sendIqRequestAndWaitForResponse
public <I extends IQ> I sendIqRequestAndWaitForResponse(IQ request) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Description copied from interface:XMPPConnectionSend an IQ request and wait for the response.- Specified by:
sendIqRequestAndWaitForResponsein 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.java.lang.InterruptedException- if the calling thread was interrupted.
-
createStanzaCollectorAndSend
public StanzaCollector createStanzaCollectorAndSend(IQ packet) throws SmackException.NotConnectedException, java.lang.InterruptedException
Description copied from interface:XMPPConnectionCreates a new stanza collector collecting IQ responses that are replies to the IQrequest. Does also send therequestIQ. The stanza filter for the collector is anIQReplyFilter, guaranteeing that stanza id and JID in the 'from' address have expected values.- Specified by:
createStanzaCollectorAndSendin 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.java.lang.InterruptedException- if the calling thread was interrupted.
-
createStanzaCollectorAndSend
public StanzaCollector createStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet) throws SmackException.NotConnectedException, java.lang.InterruptedException
Description copied from interface:XMPPConnectionCreates 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 aStanzaListenerwhen you need to wait for a specific result.- Specified by:
createStanzaCollectorAndSendin 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.java.lang.InterruptedException- if the calling thread was interrupted.
-
createStanzaCollector
public StanzaCollector createStanzaCollector(StanzaFilter packetFilter)
Description copied from interface:XMPPConnectionCreates 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 aStanzaListenerwhen 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:
createStanzaCollectorin interfaceXMPPConnection- Parameters:
packetFilter- the stanza filter to use.- Returns:
- a new stanza collector.
-
createStanzaCollector
public StanzaCollector createStanzaCollector(StanzaCollector.Configuration configuration)
Description copied from interface:XMPPConnectionCreate 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:
createStanzaCollectorin interfaceXMPPConnection- Parameters:
configuration- the stanza collector configuration.- Returns:
- a new stanza collector.
-
removeStanzaCollector
public void removeStanzaCollector(StanzaCollector collector)
Description copied from interface:XMPPConnectionRemove a stanza collector of this connection.- Specified by:
removeStanzaCollectorin 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:XMPPConnectionRegisters 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 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:
addStanzaListenerin 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:XMPPConnectionRemoves a stanza listener for received stanzas from this connection.- Specified by:
removeStanzaListenerin 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:XMPPConnectionRegisters 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 aStanzaCollectorwhen possible.- Specified by:
addSyncStanzaListenerin 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:XMPPConnectionRemoves a stanza listener for received stanzas from this connection.- Specified by:
removeSyncStanzaListenerin 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:XMPPConnectionRegisters 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:
addAsyncStanzaListenerin 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:XMPPConnectionRemoves an asynchronous stanza listener for received stanzas from this connection.- Specified by:
removeAsyncStanzaListenerin 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:XMPPConnectionRegisters 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:
addStanzaSendingListenerin 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:XMPPConnectionRemoves a stanza listener for sending stanzas from this connection.- Specified by:
removeStanzaSendingListenerin 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:XMPPConnectionRegisters 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:
addStanzaInterceptorin 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:XMPPConnectionRemoves a stanza interceptor.- Specified by:
removeStanzaInterceptorin interfaceXMPPConnection- Parameters:
packetInterceptor- the stanza interceptor to remove.
-
addMessageInterceptor
public void addMessageInterceptor(Consumer<MessageBuilder> messageInterceptor, Predicate<Message> messageFilter)
Description copied from interface:XMPPConnectionRegisters 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:
addMessageInterceptorin 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:XMPPConnectionRemoves a message interceptor.- Specified by:
removeMessageInterceptorin interfaceXMPPConnection- Parameters:
messageInterceptor- the message interceptor to remove.
-
addPresenceInterceptor
public void addPresenceInterceptor(Consumer<PresenceBuilder> presenceInterceptor, Predicate<Presence> presenceFilter)
Description copied from interface:XMPPConnectionRegisters 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:
addPresenceInterceptorin 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:XMPPConnectionRemoves a presence interceptor.- Specified by:
removePresenceInterceptorin interfaceXMPPConnection- Parameters:
presenceInterceptor- the stanza interceptor to remove.
-
initDebugger
protected void initDebugger()
Initialize thedebugger. You can specify a customizedSmackDebuggerby setup the system propertysmack.debuggerClassto the implementation.- Throws:
java.lang.IllegalStateException- if the reader or writer isn't yet initialized.java.lang.IllegalArgumentException- if the SmackDebugger can't be loaded.
-
getReplyTimeout
public long getReplyTimeout()
Description copied from interface:XMPPConnectionReturns the current value of the reply timeout in milliseconds for request for this XMPPConnection instance.- Specified by:
getReplyTimeoutin interfaceXMPPConnection- Returns:
- the reply timeout in milliseconds
-
setReplyTimeout
public void setReplyTimeout(long timeout)
Description copied from interface:XMPPConnectionSet the stanza reply timeout in milliseconds. In most cases, Smack will throw aSmackException.NoResponseExceptionif no reply to a request was received within the timeout period.- Specified by:
setReplyTimeoutin 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, java.lang.Class<SN> successNonzaClass, java.lang.Class<FN> failedNonzaClass) throws SmackException.NoResponseException, SmackException.NotConnectedException, java.lang.InterruptedException, XMPPException.FailedNonzaException
- Throws:
SmackException.NoResponseExceptionSmackException.NotConnectedExceptionjava.lang.InterruptedExceptionXMPPException.FailedNonzaException
-
parseAndProcessNonza
protected final void parseAndProcessNonza(XmlPullParser parser) throws java.io.IOException, XmlPullParserException, SmackParsingException
- Throws:
java.io.IOExceptionXmlPullParserExceptionSmackParsingException
-
parseAndProcessStanza
protected void parseAndProcessStanza(XmlPullParser parser) throws XmlPullParserException, java.io.IOException, java.lang.InterruptedException
- Throws:
XmlPullParserExceptionjava.io.IOExceptionjava.lang.InterruptedException
-
processStanza
protected void processStanza(Stanza stanza) throws java.lang.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:
java.lang.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 thewasAuthenticatedflag 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:XMPPConnectionGet 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_VALUEinstances as the counter could wrap.- Specified by:
getConnectionCounterin interfaceXMPPConnection- Returns:
- the connection counter of this XMPPConnection
-
setFromMode
public void setFromMode(XMPPConnection.FromMode fromMode)
Description copied from interface:XMPPConnectionSet the FromMode for this connection instance. Defines how the 'from' attribute of outgoing stanzas should be populated by Smack.- Specified by:
setFromModein interfaceXMPPConnection- Parameters:
fromMode- TODO javadoc me please
-
getFromMode
public XMPPConnection.FromMode getFromMode()
Description copied from interface:XMPPConnectionGet the currently active FromMode.- Specified by:
getFromModein interfaceXMPPConnection- Returns:
- the currently active
XMPPConnection.FromMode
-
parseFeatures
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException, java.io.IOException, SmackParsingException
- Throws:
XmlPullParserExceptionjava.io.IOExceptionSmackParsingException
-
parseFeaturesAndNotify
protected final void parseFeaturesAndNotify(XmlPullParser parser) throws java.lang.Exception
- Throws:
java.lang.Exception
-
afterFeaturesReceived
protected void afterFeaturesReceived() throws SmackException.SecurityRequiredException, SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.SecurityRequiredExceptionSmackException.NotConnectedExceptionjava.lang.InterruptedException
-
getFeature
public <F extends FullyQualifiedElement> F getFeature(javax.xml.namespace.QName qname)
Description copied from interface:XMPPConnectionGet the feature stanza extensions for a given stream feature of the server, ornullif the server doesn't support that feature.- Specified by:
getFeaturein interfaceXMPPConnection- Type Parameters:
F-ExtensionElementtype 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(javax.xml.namespace.QName qname)
Description copied from interface:XMPPConnectionReturn true if the server supports the given stream feature.- Specified by:
hasFeaturein 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(FullyQualifiedElement feature)
-
sendIqRequestAsync
public SmackFuture<IQ,java.lang.Exception> sendIqRequestAsync(IQ request)
Description copied from interface:XMPPConnectionSend an IQ request asynchronously. The connection's default reply timeout will be used.- Specified by:
sendIqRequestAsyncin interfaceXMPPConnection- Parameters:
request- the IQ request to send.- Returns:
- a SmackFuture for the response.
-
sendIqRequestAsync
public SmackFuture<IQ,java.lang.Exception> sendIqRequestAsync(IQ request, long timeout)
Description copied from interface:XMPPConnectionSend an IQ request asynchronously.- Specified by:
sendIqRequestAsyncin 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,java.lang.Exception> sendAsync(S stanza, StanzaFilter replyFilter)
Description copied from interface:XMPPConnectionSend 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:
sendAsyncin 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,java.lang.Exception> sendAsync(S stanza, StanzaFilter replyFilter, long timeout)
Description copied from interface:XMPPConnectionSend a stanza asynchronously, waiting for exactly one response stanza using the given reply filter.- Specified by:
sendAsyncin 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:XMPPConnectionAdd a callback that is called exactly once and synchronously with the incoming stanza that matches the given stanza filter.- Specified by:
addOneTimeSyncCallbackin 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:XMPPConnectionRegister 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:
registerIQRequestHandlerin 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:XMPPConnectionConvenience method forXMPPConnection.unregisterIQRequestHandler(String, String, org.jivesoftware.smack.packet.IQ.Type).- Specified by:
unregisterIQRequestHandlerin interfaceXMPPConnection- Parameters:
iqRequestHandler- TODO javadoc me please- Returns:
- the previously registered IQ request handler or null.
-
unregisterIQRequestHandler
public IQRequestHandler unregisterIQRequestHandler(java.lang.String element, java.lang.String namespace, IQ.Type type)
Description copied from interface:XMPPConnectionUnregister an IQ request handler with this connection.- Specified by:
unregisterIQRequestHandlerin 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:XMPPConnectionReturns the timestamp in milliseconds when the last stanza was received.- Specified by:
getLastStanzaReceivedin 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
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
asyncGoLimited
protected void asyncGoLimited(java.lang.Runnable runnable)
-
setMaxAsyncOperations
public void setMaxAsyncOperations(int maxAsyncOperations)
-
asyncGo
protected static void asyncGo(java.lang.Runnable runnable)
-
getReactor
protected final SmackReactor getReactor()
-
schedule
protected static ScheduledAction schedule(java.lang.Runnable runnable, long delay, java.util.concurrent.TimeUnit unit)
-
onStreamOpen
protected void onStreamOpen(XmlPullParser parser)
-
sendStreamOpen
protected void sendStreamOpen() throws SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.NotConnectedExceptionjava.lang.InterruptedException
-
getSmackTlsContext
protected final SmackTlsContext getSmackTlsContext()
-
-