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());
}
}
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;
}
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);
}
}
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;
}
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();
}
Aggregations