Wildfire 3.2.4 Javadoc

org.jivesoftware.wildfire
Class SessionManager

java.lang.Object
  extended by org.jivesoftware.wildfire.container.BasicModule
      extended by org.jivesoftware.wildfire.SessionManager
All Implemented Interfaces:
Module

public class SessionManager
extends BasicModule

Manages the sessions associated with an account. The information maintained by the Session manager is entirely transient and does not need to be preserved between server restarts.

Author:
Derek DeMoro

Field Summary
static int NEVER_KICK
           
 
Constructor Summary
SessionManager()
           
 
Method Summary
 void addAnonymousSession(ClientSession session)
           
 void addSession(ClientSession session)
          Add a new session to be managed.
 void broadcast(Packet packet)
          Broadcasts the given data to all connected sessions.
 void broadcastPresenceToOtherResources(JID originatingResource, Presence presence)
          Broadcasts presence updates from the originating user's resource to any of the user's existing available resources (if any).
 void changePriority(JID sender, int priority)
          Change the priority of a session, that was already available, associated with the sender.
 HttpSession createClientHttpSession(long rid, InetAddress address, StreamID id)
           
 ClientSession createClientSession(Connection conn)
          Creates a new ClientSession.
 ClientSession createClientSession(Connection conn, StreamID id)
          Creates a new ClientSession with the specified streamID.
 Session createComponentSession(Connection conn)
           
 IncomingServerSession createIncomingServerSession(Connection conn, StreamID id)
          Creates a session for a remote server.
 ConnectionMultiplexerSession createMultiplexerSession(Connection conn, JID address)
          Creates a new ConnectionMultiplexerSession.
 int getActiveSessionCount()
          Returns number of client sessions that are available.
 int getActiveSessionCount(String username)
          Returns the number of sessions for a user that are available.
 int getAnonymousSessionCount()
           
 Iterator getAnonymousSessions()
           
 ClientSession getBestRoute(JID recipient)
          Retrieve the best route to deliver packets to this session given the recipient jid.
 ComponentSession getComponentSession(String domain)
          Returns the session of the component whose domain matches the specified domain.
 Collection<ComponentSession> getComponentSessions()
          Returns a collection with the established sessions from external components.
 int getConflictKickLimit()
           
 InetAddress getConnectionMultiplexerInetAddress(String domain)
          Returns the IP address of the connection manager whose domain matches the specified domain.
 ConnectionMultiplexerSession getConnectionMultiplexerSession(JID address)
          Returns the session originated from the specified address.
 List<ConnectionMultiplexerSession> getConnectionMultiplexerSessions()
          Returns all sessions originated from connection managers.
 List<ConnectionMultiplexerSession> getConnectionMultiplexerSessions(String domain)
          Returns a collection with all the sessions originated from the connection manager whose domain matches the specified domain.
 Collection<String> getIncomingServers()
          Returns a collection with the hostnames of the remote servers that currently have an incoming server connection to this server.
 List<IncomingServerSession> getIncomingServerSessions(String hostname)
          Returns the list of sessions that were originated by a remote server.
