public class SessionManager extends BasicModule implements ClusterEventListener
Modifier and Type | Field and Description |
---|---|
static String |
C2S_INFO_CACHE_NAME |
static String |
CM_CACHE_NAME |
static String |
COMPONENT_SESSION_CACHE_NAME |
static String |
ISS_CACHE_NAME |
static int |
NEVER_KICK |
Constructor and Description |
---|
SessionManager() |
Modifier and Type | Method and Description |
---|---|
void |
addDetached(LocalSession localSession)
Record a session as being detached (ie, has no connection).
|
void |
addSession(LocalClientSession session)
Add a new session to be managed.
|
void |
broadcast(org.xmpp.packet.Message packet)
Broadcasts the given data to all connected sessions.
|
void |
broadcastPresenceToOtherResources(org.xmpp.packet.JID originatingResource,
org.xmpp.packet.Presence presence)
Broadcasts presence updates from the originating user's resource to any of the user's
existing available resources (if any).
|
void |
changePriority(LocalClientSession session,
int oldPriority)
Change the priority of a session, that was already available, associated with the sender.
|
HttpSession |
createClientHttpSession(long rid,
InetAddress address,
StreamID id,
HttpConnection connection,
Locale language)
Creates a new ClientSession with the specified streamID.
|
LocalClientSession |
createClientSession(Connection conn,
Locale language)
Creates a new ClientSession.
|
LocalClientSession |
createClientSession(Connection conn,
StreamID id)
Creates a new ClientSession with the specified streamID.
|
LocalClientSession |
createClientSession(Connection conn,
StreamID id,
Locale language)
Creates a new ClientSession with the specified streamID.
|
LocalComponentSession |
createComponentSession(org.xmpp.packet.JID address,
Connection conn) |
LocalIncomingServerSession |
createIncomingServerSession(Connection conn,
StreamID id,
String fromDomain)
Creates a session for a remote server.
|
LocalConnectionMultiplexerSession |
createMultiplexerSession(Connection conn,
org.xmpp.packet.JID address)
Creates a new ConnectionMultiplexerSession.
|
int |
getActiveSessionCount(String username)
Returns the number of sessions for a user that are available.
|
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() |
ConnectionMultiplexerSession |
getConnectionMultiplexerSession(org.xmpp.packet.JID address)
Returns the session originated from the specified address or null if none was
found.
|
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.
|
int |
getConnectionsCount(boolean onlyLocal)
Returns number of client sessions that are connected to the server.
|
Collection<String> |
getIncomingServers()
Returns a collection with the hostnames of the remote servers that currently have an
incoming server connection to this server.
|
LocalIncomingServerSession |
getIncomingServerSession(StreamID streamID)
Returns the incoming server session hosted by this JVM that matches the specified stream ID.
|
List<IncomingServerSession> |
getIncomingServerSessions(String hostname)
Returns the list of sessions that were originated by a remote server.
|
int |
getIncomingServerSessionsCount(boolean onlyLocal)
Returns number of sessions coming from remote servers.
|
static SessionManager |
getInstance()
Returns the instance of
SessionManagerImpl being used by the XMPPServer. |
Collection<DomainPair> |
getOutgoingDomainPairs() |
Collection<String> |
getOutgoingServers()
Returns a collection with the hostnames of the remote servers that currently may receive
packets sent from this server.
|
OutgoingServerSession |
getOutgoingServerSession(DomainPair pair)
Returns a session that was originated from this server to a remote server.
|
List<OutgoingServerSession> |
getOutgoingServerSessions(String host) |
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(org.xmpp.packet.JID from)
Returns the session responsible for this JID data.
|
int |
getSessionCount(String username) |
int |
getSessionDetachTime() |
Cache<String,ClientSessionInfo> |
getSessionInfoCache() |
Collection<ClientSession> |
getSessions()
Returns a list that contains all authenticated client sessions connected to the server.
|
Collection<ClientSession> |
getSessions(SessionResultFilter filter) |
Collection<ClientSession> |
getSessions(String username) |
int |
getUserSessionsCount(boolean onlyLocal)
Returns number of client sessions that are authenticated with the server.
|
Collection<String> |
getValidatedDomains(StreamID streamID)
Returns a collection with all the domains, subdomains and virtual hosts that where
validated.
|
void |
initialize(XMPPServer server)
Initializes the basic module.
|
boolean |
isActiveRoute(String username,
String resource) |
boolean |
isAnonymousRoute(org.xmpp.packet.JID address) |
boolean |
isAnonymousRoute(String username) |
boolean |
isMultipleServerConnectionsAllowed()
Returns true if remote servers are allowed to have more than one connection to this
server.
|
static boolean |
isOtherResourcePresenceEnabled()
Returns true if the session should broadcast presences to all other resources for the
current client.
|
boolean |
isPreAuthenticatedSession(org.xmpp.packet.JID address)
Returns true if the specified address belongs to a preauthenticated session.
|
void |
joinedCluster()
Notification event indicating that this JVM is now part of a cluster.
|
void |
joinedCluster(byte[] nodeID)
Notification event indicating that another JVM is now part of a cluster.
|
void |
leftCluster()
Notification event indicating that this JVM is no longer part of the cluster.
|
void |
leftCluster(byte[] nodeID)
Notification event indicating that another JVM is no longer part of the cluster.
|
void |
markedAsSeniorClusterMember()
Notification event indicating that this JVM is now the senior cluster member.
|
StreamID |
nextStreamID()
Returns a randomly created ID to be used in a stream element.
|
void |
outgoingServerSessionCreated(LocalOutgoingServerSession session)
Notification message that a new OutgoingServerSession has been created.
|
void |
registerIncomingServerSession(String hostname,
LocalIncomingServerSession session)
Registers that a server session originated by a remote server is hosting a given hostname.
|
void |
removeDetached(LocalSession localSession)
Remove a session as being detached.
|
boolean |
removeSession(ClientSession session,
org.xmpp.packet.JID fullJID,
boolean anonymous,
boolean forceUnavailable)
Removes a session.
|
boolean |
removeSession(LocalClientSession session)
Removes a session.
|
void |
sendServerMessage(org.xmpp.packet.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(LocalClientSession session,
org.xmpp.packet.Presence presence)
Notification message sent when a client sent an available presence for the session.
|
void |
sessionUnavailable(LocalClientSession 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 |
setSessionDetachTime(int idleTime) |
void |
start()
Starts the basic module.
|
void |
stop()
Stops the basic module.
|
void |
unregisterIncomingServerSession(String hostname,
IncomingServerSession session)
Unregisters the specified remote server session originiated by the specified remote server.
|
void |
userBroadcast(String username,
org.xmpp.packet.Packet packet)
Broadcasts the given data to all connected sessions for a particular
user.
|
destroy, getName
public static final String COMPONENT_SESSION_CACHE_NAME
public static final String CM_CACHE_NAME
public static final String ISS_CACHE_NAME
public static final String C2S_INFO_CACHE_NAME
public static final int NEVER_KICK
public static SessionManager getInstance()
SessionManagerImpl
being used by the XMPPServer.SessionManagerImpl
being used by the XMPPServer.public void addDetached(LocalSession localSession)
localSession
- the LocalSession (this) to mark as detached.public void removeDetached(LocalSession localSession)
localSession
- the LocalSession (this) which has been resumed or closed.public ConnectionMultiplexerSession getConnectionMultiplexerSession(org.xmpp.packet.JID address)
address
- the address of the connection manager (including resource that identifies specific socket)public List<ConnectionMultiplexerSession> getConnectionMultiplexerSessions()
public List<ConnectionMultiplexerSession> getConnectionMultiplexerSessions(String domain)
domain
- the domain of the connection manager.public LocalConnectionMultiplexerSession createMultiplexerSession(Connection conn, org.xmpp.packet.JID address)
conn
- the connection to create the session from.address
- the JID (may include a resource) of the connection manager's session.public StreamID nextStreamID()
public LocalClientSession createClientSession(Connection conn, Locale language)
conn
- the connection to create the session from.language
- The language to use for the new session.public LocalClientSession createClientSession(Connection conn, StreamID id)
conn
- the connection to create the session from.id
- the streamID to use for the new session.public LocalClientSession createClientSession(Connection conn, StreamID id, Locale language)
conn
- the connection to create the session from.id
- the streamID to use for the new session.language
- The language to use for the new session.public HttpSession createClientHttpSession(long rid, InetAddress address, StreamID id, HttpConnection connection, Locale language) throws UnauthorizedException
connection
- the connection to create the session from.id
- the streamID to use for the new session.UnauthorizedException
public LocalComponentSession createComponentSession(org.xmpp.packet.JID address, Connection conn)
public LocalIncomingServerSession createIncomingServerSession(Connection conn, StreamID id, String fromDomain) throws UnauthorizedException
conn
- the connection to the remote server.id
- the stream ID used in the stream element when authenticating the server.IncomingServerSession
.UnauthorizedException
- if the local server has not been initialized yet.public void outgoingServerSessionCreated(LocalOutgoingServerSession session)
session
- the newly created OutgoingServerSession.public void registerIncomingServerSession(String hostname, LocalIncomingServerSession session)
hostname
- the hostname that is being served by the remote server.session
- the incoming server session to the remote server.public void unregisterIncomingServerSession(String hostname, IncomingServerSession session)
hostname
- the hostname that is being served by the remote server.session
- the session to unregiser.public Collection<String> getValidatedDomains(StreamID streamID)
Content is stored in a clustered cache so that even in the case of the node hosting the sessions is lost we can still have access to this info to be able to perform proper clean up logic.
streamID
- id that uniquely identifies the session.public void addSession(LocalClientSession session)
session
- the session that was authenticated.public void sessionAvailable(LocalClientSession session, org.xmpp.packet.Presence presence)
session
- the session that receieved an available presence.presence
- the presence for the session.public static boolean isOtherResourcePresenceEnabled()
public void broadcastPresenceToOtherResources(org.xmpp.packet.JID originatingResource, org.xmpp.packet.Presence presence)
originatingResource
- the full JID of the session that sent the presence update.presence
- the presence.public void sessionUnavailable(LocalClientSession session)
session
- the session that received an unavailable presence.public void changePriority(LocalClientSession session, int oldPriority)
session
- The session whose presence priority has been modifiedoldPriority
- The old priority for the sessionpublic boolean isAnonymousRoute(String username)
public boolean isAnonymousRoute(org.xmpp.packet.JID address)
public ClientSession getSession(org.xmpp.packet.JID from)
from
- the sender of the packet.Session
associated with the JID.public Collection<ClientSession> getSessions()
public Collection<ClientSession> getSessions(SessionResultFilter filter)
public LocalIncomingServerSession getIncomingServerSession(StreamID streamID)
streamID
- the stream ID that identifies the incoming server session hosted by this JVM.public List<IncomingServerSession> getIncomingServerSessions(String hostname)
hostname
- the name of the remote server.public OutgoingServerSession getOutgoingServerSession(DomainPair pair)
pair
- DomainPair describing the local and remote servers.public List<OutgoingServerSession> getOutgoingServerSessions(String host)
public Collection<ClientSession> getSessions(String username)
public int getConnectionsCount(boolean onlyLocal)
onlyLocal
- true if only sessions connected to this JVM will be considered. Otherwise count cluster wise.public int getUserSessionsCount(boolean onlyLocal)
onlyLocal
- true if only sessions connected to this JVM will be considered. Otherwise count cluster wise.public int getIncomingServerSessionsCount(boolean onlyLocal)
onlyLocal
- true if only sessions connected to this JVM will be considered. Otherwise count cluster wise.public int getActiveSessionCount(String username)
username
- the user.getConnectionsCount(boolean)
public int getSessionCount(String username)
public Collection<ComponentSession> getComponentSessions()
public ComponentSession getComponentSession(String domain)
domain
- the domain of the component session to look for.public Collection<String> getIncomingServers()
public Collection<String> getOutgoingServers()
public Collection<DomainPair> getOutgoingDomainPairs()
public void broadcast(org.xmpp.packet.Message packet)
packet
- the packet to be broadcast.public void userBroadcast(String username, org.xmpp.packet.Packet packet) throws PacketException
username
- the user to send the boradcast to.packet
- the packet to be broadcast.PacketException
- if a packet exception occurs.public boolean removeSession(LocalClientSession session)
session
- the session.public boolean removeSession(ClientSession session, org.xmpp.packet.JID fullJID, boolean anonymous, boolean forceUnavailable)
session
- the session or null when session is derived from fullJID.fullJID
- the address of the session.anonymous
- true if the authenticated user is anonymous.forceUnavailable
- true if an unavailable presence must be created and routed.public int getConflictKickLimit()
public Collection<String> getPreAuthenticatedKeys()
public boolean isPreAuthenticatedSession(org.xmpp.packet.JID address)
address
- the address of the session.public void setConflictKickLimit(int limit)
public void initialize(XMPPServer server)
BasicModule
Initializes the basic module.
Inheriting classes that choose to override this method MUST call this initialize() method before accessing BasicModule resources.
initialize
in interface Module
initialize
in class BasicModule
server
- the server hosting this module.public void sendServerMessage(String subject, String body)
subject
- the subject to broadcast.body
- the body to broadcast.public void sendServerMessage(org.xmpp.packet.JID address, String subject, String body)
address
- the address that defines the sessions that will receive the message.subject
- the subject to broadcast.body
- the body to broadcast.public void start() throws IllegalStateException
BasicModule
Starts the basic module.
Inheriting classes that choose to override this method MUST call this start() method before accessing BasicModule resources.
start
in interface Module
start
in class BasicModule
IllegalStateException
- If start is called before initialize
successfully returnspublic void stop()
BasicModule
Stops the basic module.
Inheriting classes that choose to override this method MUST call this stop() method before accessing BasicModule resources.
stop
in interface Module
stop
in class BasicModule
public boolean isMultipleServerConnectionsAllowed()
It is highly recommended that getServerSessionTimeout()
is enabled so that
dead connections to this server can be easily discarded.
public void setMultipleServerConnectionsAllowed(boolean allowed)
It is highly recommended that getServerSessionTimeout()
is enabled so that
dead connections to this server can be easily discarded.
allowed
- true if remote servers are allowed to have more than one connection to this
server.public void setServerSessionTimeout(int timeout)
timeout
- the number of milliseconds to elapse between clearings.public int getServerSessionTimeout()
public void setServerSessionIdleTime(int idleTime)
public int getServerSessionIdleTime()
public void setSessionDetachTime(int idleTime)
public int getSessionDetachTime()
public Cache<String,ClientSessionInfo> getSessionInfoCache()
public void joinedCluster()
ClusterEventListener
XMPPServer.getNodeID()
holds the new nodeID value.
When joining the cluster as the senior cluster member the ClusterEventListener.markedAsSeniorClusterMember()
event will be sent right after this event.
At this point the CacheFactory holds clustered caches. That means that modifications to the caches will be reflected in the cluster. The clustered caches were just obtained from the cluster and no local cached data was automatically moved.
joinedCluster
in interface ClusterEventListener
public void joinedCluster(byte[] nodeID)
ClusterEventListener
At this point the CacheFactory of the new node holds clustered caches. That means that modifications to the caches of this JVM will be reflected in the cluster and in particular in the new node.
joinedCluster
in interface ClusterEventListener
nodeID
- ID of the node that joined the cluster.public void leftCluster()
ClusterEventListener
Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the island were this JVM belonged was marked as "old" then all nodes of that island will get the left cluster event and joined cluster events. That means that caches will be reset and thus will need to be repopulated again with fresh data from this JVM. This also includes the case where this JVM was the senior cluster member and when the islands met again then this JVM stopped being the senior member.
At this point the CacheFactory holds local caches. That means that modifications to the caches will only affect this JVM.
leftCluster
in interface ClusterEventListener
public void leftCluster(byte[] nodeID)
ClusterEventListener
Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the island were the other JVM belonged was marked as "old" then all nodes of that island will get the left cluster event and joined cluster events. That means that caches will be reset and thus will need to be repopulated again with fresh data from this JVM. This also includes the case where the other JVM was the senior cluster member and when the islands met again then the other JVM stopped being the senior member.
At this point the CacheFactory of the leaving node holds local caches. That means that modifications to the caches of this JVM will not affect the leaving node but other cluster members.
leftCluster
in interface ClusterEventListener
nodeID
- ID of the node that is left the cluster.public void markedAsSeniorClusterMember()
ClusterEventListener
Moreover, in the case of a "split brain" scenario (ie. separated cluster islands) each
island will have its own senior cluster member. However, when the islands meet again there
could only be one senior cluster member so one of the senior cluster members will stop playing
that role. When that happens the JVM no longer playing that role will receive the
ClusterEventListener.leftCluster()
and ClusterEventListener.joinedCluster()
events.
markedAsSeniorClusterMember
in interface ClusterEventListener
Copyright © 2003-2008 Jive Software.