Examples of LastActivity


Examples of org.jivesoftware.smackx.packet.LastActivity

   * is answered and correct
   */
  public void testServerUptime() {
    XMPPConnection conn0 = getConnection(0);

    LastActivity lastActivity = null;
    try {
      lastActivity = LastActivityManager.getLastActivity(conn0, getHost());
    } catch (XMPPException e) {
      if (e.getXMPPError().getCode() == 403) {
        //The test can not be done since the host do not allow this kind of request
        return;
      }
      e.printStackTrace();
      fail("An error occurred requesting the Last Activity");
    }

    assertNotNull("No last activity packet", lastActivity);
        assertTrue("The last activity idle time should be greater than 0 : " +
                lastActivity.getIdleTime(), lastActivity.getIdleTime() > 0);
    }
View Full Code Here

Examples of org.jivesoftware.smackx.packet.LastActivity

        // Register a listener for a last activity query
        connection.addPacketListener(new PacketListener() {

            public void processPacket(Packet packet) {
                LastActivity message = new LastActivity();
                message.setType(IQ.Type.RESULT);
                message.setTo(packet.getFrom());
                message.setFrom(packet.getTo());
                message.setPacketID(packet.getPacketID());
                message.setLastActivity(getIdleTime());

                LastActivityManager.this.connection.sendPacket(message);
            }

        }, new AndFilter(new IQTypeFilter(IQ.Type.GET), new PacketTypeFilter(LastActivity.class)));
View Full Code Here

Examples of org.jivesoftware.smackx.packet.LastActivity

     * @return the LastActivity packet of the jid.
     * @throws XMPPException
     *             thrown if a server error has occured.
     */
    public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException {
        LastActivity activity = new LastActivity();
        activity.setTo(jid);

        PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
        con.sendPacket(activity);

        LastActivity response = (LastActivity) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

        // Cancel the collector.
        collector.cancel();
        if (response == null) {
            throw new XMPPException("No response from server on status set.");
        }
        if (response.getError() != null) {
            throw new XMPPException(response.getError());
        }
        return response;
    }
View Full Code Here

Examples of rocks.xmpp.extensions.last.model.LastActivity

    public void testGetLastActivity() throws XmppException {
        MockServer mockServer = new MockServer();
        TestXmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        new TestXmppSession(JULIET, mockServer);
        LastActivityManager lastActivityManager = xmppSession1.getExtensionManager(LastActivityManager.class);
        LastActivity lastActivity = lastActivityManager.getLastActivity(JULIET);
        Assert.assertNotNull(lastActivity);
    }
View Full Code Here

Examples of rocks.xmpp.extensions.last.model.LastActivity

                "    to='romeo@montague.net/orchard'\n" +
                "    type='result'>\n" +
                "  <query xmlns='jabber:iq:last' seconds='903'/>\n" +
                "</iq>";
        IQ iq = unmarshal(xml, IQ.class);
        LastActivity lastActivity = iq.getExtension(LastActivity.class);
        Assert.assertNotNull(lastActivity);
        Assert.assertEquals(lastActivity.getSeconds(), 903);
    }
View Full Code Here

Examples of rocks.xmpp.extensions.last.model.LastActivity

                    AbstractPresence presence = e.getPresence();
                    if (presence.getTo() == null) {
                        synchronized (LastActivityManager.this) {
                            // If an available presence with <show/> value 'away' or 'xa' is sent, append last activity information.
                            if (lastActivityStrategy != null && lastActivityStrategy.getLastActivity() != null && presence.isAvailable() && (presence.getShow() == AbstractPresence.Show.AWAY || presence.getShow() == AbstractPresence.Show.XA) && presence.getExtension(LastActivity.class) == null) {
                                presence.getExtensions().add(new LastActivity(getSecondsSince(lastActivityStrategy.getLastActivity()), presence.getStatus()));
                            }
                        }
                    }
                }
            }
        });

        xmppSession.addIQListener(new IQListener() {
            @Override
            public void handle(IQEvent e) {
                IQ iq = e.getIQ();
                if (e.isIncoming() && isEnabled() && !e.isConsumed() && iq.getType() == IQ.Type.GET && iq.getExtension(LastActivity.class) != null) {
                    // If someone asks me to get my last activity, reply.
                    synchronized (LastActivityManager.this) {
                        IQ result = iq.createResult();
                        long seconds = (lastActivityStrategy != null && lastActivityStrategy.getLastActivity() != null) ? getSecondsSince(lastActivityStrategy.getLastActivity()) : 0;
                        result.setExtension(new LastActivity(seconds, null));
                        xmppSession.send(result);
                        e.consume();
                    }
                }
            }
View Full Code Here

Examples of rocks.xmpp.extensions.last.model.LastActivity

     * @return The last activity of the requested JID or null if the feature is not implemented or a time out has occurred.
     * @throws rocks.xmpp.core.stanza.model.StanzaException If the entity returned a stanza error.
     * @throws rocks.xmpp.core.session.NoResponseException  If the entity did not respond.
     */
    public LastActivity getLastActivity(Jid jid) throws XmppException {
        IQ result = xmppSession.query(new IQ(jid, IQ.Type.GET, new LastActivity()));
        return result.getExtension(LastActivity.class);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.