/** * Creates a new stanza ID filter using the specified stanza's ID. * * @param stanza the stanza which the ID is taken from. */ public StanzaIdFilter(Stanza stanza) { this(stanza.getStanzaId()); }
/** * Get the Stanza ID. * @return the stanza id. * @deprecated use {@link #getStanzaId()} instead. */ @Deprecated public String getPacketID() { return getStanzaId(); }
/** * Creates a new stanza ID filter using the specified packet's ID. * * @param packet the stanza which the ID is taken from. * @deprecated use {@link StanzaIdFilter#StanzaIdFilter(Stanza)} instead. */ @Deprecated public PacketIDFilter(Stanza packet) { this(packet.getStanzaId()); }
@Override public boolean accept(Stanza packet) { return packetID.equals(packet.getStanzaId()); }
@Override public boolean accept(Stanza stanza) { return stanzaId.equals(stanza.getStanzaId()); }
private OnceForThisStanza(XMPPTCPConnection connection, Stanza packet) { this.connection = connection; this.id = packet.getStanzaId(); if (StringUtils.isNullOrEmpty(id)) { throw new IllegalArgumentException("Stanza ID must be set"); } }
public StreamManagementCounterError(long handledCount, long previousServerHandlerCount, long ackedStanzaCount, List<Stanza> ackedStanzas) { super( "There was an error regarding the Stream Management counters. Server reported " + handledCount + " handled stanzas, which means that the " + ackedStanzaCount + " recently send stanzas by client are now acked by the server. But Smack had only " + ackedStanzas.size() + " to acknowledge. The stanza id of the last acked outstanding stanza is " + (ackedStanzas.isEmpty() ? "<no acked stanzas>" : ackedStanzas.get(ackedStanzas.size() - 1).getStanzaId())); this.handledCount = handledCount; this.previousServerHandledCount = previousServerHandlerCount; this.ackedStanzaCount = ackedStanzaCount; this.outstandingStanzasCount = ackedStanzas.size(); this.ackedStanzas = Collections.unmodifiableList(ackedStanzas); }
@Override public boolean accept(Stanza packet) { String otherId = packet.getStanzaId(); if (StringUtils.isNullOrEmpty(otherId)) { return false; } if (id.equals(otherId)) { connection.removeRequestAckPredicate(this); return true; } return false; }
@Override public void run() { for (Stanza ackedStanza : ackedStanzas) { for (StanzaListener listener : stanzaAcknowledgedListeners) { try { listener.processStanza(ackedStanza); } catch (InterruptedException | NotConnectedException | NotLoggedInException e) { LOGGER.log(Level.FINER, "Received exception", e); } } String id = ackedStanza.getStanzaId(); if (StringUtils.isNullOrEmpty(id)) { continue; } StanzaListener listener = stanzaIdAcknowledgedListeners.remove(id); if (listener != null) { try { listener.processStanza(ackedStanza); } catch (InterruptedException | NotConnectedException | NotLoggedInException e) { LOGGER.log(Level.FINER, "Received exception", e); } } } } });
/** * Set the stanza id if none is set. * * @return the stanza id. * @since 4.2 */ public String setStanzaId() { if (!hasStanzaIdSet()) { setStanzaId(StanzaIdUtil.newStanzaId()); } return getStanzaId(); }
String id = ackedStanza.getStanzaId(); if (id != null && stanzaIdAcknowledgedListeners.containsKey(id)) { atLeastOneStanzaAcknowledgedListener = true;
protected Stanza(Stanza p) { id = p.getStanzaId(); to = p.getTo(); from = p.getFrom(); error = p.error; // Copy extensions for (ExtensionElement pe : p.getExtensions()) { addExtension(pe); } }
public static Version createResultFor(Stanza request, Version version) { Version result = new Version(version); result.setStanzaId(request.getStanzaId()); result.setTo(request.getFrom()); return result; } }
/** * Add to, from, id and 'xml:lang' attributes * * @param xml the {@link XmlStringBuilder}. * @param enclosingNamespace the enclosing XML namespace. * @return the set namespace for this stanza. */ protected String addCommonAttributes(XmlStringBuilder xml, String enclosingNamespace) { String namespace; if (enclosingNamespace == null || !enclosingNamespace.equals(StreamOpen.CLIENT_NAMESPACE) || !enclosingNamespace.equals(StreamOpen.SERVER_NAMESPACE)) { namespace = StreamOpen.CLIENT_NAMESPACE; } else { namespace = enclosingNamespace; } xml.xmlnsAttribute(namespace); xml.optAttribute("to", getTo()); xml.optAttribute("from", getFrom()); xml.optAttribute("id", getStanzaId()); xml.xmllangAttribute(getLanguage()); return namespace; }
Stanza stanza = (Stanza) packet; to = stanza.getTo(); stanzaId = stanza.getStanzaId(); } else { to = null;
Stanza stanza = (Stanza) packet; from = stanza.getFrom(); stanzaId = stanza.getStanzaId(); } else { from = null;
@Test public void verifyRollover() throws InterruptedException { TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5); for (int i = 0; i < 6; i++) { Stanza testPacket = new TestPacket(i); collector.processStanza(testPacket); } // Assert that '0' has rolled off assertEquals("1", collector.nextResultBlockForever().getStanzaId()); assertEquals("2", collector.nextResultBlockForever().getStanzaId()); assertEquals("3", collector.nextResultBlockForever().getStanzaId()); assertEquals("4", collector.nextResultBlockForever().getStanzaId()); assertEquals("5", collector.pollResult().getStanzaId()); assertNull(collector.pollResult()); for (int i = 10; i < 15; i++) { Stanza testPacket = new TestPacket(i); collector.processStanza(testPacket); } assertEquals("10", collector.nextResultBlockForever().getStanzaId()); assertEquals("11", collector.nextResultBlockForever().getStanzaId()); assertEquals("12", collector.nextResultBlockForever().getStanzaId()); assertEquals("13", collector.nextResultBlockForever().getStanzaId()); assertEquals("14", collector.pollResult().getStanzaId()); assertNull(collector.pollResult()); assertNull(collector.nextResult(1000)); }
@Override public void sendStanza(Stanza packet) throws NotConnectedException, InterruptedException { super.sendStanza(packet); if (packet instanceof IQ && !timeout) { timeout = false; // Set reply packet to match one being sent. We haven't started the // other thread yet so this is still safe. IQ replyPacket = replyQ.peek(); // If no reply has been set via addIQReply, then we create a simple reply if (replyPacket == null) { replyPacket = IQ.createResultIQ((IQ) packet); replyQ.add(replyPacket); } replyPacket.setStanzaId(packet.getStanzaId()); replyPacket.setTo(packet.getFrom()); if (replyPacket.getType() == null) { replyPacket.setType(Type.result); } new ProcessQueue(replyQ).start(); } }
/** * Creates a new stanza ID filter using the specified stanza's ID. * * @param stanza the stanza which the ID is taken from. */ public StanzaIdFilter(Stanza stanza) { this(stanza.getStanzaId()); }
/** * Get the Stanza ID. * @return the stanza id. * @deprecated use {@link #getStanzaId()} instead. */ @Deprecated public String getPacketID() { return getStanzaId(); }