PacketFilter packetFilter = new IQReplyFilter(pubsubIQ, xmppConn); // Create the packet collector before sending the packet PacketCollector packetCollector = xmppConn.createPacketCollector(packetFilter); IQ responseIQ = (IQ) packetCollector.nextResult(PACKET_TIMEOUT); packetCollector.cancel();
public ListenerWrapper(PacketReader packetReader, PacketListener packetListener, PacketFilter packetFilter) { this.packetListener = packetListener; this.packetCollector = new PacketCollector(packetReader, packetFilter); }
/** * Processes a packet after it's been fully parsed by looping through the installed * packet collectors and listeners and letting them examine the packet to see if * they are a match with the filter. * * @param packet the packet to process. */ private void processPacket(Packet packet) { if (packet == null) { return; } // Loop through all collectors and notify the appropriate ones. for (PacketCollector collector: connection.getPacketCollectors()) { collector.processPacket(packet); } // Deliver the incoming packet to listeners. listenerExecutor.submit(new ListenerNotification(packet)); }
/** * Returns the next available message in the chat. The method call will block * (not return) until a message is available. * * @return the next message. */ public Message nextMessage() { return (Message) messageCollector.nextResult(); }
public void cancel() { packetCollector.cancel(); packetCollector = null; packetListener = null; } }
private boolean loadBufferWait() throws IOException { IBBExtensions.Data data; Message mess = null; while (mess == null) { if (isDone) { mess = (Message) dataCollector.pollResult(); if (mess == null) { return false; } } else { mess = (Message) dataCollector.nextResult(1000); } } lastMess = mess; data = (IBBExtensions.Data) mess.getExtension( IBBExtensions.Data.ELEMENT_NAME, IBBExtensions.NAMESPACE); checkSequence(mess, (int) data.getSeq()); buffer = Base64.decode(data.getData()); bufferPointer = 0; return true; }
/** * Returns the next available message in the chat. The method call will block * (not return) until a message is available. * * @return the next message. */ public Message nextMessage() { return (Message)messageCollector.nextResult(); }
public void finalize() throws Throwable { super.finalize(); try { if (messageCollector != null) { messageCollector.cancel(); } } catch (Exception e) { // Ignore. } } }
public synchronized ResultServiceIQ waitResult(final long timeout) { log.debug("Wait message currentID : " + currentID + " timeout : " + timeout); ResultServiceIQ message = null; boolean isWaitEncore = true; try { while (isWaitEncore && message == null) { message = (ResultServiceIQ) collector.nextResult(timeout); if (message == null) { isWaitEncore = reWaitResult != null ? reWaitResult.isReWaitResult(timeout) : false; } } collector.cancel(); } catch (Exception e) { } return message; } }
/** * Returns the next available message in the chat. The method call will block * (not return) until a packet is available or the <tt>timeout</tt> has elapased. * If the timeout elapses without a result, <tt>null</tt> will be returned. * * @param timeout the maximum amount of time to wait for the next message. * @return the next message, or <tt>null</tt> if the timeout elapses without a * message becoming available. */ public Message nextMessage(long timeout) { return (Message)messageCollector.nextResult(timeout); }
@Override public void disconnect() { if (packetCollector != null) { packetCollector.cancel(); } doDisconnect(); }
/** * Creates a new packet collector for this reader. A packet filter determines * which packets will be accumulated by the collector. * * @param packetFilter the packet filter to use. * @return a new packet collector. */ public PacketCollector createPacketCollector(PacketFilter packetFilter) { return new PacketCollector(this, packetFilter); }
/** * Processes a packet after it's been fully parsed by looping through the installed * packet collectors and listeners and letting them examine the packet to see if * they are a match with the filter. * * @param packet the packet to process. */ private void processPacket(Packet packet) { if (packet == null) { return; } // Loop through all collectors and notify the appropriate ones. for (PacketCollector collector: connection.getPacketCollectors()) { collector.processPacket(packet); } // Deliver the incoming packet to listeners. listenerExecutor.submit(new ListenerNotification(packet)); }
final XMPPConnection mConnection = this.getConnection(); this.login(); IQConnectionRequest iq = new IQConnectionRequest("00000000/relay_1A", "00000000/relay_1A"); iq.setTo("sandbox@xmppserver.domain.net/0004a369d964"); iq.setFrom("user@xmppserver.domain.net"); iq.setPacketID("123"); iq.setType(IQ.Type.GET); PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getPacketID()), new PacketTypeFilter(IQ.class)); PacketCollector collector = mConnection.createPacketCollector(filter); // Send the iq packet with an invalid namespace mConnection.sendPacket(iq); IQ result = (IQ)collector.nextResult(50000); // Stop queuing results collector.cancel(); System.out.println("result.getType () = " + result.toXML()); }
@Override public Message receive(long timeout) { // The filter of our packetCollector should make sure that we receive only // Message instances here return (Message) packetCollector.nextResult(timeout); }
private void cleanup() { dataCollector.cancel(); connection.removePacketListener(this); }
/** * Creates a new packet collector for this connection. A packet filter determines * which packets will be accumulated by the collector. A PacketCollector is * more suitable to use than a {@link PacketListener} when you need to wait for * a specific result. * * @param packetFilter the packet filter to use. * @return a new packet collector. */ public PacketCollector createPacketCollector(PacketFilter packetFilter) { PacketCollector collector = new PacketCollector(this, packetFilter); // Add the collector to the list of active collectors. collectors.add(collector); return collector; }
/** * Processes a packet after it's been fully parsed by looping through the installed * packet collectors and listeners and letting them examine the packet to see if * they are a match with the filter. * * @param packet the packet to process. */ private void processPacket(Packet packet) { if (packet == null) { return; } // Loop through all collectors and notify the appropriate ones. for (PacketCollector collector : connection.getPacketCollectors()) { collector.processPacket(packet); } // Deliver the incoming packet to listeners. listenerExecutor.submit(new ListenerNotification(packet)); }
/** * Get a new STUN Server Address and port from the server. * If a error occurs or the server don't support STUN Service, null is returned. * * @param connection * @return the STUN server address * @throws NotConnectedException */ public static STUN getSTUNServer(XMPPConnection connection) throws NotConnectedException { if (!connection.isConnected()) { return null; } STUN stunPacket = new STUN(); stunPacket.setTo(DOMAIN + "." + connection.getServiceName()); PacketCollector collector = connection.createPacketCollectorAndSend(stunPacket); STUN response = (STUN) collector.nextResult(); // Cancel the collector. collector.cancel(); return response; }
/** * Returns the next available message in the chat. The method call will block * (not return) until a message is available. * * @return the next message. */ public Message nextMessage() { return (Message)messageCollector.nextResult(); }