StanzaCollector.Configuration dataCollectorConfiguration = StanzaCollector.newConfiguration().setStanzaFilter( dataFilter).setCollectorToReset(doneCollector); StanzaCollector dataCollector = connection.createStanzaCollector(dataCollectorConfiguration); connection.createStanzaCollectorAndSend(iotDataRequest).nextResultOrThrow(); doneCollector.nextResult(); dataCollector.cancel(); doneCollector.cancel(); int collectedCount = dataCollector.getCollectedCount(); List<IoTFieldsExtension> res = new ArrayList<>(collectedCount); for (int i = 0; i < collectedCount; i++) { Message message = dataCollector.pollResult(); IoTFieldsExtension iotFieldsExtension = IoTFieldsExtension.from(message); res.add(iotFieldsExtension);
protected void performActionAndWaitUntilStanzaReceived(Runnable action, XMPPConnection connection, StanzaFilter filter) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { StanzaCollector.Configuration configuration = StanzaCollector.newConfiguration().setStanzaFilter( filter).setSize(1); StanzaCollector collector = connection.createStanzaCollector(configuration); try { action.run(); collector.nextResultOrThrow(timeout); } finally { collector.cancel(); } }
StanzaCollector.Configuration messageCollectorConfiguration = StanzaCollector.newConfiguration().setStanzaFilter(PACKET_FILTER).setCollectorToReset(resultCollector); StanzaCollector messageCollector = connection.createStanzaCollector(messageCollectorConfiguration); resultCollector.nextResultOrThrow(); messageCollector.cancel(); messages = new ArrayList<>(messageCollector.getCollectedCount()); Message message; while ((message = messageCollector.pollResult()) != null) { messages.add(message); messageCollector.cancel();
@Override public StanzaCollector createStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet) throws NotConnectedException, InterruptedException { StanzaCollector.Configuration configuration = StanzaCollector.newConfiguration() .setStanzaFilter(packetFilter) .setRequest(packet); // Create the packet collector before sending the packet StanzaCollector packetCollector = createStanzaCollector(configuration); try { // Now we can send the packet as the collector has been created sendStanza(packet); } catch (InterruptedException | NotConnectedException | RuntimeException e) { packetCollector.cancel(); throw e; } return packetCollector; }
/** * 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 * @throws InterruptedException */ @SuppressWarnings("deprecation") public static STUN getSTUNServer(XMPPConnection connection) throws NotConnectedException, InterruptedException { if (!connection.isConnected()) { return null; } STUN stunPacket = new STUN(); stunPacket.setTo(DOMAIN + "." + connection.getXMPPServiceDomain()); StanzaCollector collector = connection.createStanzaCollectorAndSend(stunPacket); STUN response = collector.nextResult(); // Cancel the collector. collector.cancel(); return response; }
@Override public <I extends IQ> I sendIqRequestAndWaitForResponse(IQ request) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { StanzaCollector collector = createStanzaCollectorAndSend(request); IQ resultResponse = collector.nextResultOrThrow(); @SuppressWarnings("unchecked") I concreteResultResponse = (I) resultResponse; return concreteResultResponse; }
/** * Returns the next available message in the chat. The method call will * block (not return) until a message is available. * * @return the next message. * @throws InterruptedException */ public Message nextMessage() throws InterruptedException { return messageCollector.nextResult(); }
StanzaCollector messageCollector = connection.createStanzaCollector(messageFilter); try { connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); message = messageCollector.nextResult(); if (message != null) { messages.add(message); messageCollector.cancel();
when(collector.nextResult(anyInt())).thenAnswer(answer); when(collector.nextResult()).thenAnswer(answer); Answer<Stanza> answerOrThrow = new Answer<Stanza>() { @Override when(collector.nextResultOrThrow()).thenAnswer(answerOrThrow); when(collector.nextResultOrThrow(anyLong())).thenAnswer(answerOrThrow);
/** * Remove the connection callbacks used by this MUC Light from the * connection. */ private void removeConnectionCallbacks() { connection.removeSyncStanzaListener(messageListener); if (messageCollector != null) { messageCollector.cancel(); messageCollector = null; } }
@Override public StanzaCollector createStanzaCollector(StanzaFilter packetFilter) { StanzaCollector.Configuration configuration = StanzaCollector.newConfiguration().setStanzaFilter(packetFilter); return createStanzaCollector(configuration); }
/** * Polls for and returns the next message. * * @return the next message if one is immediately available */ public Message pollMessage() { return messageCollector.pollResult(); }
/** * Return a list of all collected stanzas. This method must be invoked after the collector has been cancelled. * * @return a list of collected stanzas. * @since 4.3.0 */ public List<Stanza> getCollectedStanzasAfterCancelled() { if (!cancelled) { throw new IllegalStateException("Stanza collector was not yet cancelled"); } if (collectedCache == null) { collectedCache = new ArrayList<>(getCollectedCount()); resultQueue.drainTo(collectedCache); } return collectedCache; }
/** * Get a new RTPBridge Candidate from the server. * If a error occurs or the server don't support RTPBridge Service, null is returned. * * @param connection * @param sessionID * @return the new RTPBridge * @throws NotConnectedException * @throws InterruptedException */ @SuppressWarnings("deprecation") public static RTPBridge getRTPBridge(XMPPConnection connection, String sessionID) throws NotConnectedException, InterruptedException { if (!connection.isConnected()) { return null; } RTPBridge rtpPacket = new RTPBridge(sessionID); rtpPacket.setTo(RTPBridge.NAME + "." + connection.getXMPPServiceDomain()); StanzaCollector collector = connection.createStanzaCollectorAndSend(rtpPacket); RTPBridge response = collector.nextResult(); // Cancel the collector. collector.cancel(); return response; }
/** * Activates the SOCKS5 Bytestream by sending an XMPP SOCKS5 Bytestream activation stanza to the * SOCKS5 proxy. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException * @throws SmackException if there was no response from the server. */ private void activate() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Bytestream activate = createStreamHostActivation(); // if activation fails #nextResultOrThrow() throws an exception connection.get().createStanzaCollectorAndSend(activate).nextResultOrThrow(); }
/** * Returns the next available message in the chat. * * @param timeout * the maximum amount of time to wait for the next message. * @return the next message, or null if the timeout elapses without a * message becoming available. * @throws InterruptedException */ public Message nextMessage(long timeout) throws InterruptedException { return messageCollector.nextResult(timeout); }
private MamQueryPage queryArchivePage(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { final XMPPConnection connection = getAuthenticatedConnectionOrThrow(); MamFinIQ mamFinIQ; StanzaCollector mamFinIQCollector = connection.createStanzaCollector(new IQReplyFilter(mamQueryIq, connection)); StanzaCollector.Configuration resultCollectorConfiguration = StanzaCollector.newConfiguration() .setStanzaFilter(new MamResultFilter(mamQueryIq)).setCollectorToReset(mamFinIQCollector); StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration); try { connection.sendStanza(mamQueryIq); mamFinIQ = mamFinIQCollector.nextResultOrThrow(); } finally { mamFinIQCollector.cancel(); resultCollector.cancel(); } return new MamQueryPage(resultCollector, mamFinIQ); }
/** * Remove the connection callbacks (PacketListener, PacketInterceptor, StanzaCollector) used by this MUC from the * connection. */ private void removeConnectionCallbacks() { connection.removeSyncStanzaListener(messageListener); connection.removeSyncStanzaListener(presenceListener); connection.removeSyncStanzaListener(subjectListener); connection.removeSyncStanzaListener(declinesListener); connection.removeStanzaInterceptor(presenceInterceptor); if (messageCollector != null) { messageCollector.cancel(); messageCollector = null; } }
@Override public StanzaCollector createStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet) throws NotConnectedException, InterruptedException { StanzaCollector.Configuration configuration = StanzaCollector.newConfiguration() .setStanzaFilter(packetFilter) .setRequest(packet); // Create the packet collector before sending the packet StanzaCollector packetCollector = createStanzaCollector(configuration); try { // Now we can send the packet as the collector has been created sendStanza(packet); } catch (InterruptedException | NotConnectedException | RuntimeException e) { packetCollector.cancel(); throw e; } return packetCollector; }
protected TestStanzaCollector(XMPPConnection conection, StanzaFilter packetFilter, int size) { super(conection, StanzaCollector.newConfiguration().setStanzaFilter(packetFilter).setSize(size)); } }