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"));
}
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());
}
}
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();
}
}
Aggregations