Package org.jivesoftware.openfire.spi
Class PresenceManagerImpl
- java.lang.Object
-
- org.jivesoftware.openfire.container.BasicModule
-
- org.jivesoftware.openfire.spi.PresenceManagerImpl
-
- All Implemented Interfaces:
Module
,UserEventListener
,PresenceManager
,XMPPServerListener
public class PresenceManagerImpl extends BasicModule implements PresenceManager, UserEventListener, XMPPServerListener
Simple in memory implementation of the PresenceManager interface.- Author:
- Iain Shigeoka
-
-
Field Summary
-
Fields inherited from interface org.jivesoftware.openfire.PresenceManager
SORT_ONLINE_TIME, SORT_USERNAME
-
-
Constructor Summary
Constructors Constructor Description PresenceManagerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canProbePresence(org.xmpp.packet.JID prober, String probee)
Returns true if the the prober is allowed to see the presence of the probee.long
getLastActivity(User user)
Returns the number of milliseconds since the user went offline or -1 if such information is not available or if the user is online.String
getLastPresenceStatus(User user)
Returns the status sent by the user in his last unavailable presence ornull
if the user is online or never set such information.org.xmpp.packet.Presence
getPresence(User user)
Returns the user's current presence, ornull
if the user is unavailable.Collection<org.xmpp.packet.Presence>
getPresences(String username)
Returns all presences for the user, ornull
if the user is unavailable.void
handleProbe(org.xmpp.packet.Presence packet)
Handle a presence probe sent by a remote server.void
initialize(XMPPServer server)
Initializes the basic module.boolean
isAvailable(User user)
Returns the availability of the user.void
probePresence(org.xmpp.packet.JID prober, org.xmpp.packet.JID probee)
Probes the presence of the given XMPPAddress and attempts to send it to the given user.void
sendUnavailableFromSessions(org.xmpp.packet.JID recipientJID, org.xmpp.packet.JID userJID)
Sends unavailable presence from all of the user's available resources to the remote user.void
serverStarted()
Notification message indicating that the server has been started.void
serverStopping()
Notification message indication that the server is about to be stopped.void
start()
Starts the basic module.void
stop()
Stops the basic module.void
userAvailable(org.xmpp.packet.Presence presence)
Notification message saying that the sender of the given presence just became available.void
userCreated(User user, Map<String,Object> params)
A user was created.void
userDeleting(User user, Map<String,Object> params)
A user is being deleted.void
userModified(User user, Map<String,Object> params)
A user's name, email, or an extended property was changed.void
userUnavailable(org.xmpp.packet.Presence presence)
Notification message saying that the sender of the given presence just became unavailable.-
Methods inherited from class org.jivesoftware.openfire.container.BasicModule
destroy, getName
-
-
-
-
Method Detail
-
isAvailable
public boolean isAvailable(User user)
Description copied from interface:PresenceManager
Returns the availability of the user.
- Specified by:
isAvailable
in interfacePresenceManager
- Parameters:
user
- the user who's availability is in question- Returns:
- true if the user as available for messaging (1 or more available sessions)
-
getPresence
public org.xmpp.packet.Presence getPresence(User user)
Description copied from interface:PresenceManager
Returns the user's current presence, ornull
if the user is unavailable. If the user is connected with more than one session, the user's "most available" presence status is returned.- Specified by:
getPresence
in interfacePresenceManager
- Parameters:
user
- the user.- Returns:
- the user's current presence.
-
getPresences
public Collection<org.xmpp.packet.Presence> getPresences(String username)
Description copied from interface:PresenceManager
Returns all presences for the user, ornull
if the user is unavailable.- Specified by:
getPresences
in interfacePresenceManager
- Parameters:
username
- the name of the user.- Returns:
- the Presence packets for all the users's connected sessions.
-
getLastPresenceStatus
public String getLastPresenceStatus(User user)
Description copied from interface:PresenceManager
Returns the status sent by the user in his last unavailable presence ornull
if the user is online or never set such information.- Specified by:
getLastPresenceStatus
in interfacePresenceManager
- Parameters:
user
- the user to return his last status information- Returns:
- the status sent by the user in his last unavailable presence or
null
if the user is online or never set such information.
-
getLastActivity
public long getLastActivity(User user)
Description copied from interface:PresenceManager
Returns the number of milliseconds since the user went offline or -1 if such information is not available or if the user is online.- Specified by:
getLastActivity
in interfacePresenceManager
- Parameters:
user
- the user to return his information.- Returns:
- the number of milliseconds since the user went offline or -1 if such information is not available or if the user is online.
-
userAvailable
public void userAvailable(org.xmpp.packet.Presence presence)
Description copied from interface:PresenceManager
Notification message saying that the sender of the given presence just became available.- Specified by:
userAvailable
in interfacePresenceManager
- Parameters:
presence
- the presence sent by the available user.
-
userUnavailable
public void userUnavailable(org.xmpp.packet.Presence presence)
Description copied from interface:PresenceManager
Notification message saying that the sender of the given presence just became unavailable.- Specified by:
userUnavailable
in interfacePresenceManager
- Parameters:
presence
- the presence sent by the unavailable user.
-
handleProbe
public void handleProbe(org.xmpp.packet.Presence packet) throws UnauthorizedException
Description copied from interface:PresenceManager
Handle a presence probe sent by a remote server. The logic to apply is the following: If the remote user is not in the local user's roster with a subscription state of "From", or "Both", then return a presence stanza of type "error" in response to the presence probe. Otherwise, answer the presence of the local user sessions or the last unavailable presence.- Specified by:
handleProbe
in interfacePresenceManager
- Parameters:
packet
- the received probe presence from a remote server.- Throws:
UnauthorizedException
- if the user is not authorised
-
canProbePresence
public boolean canProbePresence(org.xmpp.packet.JID prober, String probee) throws UserNotFoundException
Description copied from interface:PresenceManager
Returns true if the the prober is allowed to see the presence of the probee.- Specified by:
canProbePresence
in interfacePresenceManager
- Parameters:
prober
- the user that is trying to probe the presence of another user.probee
- the username of the user that is being probed.- Returns:
- true if the the prober is allowed to see the presence of the probee.
- Throws:
UserNotFoundException
- If the probee does not exist in the local server or the prober is not present in the roster of the probee.
-
probePresence
public void probePresence(org.xmpp.packet.JID prober, org.xmpp.packet.JID probee)
Description copied from interface:PresenceManager
Probes the presence of the given XMPPAddress and attempts to send it to the given user. If the user probing the presence is using his bare JID then the probee's presence will be sent to all connected resources of the prober.- Specified by:
probePresence
in interfacePresenceManager
- Parameters:
prober
- The user requesting the probeprobee
- The XMPPAddress whos presence we would like sent have have probed
-
sendUnavailableFromSessions
public void sendUnavailableFromSessions(org.xmpp.packet.JID recipientJID, org.xmpp.packet.JID userJID)
Description copied from interface:PresenceManager
Sends unavailable presence from all of the user's available resources to the remote user. When a remote user unsubscribes from the presence of a local user then the server should send to the remote user unavailable presence from all of the local user's available resources. Moreover, if the recipient user is a local user then the unavailable presence will be sent to all user resources.- Specified by:
sendUnavailableFromSessions
in interfacePresenceManager
- Parameters:
recipientJID
- JID of the remote user that will receive the unavailable presences.userJID
- JID of the local user.
-
userCreated
public void userCreated(User user, Map<String,Object> params)
Description copied from interface:UserEventListener
A user was created.- Specified by:
userCreated
in interfaceUserEventListener
- Parameters:
user
- the user.params
- event parameters.
-
userDeleting
public void userDeleting(User user, Map<String,Object> params)
Description copied from interface:UserEventListener
A user is being deleted.- Specified by:
userDeleting
in interfaceUserEventListener
- Parameters:
user
- the user.params
- event parameters.
-
userModified
public void userModified(User user, Map<String,Object> params)
Description copied from interface:UserEventListener
A user's name, email, or an extended property was changed.- Specified by:
userModified
in interfaceUserEventListener
- Parameters:
user
- the user.params
- event parameters.
-
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 interfaceModule
- Overrides:
initialize
in classBasicModule
- Parameters:
server
- the server hosting this module.
-
start
public void start() throws IllegalStateException
Description copied from class:BasicModule
Starts the basic module.
Inheriting classes that choose to override this method MUST call this start() method before accessing BasicModule resources.
- Specified by:
start
in interfaceModule
- Overrides:
start
in classBasicModule
- Throws:
IllegalStateException
- If start is called before initialize successfully returns
-
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 interfaceModule
- Overrides:
stop
in classBasicModule
-
serverStarted
public void serverStarted()
Description copied from interface:XMPPServerListener
Notification message indicating that the server has been started. At this point all server modules have been initialized and started. Message sending and receiving is now possible. However, some plugins may still be pending to be loaded.- Specified by:
serverStarted
in interfaceXMPPServerListener
-
serverStopping
public void serverStopping()
Description copied from interface:XMPPServerListener
Notification message indication that the server is about to be stopped. At this point all modules are still running so all services are still available.- Specified by:
serverStopping
in interfaceXMPPServerListener
-
-