Search in sources :

Example 6 with ThreadFilter

use of org.jivesoftware.smack.filter.ThreadFilter in project Smack by igniterealtime.

the class ChatTest method testProperties.

@SuppressWarnings("deprecation")
@SmackIntegrationTest
public void testProperties() throws XmppStringprepException, NotConnectedException, Exception {
    org.jivesoftware.smack.chat.Chat newChat = chatManagerOne.createChat(conTwo.getUser());
    StanzaCollector collector = conTwo.createStanzaCollector(new ThreadFilter(newChat.getThreadID()));
    Message msg = new Message();
    msg.setSubject("Subject of the chat");
    msg.setBody("Body of the chat");
    addProperty(msg, "favoriteColor", "red");
    addProperty(msg, "age", 30);
    addProperty(msg, "distance", 30f);
    addProperty(msg, "weight", 30d);
    addProperty(msg, "male", true);
    addProperty(msg, "birthdate", new Date());
    newChat.sendMessage(msg);
    Message msg2 = (Message) collector.nextResult(2000);
    assertNotNull("No message was received", msg2);
    assertEquals("Subjects are different", msg.getSubject(), msg2.getSubject());
    assertEquals("Bodies are different", msg.getBody(), msg2.getBody());
    assertEquals("favoriteColors are different", getProperty(msg, "favoriteColor"), getProperty(msg2, "favoriteColor"));
    assertEquals("ages are different", getProperty(msg, "age"), getProperty(msg2, "age"));
    assertEquals("distances are different", getProperty(msg, "distance"), getProperty(msg2, "distance"));
    assertEquals("weights are different", getProperty(msg, "weight"), getProperty(msg2, "weight"));
    assertEquals("males are different", getProperty(msg, "male"), getProperty(msg2, "male"));
    assertEquals("birthdates are different", getProperty(msg, "birthdate"), getProperty(msg2, "birthdate"));
}
Also used : Message(org.jivesoftware.smack.packet.Message) ThreadFilter(org.jivesoftware.smack.filter.ThreadFilter) Date(java.util.Date) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 7 with ThreadFilter

use of org.jivesoftware.smack.filter.ThreadFilter in project Smack by igniterealtime.

the class FloodTest method testMessageFlood.

public void testMessageFlood() {
    try {
        Chat chat11 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
        StanzaCollector chat12 = getConnection(1).createStanzaCollector(new ThreadFilter(chat11.getThreadID()));
        Chat chat21 = getConnection(0).getChatManager().createChat(getBareJID(2), null);
        StanzaCollector chat22 = getConnection(2).createStanzaCollector(new ThreadFilter(chat21.getThreadID()));
        Chat chat31 = getConnection(0).getChatManager().createChat(getBareJID(3), null);
        StanzaCollector chat32 = getConnection(3).createStanzaCollector(new ThreadFilter(chat31.getThreadID()));
        for (int i = 0; i < 500; i++) {
            chat11.sendMessage("Hello_1" + i);
            chat21.sendMessage("Hello_2" + i);
            chat31.sendMessage("Hello_3" + i);
        }
        for (int i = 0; i < 500; i++) {
            assertNotNull("Some message was lost (" + i + ")", chat12.nextResult(1000));
            assertNotNull("Some message was lost (" + i + ")", chat22.nextResult(1000));
            assertNotNull("Some message was lost (" + i + ")", chat32.nextResult(1000));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ThreadFilter(org.jivesoftware.smack.filter.ThreadFilter)

Example 8 with ThreadFilter

use of org.jivesoftware.smack.filter.ThreadFilter in project intellij-plugins by JetBrains.

the class JabberTransport method sendXmlMessage.

@Override
public synchronized void sendXmlMessage(User user, final XmlMessage xmlMessage) {
    if (!myUI.connectAndLogin(null)) {
        return;
    }
    final String threadId = getThreadId(user);
    final PacketCollector packetCollector = myFacade.getConnection().createPacketCollector(new ThreadFilter(threadId));
    doSendMessage(xmlMessage, user, threadId);
    if (xmlMessage.needsResponse()) {
        //noinspection HardCodedStringLiteral
        final Runnable responseWaiterRunnable = () -> {
            try {
                processResponse(xmlMessage, packetCollector);
            } finally {
                packetCollector.cancel();
            }
        };
        myIdeFacade.runOnPooledThread(responseWaiterRunnable);
    } else {
        packetCollector.cancel();
    }
}
Also used : ThreadFilter(org.jivesoftware.smack.filter.ThreadFilter)

Aggregations

ThreadFilter (org.jivesoftware.smack.filter.ThreadFilter)8 Message (org.jivesoftware.smack.packet.Message)4 StanzaCollector (org.jivesoftware.smack.StanzaCollector)3 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)2 Chat (org.jivesoftware.smack.Chat)2 Packet (org.jivesoftware.smack.packet.Packet)2 Date (java.util.Date)1 PacketListener (org.jivesoftware.smack.PacketListener)1 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)1 StanzaExtensionFilter (org.jivesoftware.smack.filter.StanzaExtensionFilter)1 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)1