static SessionManager getInstance()
          Returns the instance of SessionManagerImpl being used by the XMPPServer.
 Collection<String> getOutgoingServers()
          Returns a collection with the hostnames of the remote servers that currently may receive packets sent from this server.
 OutgoingServerSession getOutgoingServerSession(String hostname)
          Returns a session that was originated from this server to a remote server.
 Collection<String> getPreAuthenticatedKeys()
          Returns the temporary keys used by the sessions that has not been authenticated yet.
 int getServerSessionIdleTime()
           
 int getServerSessionTimeout()
          Returns the number of milliseconds to elapse between clearing of idle server sessions.
 ClientSession getSession(JID from)
          Returns the session responsible for this JID.
 ClientSession getSession(String username, String domain, String resource)
          Returns the session responsible for this JID data.
 int getSessionCount()
          Returns number of client sessions that are connected to the server.
 int getSessionCount(String username)
           
 Collection<ClientSession> getSessions()
          Returns a list that contains all client sessions connected to the server.
 Collection<ClientSession> getSessions(SessionResultFilter filter)
           
 Collection<ClientSession> getSessions(String username)
           
 Collection<String> getSessionUsers()
           
 void initialize(XMPPServer server)
          Initializes the basic module.
 boolean isActiveRoute(String username, String resource)
           
 boolean isAnonymousRoute(String username)
           
 boolean isMultipleServerConnectionsAllowed()
          Returns true if remote servers are allowed to have more than one connection to this server.
 StreamID nextStreamID()
          Returns a randomly created ID to be used in a stream element.
 void outgoingServerSessionCreated(OutgoingServerSession session)
          Notification message that a new OutgoingServerSession has been created.
 void registerIncomingServerSession(String hostname, IncomingServerSession session)
          Registers that a server session originated by a remote server is hosting a given hostname.
 void registerOutgoingServerSession(String hostname, OutgoingServerSession session)
          Registers that a server session originated by this server has been established to a remote server named hostname.
 boolean removeSession(ClientSession session)
          Removes a session.
 void sendServerMessage(JID address, String subject, String body)
          Sends a message with a given subject and body to one or more user sessions related to the specified address.
 void sendServerMessage(String subject, String body)
          Sends a message with a given subject and body to all the active user sessions in the server.
 void sessionAvailable(ClientSession session)
          Notification message sent when a client sent an available presence for the session.
 void sessionUnavailable(ClientSession session)
          Notification message sent when a client sent an unavailable presence for the session.
 void setConflictKickLimit(int limit)
           
 void setMultipleServerConnectionsAllowed(boolean allowed)
          Sets if remote servers are allowed to have more than one connection to this server.
 void setServerSessionIdleTime(int idleTime)
           
 void setServerSessionTimeout(int timeout)
          Sets the number of milliseconds to elapse between clearing of idle server sessions.
 void stop()
          Stops the basic module.
 void unregisterIncomingServerSessions(String hostname)
          Unregisters the server sessions originated by a remote server with the specified hostname.
 void unregisterOutgoingServerSession(String hostname)
          Unregisters the server session that was originated by this server to a remote server named hostname.
 void userBroadcast(String username, Packet packet)
          Broadcasts the given data to all connected sessions for a particular user.
 
Methods inherited from class org.jivesoftware.wildfire.container.BasicModule
destroy, getName, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEVER_KICK

public static final int NEVER_KICK
See Also:
Constant Field Values
Constructor Detail

SessionManager

public SessionManager()
Method Detail

getInstance

public static SessionManager getInstance()
Returns the instance of SessionManagerImpl being used by the XMPPServer.

Returns:
the instance of SessionManagerImpl being used by the XMPPServer.

getConnectionMultiplexerSession

public ConnectionMultiplexerSession getConnectionMultiplexerSession(JID address)
Returns the session originated from the specified address. If the address contains a resource then the exact session is going to be looked for and if none is found then null is going to be returned. On the other hand, if the address is just a domain then any session originated from the connection manager is going to be returned and if the connection manager has no sessions then null is going to be returned.

Parameters:
address - the address of the connection manager (no resource included) or a specific session of the connection manager (resource included).
Returns:
the session originated from the specified address.

getConnectionMultiplexerSessions

public List<ConnectionMultiplexerSession> getConnectionMultiplexerSessions()
Returns all sessions originated from connection managers.

Returns:
all sessions originated from connection managers.

getConnectionMultiplexerSessions

public List<ConnectionMultiplexerSession> getConnectionMultiplexerSessions(String domain)
Returns a collection with all the sessions originated from the connection manager whose domain matches the specified domain. If there is no connection manager with the specified domain then an empty list is going to be returned.

Parameters:
domain - the domain of the connection manager.
Returns:
a collection with all the sessions originated from the connection manager whose domain matches the specified domain.

getConnectionMultiplexerInetAddress

public InetAddress getConnectionMultiplexerInetAddress(String domain)
Returns the IP address of the connection manager whose domain matches the specified domain.

Parameters:
domain - the domain of the connection manager.
Returns:
the IP address of the connection manager.

createMultiplexerSession

public ConnectionMultiplexerSession createMultiplexerSession(Connection conn,
                                                             JID address)
Creates a new ConnectionMultiplexerSession.

Parameters:
conn - the connection to create the session from.
address - the JID (may include a resource) of the connection manager's session.
Returns:
a newly created session.

