Class LastActivityManager


  • public final class LastActivityManager
    extends org.jivesoftware.smack.Manager
    A last activity manager for handling information about the last activity associated with a Jabber ID. A manager handles incoming LastActivity requests of existing Connections. It also allows to request last activity information of other users. LastActivity (XEP-0012) based on the sending JID's type allows for retrieval of:
    1. How long a particular user has been idle
    2. How long a particular user has been logged-out and the message the specified when doing so.
    3. How long a host has been up.
    For example to get the idle time of a user logged in a resource, simple send the LastActivity stanza to them, as in the following code:
     XMPPConnection con = new XMPPTCPConnection("jabber.org");
     con.login("john", "doe");
     LastActivity activity = LastActivity.getLastActivity(con, "xray@jabber.org/Smack");
     
    To get the lapsed time since the last user logout is the same as above but with out the resource:
     LastActivity activity = LastActivity.getLastActivity(con, "xray@jabber.org");
     
    To get the uptime of a host, you simple send the LastActivity stanza to it, as in the following code example:
     LastActivity activity = LastActivity.getLastActivity(con, "jabber.org");
     
    See Also:
    XEP-0012: Last Activity
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void disable()  
      void enable()  
      static LastActivityManager getInstanceFor​(org.jivesoftware.smack.XMPPConnection connection)  
      LastActivity getLastActivity​(org.jxmpp.jid.Jid jid)
      Returns the last activity of a particular jid.
      boolean isLastActivitySupported​(org.jxmpp.jid.Jid jid)
      Returns true if Last Activity (XEP-0012) is supported by a given JID.
      static void setEnabledPerDefault​(boolean enabledPerDefault)
      Enable or disable Last Activity for new XMPPConnections.
      • Methods inherited from class org.jivesoftware.smack.Manager

        connection, getAuthenticatedConnectionOrThrow, schedule, schedule, scheduleBlocking
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • setEnabledPerDefault

        public static void setEnabledPerDefault​(boolean enabledPerDefault)
        Enable or disable Last Activity for new XMPPConnections.
        Parameters:
        enabledPerDefault - TODO javadoc me please
      • getInstanceFor

        public static LastActivityManager getInstanceFor​(org.jivesoftware.smack.XMPPConnection connection)
      • enable

        public void enable()
      • disable

        public void disable()
      • getLastActivity

        public LastActivity getLastActivity​(org.jxmpp.jid.Jid jid)
                                     throws org.jivesoftware.smack.SmackException.NoResponseException,
                                            org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                            org.jivesoftware.smack.SmackException.NotConnectedException,
                                            java.lang.InterruptedException
        Returns the last activity of a particular jid. If the jid is a full JID (i.e., a JID of the form of 'user@host/resource') then the last activity is the idle time of that connected resource. On the other hand, when the jid is a bare JID (e.g. 'user@host') then the last activity is the lapsed time since the last logout or 0 if the user is currently logged in. Moreover, when the jid is a server or component (e.g., a JID of the form 'host') the last activity is the uptime.
        Parameters:
        jid - TODO javadoc me please the JID of the user.
        Returns:
        the LastActivity stanza of the jid.
        Throws:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned. thrown if a server error has occurred.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the server.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • isLastActivitySupported

        public boolean isLastActivitySupported​(org.jxmpp.jid.Jid jid)
                                        throws org.jivesoftware.smack.SmackException.NoResponseException,
                                               org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                               org.jivesoftware.smack.SmackException.NotConnectedException,
                                               java.lang.InterruptedException
        Returns true if Last Activity (XEP-0012) is supported by a given JID.
        Parameters:
        jid - a JID to be tested for Last Activity support
        Returns:
        true if Last Activity is supported, otherwise false
        Throws:
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        java.lang.InterruptedException - if the calling thread was interrupted.