Search in sources :

Example 46 with PacketCollector

use of org.jivesoftware.smack.PacketCollector 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("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)

Aggregations

PacketCollector (org.jivesoftware.smack.PacketCollector)46 XMPPException (org.jivesoftware.smack.XMPPException)44 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)36 IQ (org.jivesoftware.smack.packet.IQ)24 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)21 Packet (org.jivesoftware.smack.packet.Packet)10 ArrayList (java.util.ArrayList)6 AndFilter (org.jivesoftware.smack.filter.AndFilter)6 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)6 MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)6 MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)6 FromMatchesFilter (org.jivesoftware.smack.filter.FromMatchesFilter)4 Message (org.jivesoftware.smack.packet.Message)4 OfflineMessageRequest (org.jivesoftware.smackx.packet.OfflineMessageRequest)4 PacketInterceptor (org.jivesoftware.smack.PacketInterceptor)3 Presence (org.jivesoftware.smack.packet.Presence)3 MUCInitialPresence (org.jivesoftware.smackx.packet.MUCInitialPresence)3 Registration (org.jivesoftware.smack.packet.Registration)2 StreamInitiation (org.jivesoftware.smackx.packet.StreamInitiation)2 AgentInfo (org.jivesoftware.smackx.workgroup.packet.AgentInfo)2