nextStreamID

public StreamID nextStreamID()
Returns a randomly created ID to be used in a stream element.

Returns:
a randomly created ID to be used in a stream element.

createClientSession

public ClientSession createClientSession(Connection conn)
Creates a new ClientSession. The new Client session will have a newly created stream ID.

Parameters:
conn - the connection to create the session from.
Returns:
a newly created session.

createClientSession

public ClientSession createClientSession(Connection conn,
                                         StreamID id)
Creates a new ClientSession with the specified streamID.

Parameters:
conn - the connection to create the session from.
id - the streamID to use for the new session.
Returns:
a newly created session.
Throws:
UnauthorizedException

createClientHttpSession

public HttpSession createClientHttpSession(long rid,
                                           InetAddress address,
                                           StreamID id)
                                    throws UnauthorizedException
Throws:
UnauthorizedException

createComponentSession

public Session createComponentSession(Connection conn)
                               throws UnauthorizedException
Throws:
UnauthorizedException

createIncomingServerSession

public IncomingServerSession createIncomingServerSession(Connection conn,
                                                         StreamID id)
                                                  throws UnauthorizedException
Creates a session for a remote server. The session should be created only after the remote server has been authenticated either using "server dialback" or SASL.

Parameters:
conn - the connection to the remote server.
id - the stream ID used in the stream element when authenticating the server.
Returns:
the newly created IncomingServerSession.
Throws:
UnauthorizedException - if the local server has not been initialized yet.

outgoingServerSessionCreated

public void outgoingServerSessionCreated(OutgoingServerSession session)
Notification message that a new OutgoingServerSession has been created. Register a listener that will react when the connection gets closed.

Parameters:
session - the newly created OutgoingServerSession.

registerIncomingServerSession

public void registerIncomingServerSession(String hostname,
                                          IncomingServerSession session)
Registers that a server session originated by a remote server is hosting a given hostname. Notice that the remote server may be hosting several subdomains as well as virtual hosts so the same IncomingServerSession may be associated with many keys. If the remote server creates many sessions to this server (eg. one for each subdomain) then associate all the sessions with the originating server that created all the sessions.

Parameters:
hostname - the hostname that is being served by the remote server.
session - the incoming server session to the remote server.

unregisterIncomingServerSessions

public void unregisterIncomingServerSessions(String hostname)
Unregisters the server sessions originated by a remote server with the specified hostname. Notice that the remote server may be hosting several subdomains as well as virtual hosts so the same IncomingServerSession may be associated with many keys. The remote server may have many sessions established with this server (eg. to the server itself and to subdomains hosted by this server).

Parameters:
hostname - the hostname that is being served by the remote server.

registerOutgoingServerSession

public void registerOutgoingServerSession(String hostname,
                                          OutgoingServerSession session)
Registers that a server session originated by this server has been established to a remote server named hostname. This session will only be used for sending packets to the remote server and cannot receive packets. The OutgoingServerSession may have one or more domains, subdomains or virtual hosts authenticated with the remote server.

Parameters:
hostname - the hostname that is being served by the remote server.
session - the outgoing server session to the remote server.

unregisterOutgoingServerSession

public void unregisterOutgoingServerSession(String hostname)
Unregisters the server session that was originated by this server to a remote server named hostname. This session was only being used for sending packets to the remote server and not for receiving packets. The OutgoingServerSession may have one or more domains, subdomains or virtual hosts authenticated with the remote server.

Parameters:
hostname - the hostname that the session was connected with.

addSession

public void addSession(ClientSession session)
Add a new session to be managed.


sessionAvailable

public void sessionAvailable(ClientSession session)
Notification message sent when a client sent an available presence for the session. Making the session available means that the session is now eligible for receiving messages from other clients. Sessions whose presence is not available may only receive packets (IQ packets) from the server. Therefore, an unavailable session remains invisible to other clients.

Parameters:
session - the session that receieved an available presence.

broadcastPresenceToOtherResources

public void broadcastPresenceToOtherResources(JID originatingResource,
                                              Presence presence)
Broadcasts presence updates from the originating user's resource to any of the user's existing available resources (if any).

Parameters:
originatingResource - the full JID of the session that sent the presence update.

sessionUnavailable

