Search in sources :

Example 56 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class AccountManager method deleteAccount.

/**
 * Deletes the currently logged-in account from the server. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support deleting accounts; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when deleting the account.
 */
public void deleteAccount() throws XMPPException {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Must be logged in to delete a account.");
    }
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    Map<String, String> attributes = new HashMap<String, String>();
    // To delete an account, we add a single attribute, "remove", that is blank.
    attributes.put("remove", "");
    reg.setAttributes(attributes);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    } else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) HashMap(java.util.HashMap) Registration(org.jivesoftware.smack.packet.Registration) IQ(org.jivesoftware.smack.packet.IQ) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 57 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class LastActivityManager method getLastActivity.

/**
 * 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.
 *
 * @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.
 */
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;
}
Also used : LastActivity(org.jivesoftware.smackx.packet.LastActivity) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 58 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class KeepAliveManager method schedulePingServerTask.

/**
 * Cancels any existing periodic ping task if there is one and schedules a new ping task if pingInterval is greater
 * then zero.
 *
 * This is designed so only one executor is used for scheduling all pings on all connections.  This results in only 1 thread used for pinging.
 */
private synchronized void schedulePingServerTask() {
    enableExecutorService();
    stopPingServerTask();
    if (pingInterval > 0) {
        periodicPingTask = periodicPingExecutorService.schedule(new Runnable() {

            public void run() {
                Ping ping = new Ping();
                PacketFilter responseFilter = new PacketIDFilter(ping.getPacketID());
                final PacketCollector response = pingFailedListeners.isEmpty() ? null : connection.createPacketCollector(responseFilter);
                connection.sendPacket(ping);
                if (response != null) {
                    // Schedule a collector for the ping reply, notify listeners if none is received.
                    periodicPingExecutorService.schedule(new Runnable() {

                        public void run() {
                            Packet result = response.nextResult(1);
                            // Stop queuing results
                            response.cancel();
                            // The actual result of the reply can be ignored since we only care if we actually got one.
                            if (result == null) {
                                for (PingFailedListener listener : pingFailedListeners) {
                                    listener.pingFailed();
                                }
                            }
                        }
                    }, SmackConfiguration.getPacketReplyTimeout(), TimeUnit.MILLISECONDS);
                }
            }
        }, getPingInterval(), TimeUnit.MILLISECONDS);
    }
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) PingFailedListener(org.jivesoftware.smack.ping.PingFailedListener) Ping(org.jivesoftware.smack.ping.packet.Ping) PacketCollector(org.jivesoftware.smack.PacketCollector) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 59 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class SyncPacketSend method getReply.

public static Packet getReply(Connection connection, Packet packet, long timeout) throws XMPPException {
    PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    connection.sendPacket(packet);
    // Wait up to a certain number of seconds for a reply.
    Packet result = response.nextResult(timeout);
    // Stop queuing results
    response.cancel();
    if (result == null) {
        throw new XMPPException(SmackError.NO_RESPONSE_FROM_SERVER);
    } else if (result.getError() != null) {
        throw new XMPPException(result.getError());
    }
    return result;
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 60 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class Agent method getWorkgroups.

public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
    AgentWorkgroups request = new AgentWorkgroups(agentJID);
    request.setTo(serviceJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);
    AgentWorkgroups response = (AgentWorkgroups) 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.getWorkgroups();
}
Also used : AgentWorkgroups(org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups) PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)66 IQ (org.jivesoftware.smack.packet.IQ)38 PacketCollector (org.jivesoftware.smack.PacketCollector)36 XMPPException (org.jivesoftware.smack.XMPPException)34 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)22 Packet (org.jivesoftware.smack.packet.Packet)10 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)6 Registration (org.jivesoftware.smack.packet.Registration)6 MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)6 MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)6 RosterPacket (org.jivesoftware.smack.packet.RosterPacket)4 ArrayList (java.util.ArrayList)3 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HashMap (java.util.HashMap)2 StanzaCollector (org.jivesoftware.smack.StanzaCollector)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 Authentication (org.jivesoftware.smack.packet.Authentication)2