Class LastActivityManager
- java.lang.Object
-
- rocks.xmpp.core.session.Manager
-
- rocks.xmpp.extensions.last.LastActivityManager
-
- All Implemented Interfaces:
ExtensionProtocol
,DiscoverableInfo
public final class LastActivityManager extends Manager implements ExtensionProtocol, DiscoverableInfo
The implementation of XEP-0012: Last Activity and XEP-0256: Last Activity in Presence.It is often helpful to know the time of the last activity associated with a entity. The canonical usage is to discover when a disconnected user last accessed its server. The 'jabber:iq:last' namespace provides a method for retrieving that information. The 'jabber:iq:last' namespace can also be used to discover or publicize when a connected user was last active on the server (i.e., the user's idle time) or to query servers and components about their current uptime.
This class also takes care about the following use case, by automatically appending last activity information to 'away' and 'xa' presences:
When a client automatically sets the user's
<show/>
value to "away" or "xa" (extended away), it can indicate when that particular was last active during the current presence session.This manager also automatically adds an
<idle/>
extension to outbound presences, if the presence is of type away or xa. However, sending such presences is still the responsibility of the application developer, i.e. no presences are sent automatically.By default, idle time is determined by outbound messages and non-away, non-xa presences. E.g. whenever a message is sent, the idle time is reset to the current time. Then, when a 'away' or 'xa' presence is sent, the
<idle/>
extension is added with the date of the last sent message.The strategy for determining last user interaction can be changed by setting a supplier which returns the timestamp of last user interaction. Possible alternative strategies is to track mouse movement or keyboard interaction for which cases you would set a supplier which gets the date of the last mouse movement.
Automatic inclusion of last activity information in presence stanzas and support for this protocol can be Manager.setEnabled(boolean) enabled or disabled}.
Code sample
LastActivityManager lastActivityManager = xmppSession.getManager(LastActivityManager.class); LastActivity lastActivity = lastActivityManager.getLastActivity(Jid.of("juliet@example.com/balcony")).getResult();
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>
getFeatures()
Gets the features.Supplier<Instant>
getIdleStrategy()
Gets the current idle strategy, i.e. a supplier for last user interaction.AsyncResult<LastActivity>
getLastActivity(Jid jid)
Gets the last activity of the specified user.Instant
getLastSentStanzaTime()
Gets the time of the last sent message or non-away, non-xa presence.String
getNamespace()
The protocol's main namespace.void
setIdleStrategy(Supplier<Instant> idleStrategy)
Sets an idle strategy, i.e. a supplier for last user interaction.-
Methods inherited from class rocks.xmpp.core.session.Manager
isEnabled, setEnabled
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface rocks.xmpp.extensions.disco.model.info.DiscoverableInfo
getExtensions, getIdentities
-
Methods inherited from interface rocks.xmpp.core.ExtensionProtocol
isEnabled
-
-
-
-
Method Detail
-
getLastSentStanzaTime
public Instant getLastSentStanzaTime()
Gets the time of the last sent message or non-away, non-xa presence.This is the default strategy for determining last user interaction.
- Returns:
- The time of the last sent stanza.
-
setIdleStrategy
public void setIdleStrategy(Supplier<Instant> idleStrategy)
Sets an idle strategy, i.e. a supplier for last user interaction.- Parameters:
idleStrategy
- The strategy.- See Also:
getLastSentStanzaTime()
-
getIdleStrategy
public Supplier<Instant> getIdleStrategy()
Gets the current idle strategy, i.e. a supplier for last user interaction.- Returns:
- The strategy or null if no strategy is set.
-
getLastActivity
public AsyncResult<LastActivity> getLastActivity(Jid jid)
Gets the last activity of the specified user.The information contained in an IQ reply for this namespace is inherently ambiguous. Specifically, for a bare JID
<localpart@domain.tld>
the information is the time since the JID was last connected to its server; for a full JID<localpart@domain.tld/resource>
the information is the time since the resource was last active in the context of an existing session; and for a bare domain the information is the uptime for the server or component. An application MUST take these differences into account when presenting the information to a human user (if any).- Parameters:
jid
- The JID for which the last activity is requested.- Returns:
- The async result with the last activity of the requested JID or null if the feature is not implemented or a time out has occurred.
-
getNamespace
public final String getNamespace()
Description copied from interface:ExtensionProtocol
The protocol's main namespace. This is used to uniquely identify the extension protocol.- Specified by:
getNamespace
in interfaceExtensionProtocol
- Returns:
- The main namespace.
-
getFeatures
public final Set<String> getFeatures()
Description copied from interface:DiscoverableInfo
Gets the features.- Specified by:
getFeatures
in interfaceDiscoverableInfo
- Returns:
- The features.
-
-