use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class AbstractXMPPConnection method firePacketSendingListeners.
/**
* Process all stanza listeners for sending stanzas.
* <p>
* Compared to {@link #firePacketInterceptors(Stanza)}, the listeners will be invoked in a new thread.
* </p>
*
* @param sendTopLevelStreamElement the top level stream element which just got send.
*/
// TODO: Rename to fireElementSendingListeners().
@SuppressWarnings("javadoc")
protected void firePacketSendingListeners(final TopLevelStreamElement sendTopLevelStreamElement) {
if (debugger != null) {
debugger.onOutgoingStreamElement(sendTopLevelStreamElement);
}
if (!(sendTopLevelStreamElement instanceof Stanza)) {
return;
}
Stanza packet = (Stanza) sendTopLevelStreamElement;
final List<StanzaListener> listenersToNotify = new LinkedList<>();
synchronized (sendListeners) {
for (ListenerWrapper listenerWrapper : sendListeners.values()) {
if (listenerWrapper.filterMatches(packet)) {
listenersToNotify.add(listenerWrapper.getListener());
}
}
}
if (listenersToNotify.isEmpty()) {
return;
}
// Notify in a new thread, because we can
asyncGo(new Runnable() {
@Override
public void run() {
for (StanzaListener listener : listenersToNotify) {
try {
listener.processStanza(packet);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Sending listener threw exception", e);
continue;
}
}
}
});
}
use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class StanzaCollectorTest method verifyRollover.
@Test
public void verifyRollover() throws InterruptedException {
StanzaCollector collector = createTestStanzaCollector(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(10));
}
use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class FromMatchesFilterTest method fullCompareMatchingEntityFullJid.
@Test
public void fullCompareMatchingEntityFullJid() {
FromMatchesFilter filter = FromMatchesFilter.createFull(FULL_JID1_R1);
Stanza packet = StanzaBuilder.buildMessage().build();
packet.setFrom(FULL_JID1_R1);
assertTrue(filter.accept(packet));
packet.setFrom(BASE_JID1);
assertFalse(filter.accept(packet));
packet.setFrom(FULL_JID1_R2);
assertFalse(filter.accept(packet));
packet.setFrom(BASE_JID2);
assertFalse(filter.accept(packet));
packet.setFrom(FULL_JID2);
assertFalse(filter.accept(packet));
packet.setFrom(BASE_JID3);
assertFalse(filter.accept(packet));
}
use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class FromMatchesFilterTest method bareCompareMatchingBaseJid.
@Test
public void bareCompareMatchingBaseJid() {
FromMatchesFilter filter = FromMatchesFilter.createBare(BASE_JID1);
Stanza packet = StanzaBuilder.buildMessage().build();
packet.setFrom(BASE_JID1);
assertTrue(filter.accept(packet));
packet.setFrom(FULL_JID1_R1);
assertTrue(filter.accept(packet));
packet.setFrom(FULL_JID1_R2);
assertTrue(filter.accept(packet));
packet.setFrom(BASE_JID2);
assertFalse(filter.accept(packet));
packet.setFrom(FULL_JID2);
assertFalse(filter.accept(packet));
packet.setFrom(BASE_JID3);
assertFalse(filter.accept(packet));
}
use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class FromMatchesFilterTest method bareCompareMatchingEntityFullJid.
@Test
public void bareCompareMatchingEntityFullJid() {
FromMatchesFilter filter = FromMatchesFilter.createBare(FULL_JID1_R1);
Stanza packet = StanzaBuilder.buildMessage().build();
packet.setFrom(BASE_JID1);
assertTrue(filter.accept(packet));
packet.setFrom(FULL_JID1_R1);
assertTrue(filter.accept(packet));
packet.setFrom(FULL_JID1_R2);
assertTrue(filter.accept(packet));
packet.setFrom(BASE_JID2);
assertFalse(filter.accept(packet));
packet.setFrom(FULL_JID2);
assertFalse(filter.accept(packet));
packet.setFrom(BASE_JID3);
assertFalse(filter.accept(packet));
}
Aggregations