public class XmppSession extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
static class |
XmppSession.Status
Represents the connection status.
|
| Constructor and Description |
|---|
XmppSession(String xmppServiceDomain,
ConnectionConfiguration... connectionConfigurations)
Creates a session with the specified service domain, by using the default configuration.
|
XmppSession(String xmppServiceDomain,
XmppSessionConfiguration configuration,
ConnectionConfiguration... connectionConfigurations)
Creates a session with the specified service domain by using a configuration.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addIQListener(IQListener iqListener)
Adds an IQ listener to the connection, which will get notified, whenever an IQ stanza is received.
|
void |
addMessageListener(MessageListener messageListener)
Adds a message listener to the connection, which will get notified, whenever a message is received.
|
void |
addPresenceListener(PresenceListener presenceListener)
Adds a presence listener to the connection, which will get notified, whenever a presence is received.
|
void |
addSessionStatusListener(SessionStatusListener sessionStatusListener)
Adds a session listener, which listens for session status changes.
|
void |
close()
Explicitly closes the connection and performs a clean up of all listeners.
|
void |
connect()
Connects to the XMPP server.
|
Connection |
getActiveConnection()
Gets the actively used connection.
|
AuthenticationManager |
getAuthenticationManager()
Gets the authentication manager, which is responsible for SASL negotiation.
|
ChatManager |
getChatManager()
Gets the chat manager, which is responsible for one-to-one chat sessions.
|
XmppSessionConfiguration |
getConfiguration() |
Jid |
getConnectedResource()
Gets the connected resource, which is assigned by the server after resource binding.
|
List<Connection> |
getConnections()
Gets an unmodifiable list of connections.
|
int |
getDefaultTimeout()
Gets the default timeout for synchronous operations.
|
String |
getDomain()
Gets the XMPP domain of the connected server.
|
<T extends ExtensionManager> |
getExtensionManager(Class<T> clazz) |
FeaturesManager |
getFeaturesManager()
Gets the features manager, which is responsible for negotiating features.
|
Marshaller |
getMarshaller()
Gets the marshaller, which is used to marshal XML during writing to the output stream.
|
PresenceManager |
getPresenceManager()
Gets the presence manager, which is responsible for presence subscriptions.
|
ReconnectionManager |
getReconnectionManager()
Gets the reconnection manager, which is responsible for automatic reconnection.
|
RosterManager |
getRosterManager()
Gets the roster manager, which is responsible for retrieving, updating and deleting contacts from the roster.
|
XmppSession.Status |
getStatus()
Gets the status of the connection.
|
Unmarshaller |
getUnmarshaller()
Gets the unmarshaller, which is used to unmarshal XML during reading from the input stream.
|
boolean |
handleElement(Object element)
Handles a XMPP element.
|
boolean |
isConnected()
Indicates, whether the session is connected.
|
void |
login(String user,
String password)
Authenticates against the server and binds a random resource (assigned by the server).
|
void |
login(String user,
String password,
String resource)
Authenticates against the server and binds a resource.
|
void |
loginAnonymously()
Logs in anonymously and binds a resource.
|
void |
notifyException(Exception e)
Called if any unhandled exception is thrown during reading or writing.
|
IQ |
query(IQ iq)
Sends an
<iq/> stanza and waits for the response. |
IQ |
query(IQ iq,
long timeout)
Sends an
<iq/> stanza and waits for the response. |
void |
reconnect()
Reconnects to the XMPP server and automatically logs in by using the last known information (e.g. user name, password and bound resource).
|
void |
removeIQListener(IQListener iqListener)
Removes a previously added IQ listener from the connection.
|
void |
removeMessageListener(MessageListener messageListener)
Removes a previously added message listener from the connection.
|
void |
removePresenceListener(PresenceListener presenceListener)
Removes a previously added presence listener from the connection.
|
void |
removeSessionStatusListener(SessionStatusListener sessionStatusListener)
Removes a previously added connection listener.
|
void |
send(ClientStreamElement element)
Sends an XML element to the server, usually a stanza, i.e. a message, presence or IQ.
|
IQ |
sendAndAwaitIQ(ClientStreamElement stanza,
StanzaFilter<IQ> filter)
Sends a stanza and then waits for an IQ stanza to arrive.
|
IQ |
sendAndAwaitIQ(ClientStreamElement stanza,
StanzaFilter<IQ> filter,
long timeout)
Sends a stanza and then waits for an IQ stanza to arrive.
|
Message |
sendAndAwaitMessage(ClientStreamElement stanza,
StanzaFilter<Message> filter)
Sends a stanza and then waits for a message stanza to arrive.
|
Presence |
sendAndAwaitPresence(ClientStreamElement stanza,
StanzaFilter<Presence> filter)
Sends a stanza and then waits for a presence stanza to arrive.
|
Presence |
sendAndAwaitPresence(ClientStreamElement stanza,
StanzaFilter<Presence> filter,
long timeout)
Sends a stanza and then waits for a presence stanza to arrive.
|
void |
setXmppServiceDomain(String xmppServiceDomain)
Sets the XMPP service domain.
|
protected void |
waitUntilSaslNegotiationStarted()
Waits until SASL negotiation has started and then releases the lock.
|
public XmppSession(String xmppServiceDomain, ConnectionConfiguration... connectionConfigurations)
xmppServiceDomain - The service domain.connectionConfigurations - The connection configurations.public XmppSession(String xmppServiceDomain, XmppSessionConfiguration configuration, ConnectionConfiguration... connectionConfigurations)
xmppServiceDomain - The service domain.configuration - The configuration.connectionConfigurations - The connection configurations.public Connection getActiveConnection()
public void setXmppServiceDomain(String xmppServiceDomain)
xmppServiceDomain - The XMPP service domain.public final void addMessageListener(MessageListener messageListener)
messageListener - The message listener.removeMessageListener(MessageListener)public final void removeMessageListener(MessageListener messageListener)
messageListener - The message listener.addMessageListener(MessageListener)public final void addPresenceListener(PresenceListener presenceListener)
presenceListener - The presence listener.removePresenceListener(PresenceListener)public final void removePresenceListener(PresenceListener presenceListener)
presenceListener - The presence listener.addPresenceListener(PresenceListener)public final void addIQListener(IQListener iqListener)
iqListener - The IQ listener.removeIQListener(IQListener)public final void removeIQListener(IQListener iqListener)
iqListener - The IQ listener.addIQListener(IQListener)public final void addSessionStatusListener(SessionStatusListener sessionStatusListener)
sessionStatusListener - The session listener.removeSessionStatusListener(SessionStatusListener)public final void removeSessionStatusListener(SessionStatusListener sessionStatusListener)
sessionStatusListener - The session listener.addSessionStatusListener(SessionStatusListener)public IQ query(IQ iq) throws XmppException
<iq/> stanza and waits for the response.
This method blocks until a result was received or a timeout occurred.
iq - The <iq/> stanza, which must be of type get or set.<iq/> stanza.StanzaException - If the entity returned a stanza error.NoResponseException - If the entity did not respond.XmppExceptionpublic IQ query(IQ iq, long timeout) throws XmppException
<iq/> stanza and waits for the response.
This method blocks until a result was received or a timeout occurred.
iq - The <iq/> stanza, which must be of type get or set.timeout - The timeout.<iq/> stanza.StanzaException - If the entity returned a stanza error.NoResponseException - If the entity did not respond.XmppExceptionpublic IQ sendAndAwaitIQ(ClientStreamElement stanza, StanzaFilter<IQ> filter) throws NoResponseException, StanzaException
stanza - The stanza, which is sent.filter - The presence filter.NoResponseException - If no IQ stanza has arrived in time.StanzaException - If the returned IQ contains a stanza error.public IQ sendAndAwaitIQ(ClientStreamElement stanza, StanzaFilter<IQ> filter, long timeout) throws NoResponseException, StanzaException
stanza - The stanza, which is sent.filter - The presence filter.timeout - The timeout.NoResponseException - If no IQ stanza has arrived in time.StanzaException - If the returned presence IQ a stanza error.public Presence sendAndAwaitPresence(ClientStreamElement stanza, StanzaFilter<Presence> filter) throws NoResponseException, StanzaException
stanza - The stanza, which is sent.filter - The presence filter.NoResponseException - If no presence stanza has arrived in time.StanzaException - If the returned presence contains a stanza error.public Presence sendAndAwaitPresence(ClientStreamElement stanza, StanzaFilter<Presence> filter, long timeout) throws NoResponseException, StanzaException
stanza - The stanza, which is sent.filter - The presence filter.timeout - The timeout.NoResponseException - If no presence stanza has arrived in time.StanzaException - If the returned presence contains a stanza error.public Message sendAndAwaitMessage(ClientStreamElement stanza, StanzaFilter<Message> filter) throws NoResponseException, StanzaException
stanza - The stanza, which is sent.filter - The message filter.NoResponseException - If no message stanza has arrived in time.StanzaException - If the returned message contains a stanza error.public final void reconnect()
throws IOException,
LoginException
IOException - If an exception occurred while connecting.LoginException - If an exception occurred while logging in.public void connect()
throws IOException
IOException - If anything went wrong, e.g. the host was not found.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - If an exception occurs while closing the connection, e.g. the underlying socket connection.public void send(ClientStreamElement element)
element - The XML element.public final void login(String user, String password) throws LoginException
user - The user name. Usually this is the local part of the user's JID. Must not be null.password - The password. Must not be null.LoginException - If the login failed, due to a SASL error reported by the server.FailedLoginException - If the login failed, due to a wrong username or password. It is thrown if the server reports a <not-authorized/> SASL error.AccountLockedException - If the login failed, because the account has been disabled. It is thrown if the server reports a <account-disabled/> SASL error.CredentialExpiredException - If the login failed, because the credentials have expired. It is thrown if the server reports a <credentials-expired/> SASL error.public final void login(String user, String password, String resource) throws LoginException
user - The user name. Usually this is the local part of the user's JID. Must not be null.password - The password. Must not be null.resource - The resource. If null or empty, the resource is randomly assigned by the server.LoginException - If the login failed, due to a SASL error reported by the server.FailedLoginException - If the login failed, due to a wrong username or password. It is thrown if the server reports a <not-authorized/> SASL error.AccountLockedException - If the login failed, because the account has been disabled. It is thrown if the server reports a <account-disabled/> SASL error.CredentialExpiredException - If the login failed, because the credentials have expired. It is thrown if the server reports a <credentials-expired/> SASL error.public final void loginAnonymously()
throws LoginException
LoginException - If the anonymous login failed.AuthenticationManager.authenticateAnonymously()public final boolean handleElement(Object element) throws Exception
This method should be called on the reader thread.
element - The XMPP element.StreamException - If the element is a stream error.Exception - If any exception occurred during feature negotiation.public final void notifyException(Exception e)
This method will close the stream.
e - The exception. If an unrecoverable XMPP stream error occurred, the exception is a StreamError.public final <T extends ExtensionManager> T getExtensionManager(Class<T> clazz)
T - The type.clazz - The class of the extension manager.public final AuthenticationManager getAuthenticationManager()
public final RosterManager getRosterManager()
public final PresenceManager getPresenceManager()
public final ReconnectionManager getReconnectionManager()
public final FeaturesManager getFeaturesManager()
public final ChatManager getChatManager()
public final Jid getConnectedResource()
After a client has bound a resource to the stream, it is referred to as a "connected resource".
public final String getDomain()
public final XmppSession.Status getStatus()
public List<Connection> getConnections()
public Unmarshaller getUnmarshaller()
public Marshaller getMarshaller()
protected final void waitUntilSaslNegotiationStarted()
throws NoResponseException,
IOException
connect() method.NoResponseException - If no response was received from the server.IOException - If any exception occurred during stream negotiation.public final int getDefaultTimeout()
public boolean isConnected()
XmppSession.Status.CONNECTED, XmppSession.Status.AUTHENTICATED or XmppSession.Status.AUTHENTICATING.getStatus()public XmppSessionConfiguration getConfiguration()
Copyright © 2014 XMPP.rocks. All rights reserved.