public void sessionUnavailable(ClientSession session)
Notification message sent when a client sent an unavailable presence for the session. Making the session unavailable means that the session is not eligible for receiving messages from other clients.

Parameters:
session - the session that receieved an unavailable presence.

changePriority

public void changePriority(JID sender,
                           int priority)
Change the priority of a session, that was already available, associated with the sender.

Parameters:
sender - The sender who's session just changed priority
priority - The new priority for the session

getBestRoute

public ClientSession getBestRoute(JID recipient)
Retrieve the best route to deliver packets to this session given the recipient jid. If the requested JID does not have a node (i.e. username) then the best route will be looked up in the anonymous sessions list. Otherwise, try to find a root for the exact JID (i.e. including the resource) and if none is found then answer the deafult session if any.

Parameters:
recipient - The recipient ID to deliver packets to
Returns:
The XMPPAddress best suited to use for delivery to the recipient

isAnonymousRoute

public boolean isAnonymousRoute(String username)

isActiveRoute

public boolean isActiveRoute(String username,
                             String resource)

getSession

public ClientSession getSession(JID from)
Returns the session responsible for this JID.

Parameters:
from - the sender of the packet.
Returns:
the Session associated with the JID.

getSession

public ClientSession getSession(String username,
                                String domain,
                                String resource)
Returns the session responsible for this JID data. The returned Session may have never sent an available presence (thus not have a route) or could be a Session that hasn't authenticated yet (i.e. preAuthenticatedSessions).

Parameters:
username - the username of the JID.
domain - the username of the JID.
resource - the username of the JID.
Returns:
the Session associated with the JID data.

getSessions

public Collection<ClientSession> getSessions()
Returns a list that contains all client sessions connected to the server. The list contains sessions of anonymous and non-anonymous users.

Returns:
a list that contains all client sessions connected to the server.

getSessions

public Collection<ClientSession> getSessions(SessionResultFilter filter)

getIncomingServerSessions

public List<IncomingServerSession> getIncomingServerSessions(String hostname)
Returns the list of sessions that were originated by a remote server. The list will be ordered chronologically. IncomingServerSession can only receive packets from the remote server but are not capable of sending packets to the remote server.

Parameters:
hostname - the name of the remote server.
Returns:
the sessions that were originated by a remote server.

getOutgoingServerSession

public OutgoingServerSession getOutgoingServerSession(String hostname)
Returns a session that was originated from this server to a remote server. OutgoingServerSession an only send packets to the remote server but are not capable of receiving packets from the remote server.

Parameters:
hostname - the name of the remote server.
Returns:
a session that was originated from this server to a remote server.

getAnonymousSessions

public Iterator getAnonymousSessions()

getSessions

public Collection<ClientSession> getSessions(String username)

getSessionCount

public int getSessionCount()
Returns number of client sessions that are connected to the server. Anonymous users are included too.

Returns:
number of client sessions that are connected to the server.

getActiveSessionCount

public int getActiveSessionCount()
Returns number of client sessions that are available. Anonymous users are included too.

Returns:
number of client sessions that are available.

getAnonymousSessionCount

public int getAnonymousSessionCount()

getActiveSessionCount

public int getActiveSessionCount(String username)
Returns the number of sessions for a user that are available. For the count of all sessions for the user, including sessions that are just starting or closed, see getSessionCount(String).

Parameters:
username - the user.
Returns:
number of available sessions for a user.

getSessionCount

public int getSessionCount(String username)

getSessionUsers

public Collection<String> getSessionUsers()

getComponentSessions

public Collection<ComponentSession> getComponentSessions()
Returns a collection with the established sessions from external components.

Returns:
a collection with the established sessions from external components.

getComponentSession

public ComponentSession getComponentSession(String domain)
Returns the session of the component whose domain matches the specified domain.

Parameters:
domain - the domain of the component session to look for.
Returns:
the session of the component whose domain matches the specified domain.

getIncomingServers

public Collection<String> getIncomingServers()
Returns a collection with the hostnames of the remote servers that currently have an incoming server connection to this server.

Returns:
a collection with the hostnames of the remote servers that currently have an incoming server connection to this server.

getOutgoingServers

