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); }
/** * Retrieve the last activity of a particular jid. * @param con the current XMPPConnection. * @param jid the JID of the user. * @return the LastActivity packet of the jid. * @throws XMPPException thrown if a server error has occured. */ public static LastActivity getLastActivity(XMPPConnection con, String jid) throws XMPPException { LastActivity activity = new LastActivity(); jid = StringUtils.parseBareAddress(jid); 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; } }
public IQ parseIQ(XmlPullParser parser) throws Exception { if (parser.getEventType() != XmlPullParser.START_TAG) { throw new IllegalStateException("Parser not in proper position, or bad XML."); } LastActivity lastActivity = new LastActivity(); try { String seconds = parser.getAttributeValue("", "seconds"); String message = parser.nextText(); if (seconds != null) { long xmlSeconds = new Double(seconds).longValue(); lastActivity.setLastActivity((int)xmlSeconds); } if (message != null) { lastActivity.setMessage(message); } } catch (Exception e) { e.printStackTrace(); } return lastActivity; } }
public LastActivity() { setType(IQ.Type.GET); }
public IQ parseIQ(XmlPullParser parser) throws Exception { if (parser.getEventType() != XmlPullParser.START_TAG) { throw new IllegalStateException("Parser not in proper position, or bad XML."); } LastActivity lastActivity = new LastActivity(); try { String seconds = parser.getAttributeValue("", "seconds"); String message = parser.nextText(); if (seconds != null) { long xmlSeconds = new Double(seconds).longValue(); lastActivity.setLastActivity((int)xmlSeconds); } if (message != null) { lastActivity.setMessage(message); } } catch (Exception e) { e.printStackTrace(); } return lastActivity; } }
LastActivity activity = new LastActivity(); activity.setTo(jid); PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID())); con.sendPacket(activity); throw new XMPPException("No response from server on status set."); if (response.getError() != null) { throw new XMPPException(response.getError());
public IQ parseIQ(XmlPullParser parser) throws Exception { if (parser.getEventType() != XmlPullParser.START_TAG) { throw new IllegalStateException("Parser not in proper position, or bad XML."); } LastActivity lastActivity = new LastActivity(); try { String seconds = parser.getAttributeValue("", "seconds"); String message = parser.nextText(); if (seconds != null) { long xmlSeconds = new Double(seconds).longValue(); lastActivity.setLastActivity((int)xmlSeconds); } if (message != null) { lastActivity.setMessage(message); } } catch (Exception e) { e.printStackTrace(); } return lastActivity; } }
public LastActivity() { setType(Type.GET); }
/** * Creates a last activity manager to response last activity requests. * * @param connection The Connection that the last activity requests will use. */ private LastActivityManager(Connection connection) { this.connection = connection; // Listen to all the sent messages to reset the idle time on each one connection.addPacketSendingListener(new PacketListener() { public void processPacket(Packet packet) { resetIdleTime(); } }, null); // 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))); }
/** * Retrieve the last activity of a particular jid. * @param con the current Connection. * @param jid the JID of the user. * @return the LastActivity packet of the jid. * @throws XMPPException thrown if a server error has occured. * @deprecated This method only retreives the lapsed time since the last logout of a particular jid. * Replaced by {@link org.jivesoftware.smackx.LastActivityManager#getLastActivity(Connection, String) getLastActivity} */ public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException { LastActivity activity = new LastActivity(); jid = StringUtils.parseBareAddress(jid); 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; } }
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); }
public IQ parseIQ(XmlPullParser parser) throws XMPPException, XmlPullParserException { if (parser.getEventType() != XmlPullParser.START_TAG) { throw new XMPPException("Parser not in proper position, or bad XML."); } LastActivity lastActivity = new LastActivity(); String seconds = parser.getAttributeValue("", "seconds"); String message = null; try { message = parser.nextText(); } catch (IOException e1) { // Ignore } if (seconds != null) { try { lastActivity.setLastActivity(Long.parseLong(seconds)); } catch (NumberFormatException e) { // Ignore } } if (message != null) { lastActivity.setMessage(message); } return lastActivity; } }
public LastActivity() { setType(IQ.Type.GET); }
/** * Creates a last activity manager to response last activity requests. * * @param connection The Connection that the last activity requests will use. */ private LastActivityManager(Connection connection) { this.connection = connection; // Listen to all the sent messages to reset the idle time on each one connection.addPacketSendingListener(new PacketListener() { public void processPacket(Packet packet) { resetIdleTime(); } }, null); // 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))); }
/** * Retrieve the last activity of a particular jid. * @param con the current Connection. * @param jid the JID of the user. * @return the LastActivity packet of the jid. * @throws XMPPException thrown if a server error has occured. * @deprecated This method only retreives the lapsed time since the last logout of a particular jid. * Replaced by {@link org.jivesoftware.smackx.LastActivityManager#getLastActivity(Connection, String) getLastActivity} */ public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException { LastActivity activity = new LastActivity(); jid = StringUtils.parseBareAddress(jid); 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; } }
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); }
public LastActivity() { setType(IQ.Type.GET); }
LastActivity message = new LastActivity(); message.setType(IQ.Type.RESULT); message.setTo(packet.getFrom());
LastActivity activity = new LastActivity(); activity.setTo(jid); con.createPacketCollector(new PacketIDFilter(activity.getPacketID())); con.sendPacket(activity); throw new XMPPException("No response from server on status set."); if (response.getError() != null) { throw new XMPPException(response.getError());
LastActivity activity = new LastActivity(); activity.setTo(jid); con.createPacketCollector(new PacketIDFilter(activity.getPacketID())); con.sendPacket(activity); throw new XMPPException("No response from server on status set."); if (response.getError() != null) { throw new XMPPException(response.getError());