/** * 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; } }
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(); } }
collector.cancel();
/** * 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; }
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); }
messageCollector.cancel();
/** * 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; }
/** * 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; }
result = nextResult(timeout); } finally { cancel();
@SmackIntegrationTest public void testStreamManagement(XMPPTCPConnection conOne, XMPPTCPConnection conTwo) throws InterruptedException, SmackException, IOException, XMPPException { final String body1 = "Hi, what's up? " + testRunId; final String body2 = "Hi, what's up? I've been just instantly shutdown" + testRunId; final String body3 = "Hi, what's up? I've been just resumed" + testRunId; final StanzaCollector collector = conTwo.createStanzaCollector(new AndFilter( MessageWithBodiesFilter.INSTANCE, FromMatchesFilter.createFull(conOne.getUser()))); try { send(body1, conOne, conTwo); assertMessageWithBodyReceived(body1, collector); conOne.instantShutdown(); send(body2, conOne, conTwo); // Reconnect with xep198 conOne.connect().login(); assertMessageWithBodyReceived(body2, collector); send(body3, conOne, conTwo); assertMessageWithBodyReceived(body3, collector); } finally { collector.cancel(); } }
/** * Check if the server support RTPBridge Service. * * @param connection * @return the RTPBridge * @throws NotConnectedException * @throws InterruptedException */ @SuppressWarnings("deprecation") public static RTPBridge relaySession(XMPPConnection connection, String sessionID, String pass, TransportCandidate proxyCandidate, TransportCandidate localCandidate) throws NotConnectedException, InterruptedException { if (!connection.isConnected()) { return null; } RTPBridge rtpPacket = new RTPBridge(sessionID, RTPBridge.BridgeAction.change); rtpPacket.setTo(RTPBridge.NAME + "." + connection.getXMPPServiceDomain()); rtpPacket.setType(Type.set); rtpPacket.setPass(pass); rtpPacket.setPortA(localCandidate.getPort()); rtpPacket.setPortB(proxyCandidate.getPort()); rtpPacket.setHostA(localCandidate.getIp()); rtpPacket.setHostB(proxyCandidate.getIp()); // LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort()); StanzaCollector collector = connection.createStanzaCollectorAndSend(rtpPacket); RTPBridge response = collector.nextResult(); // Cancel the collector. collector.cancel(); return response; }
/** * 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; } }
private <R extends OAStanza> R sendOAStanza(XMPPTCPConnection authConnection, OAStanza stanza, Class<R> replyClass, long replyTimeout) { StanzaCollector collector = authConnection.createStanzaCollector(new OAReplyFilter(stanza, authConnection)); messageLock.lock(); try { authConnection.sendStanza(stanza); return replyClass.cast(getNextStanzaSkipContinues(collector, replyTimeout, authConnection)); } catch (InterruptedException | SmackException | XMPPErrorException e) { throw new RuntimeException("Failed communicating with Harmony Hub", e); } finally { messageLock.unlock(); collector.cancel(); } }
private Stanza sendOAStanza(XMPPTCPConnection authConnection, OAStanza stanza, long replyTimeout) { StanzaCollector collector = authConnection .createStanzaCollector(new EmptyIncrementedIdReplyFilter(stanza, authConnection)); messageLock.lock(); try { authConnection.sendStanza(stanza); return getNextStanzaSkipContinues(collector, replyTimeout, authConnection); } catch (InterruptedException | SmackException | XMPPErrorException e) { throw new RuntimeException("Failed communicating with Harmony Hub", e); } finally { messageLock.unlock(); collector.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; }
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); }