public Collection<String> getOutgoingServers()
Returns a collection with the hostnames of the remote servers that currently may receive packets sent from this server.

Returns:
a collection with the hostnames of the remote servers that currently may receive packets sent from this server.

broadcast

public void broadcast(Packet packet)
               throws UnauthorizedException
Broadcasts the given data to all connected sessions. Excellent for server administration messages.

Parameters:
packet - The packet to be broadcast
Throws:
UnauthorizedException

userBroadcast

public void userBroadcast(String username,
                          Packet packet)
                   throws UnauthorizedException,
                          PacketException
Broadcasts the given data to all connected sessions for a particular user. Excellent for updating all connected resources for users such as roster pushes.

Parameters:
packet - The packet to be broadcast
Throws:
UnauthorizedException
PacketException

removeSession

public boolean removeSession(ClientSession session)
Removes a session.

Parameters:
session - the session.
Returns:
true if the requested session was successfully removed.

addAnonymousSession

public void addAnonymousSession(ClientSession session)

getConflictKickLimit

public int getConflictKickLimit()

getPreAuthenticatedKeys

public Collection<String> getPreAuthenticatedKeys()
Returns the temporary keys used by the sessions that has not been authenticated yet. This is an utility method useful for debugging situations.

Returns:
the temporary keys used by the sessions that has not been authenticated yet.

setConflictKickLimit

public void setConflictKickLimit(int limit)

initialize

public void initialize(XMPPServer server)
Description copied from class: BasicModule

Initializes the basic module.

Inheriting classes that choose to override this method MUST call this initialize() method before accessing BasicModule resources.

Specified by:
initialize in interface Module
Overrides:
initialize in class BasicModule
Parameters:
server - the server hosting this module.

sendServerMessage

public void sendServerMessage(String subject,
                              String body)
Sends a message with a given subject and body to all the active user sessions in the server.

Parameters:
subject - the subject to broadcast.
body - the body to broadcast.

sendServerMessage

public void sendServerMessage(JID address,
                              String subject,
                              String body)
Sends a message with a given subject and body to one or more user sessions related to the specified address. If address is null or the address's node is null then the message will be sent to all the user sessions. But if the address includes a node but no resource then the message will be sent to all the user sessions of the requeted user (defined by the node). Finally, if the address is a full JID then the message will be sent to the session associated to the full JID. If no session is found then the message is not sent.

Parameters:
address - the address that defines the sessions that will receive the message.
subject - the subject to broadcast.
body - the body to broadcast.

stop

public void stop()
Description copied from class: BasicModule

Stops the basic module.

Inheriting classes that choose to override this method MUST call this stop() method before accessing BasicModule resources.

Specified by:
stop in interface Module
Overrides:
stop in class BasicModule

isMultipleServerConnectionsAllowed

public boolean isMultipleServerConnectionsAllowed()
Returns true if remote servers are allowed to have more than one connection to this server. Having more than one connection may improve number of packets that can be transfered per second. This setting only used by the server dialback mehod.

It is highly recommended that getServerSessionTimeout() is enabled so that dead connections to this server can be easily discarded.

Returns:
true if remote servers are allowed to have more than one connection to this server.

setMultipleServerConnectionsAllowed

public void setMultipleServerConnectionsAllowed(boolean allowed)
Sets if remote servers are allowed to have more than one connection to this server. Having more than one connection may improve number of packets that can be transfered per second. This setting only used by the server dialback mehod.

It is highly recommended that getServerSessionTimeout() is enabled so that dead connections to this server can be easily discarded.

Parameters:
allowed - true if remote servers are allowed to have more than one connection to this server.

setServerSessionTimeout

public void setServerSessionTimeout(int timeout)
Sets the number of milliseconds to elapse between clearing of idle server sessions.

Parameters:
timeout - the number of milliseconds to elapse between clearings.

getServerSessionTimeout

public int getServerSessionTimeout()
Returns the number of milliseconds to elapse between clearing of idle server sessions.

Returns:
the number of milliseconds to elapse between clearing of idle server sessions.

setServerSessionIdleTime

public void setServerSessionIdleTime(int idleTime)

getServerSessionIdleTime

public int getServerSessionIdleTime()

Wildfire 3.2.4 Javadoc

Copyright © 2003-2007 Jive Software.