use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class EnhancedDebugger method addReadPacketToTable.
/**
* Adds the received stanza(/packet) detail to the messages table.
*
* @param dateFormatter the SimpleDateFormat to use to format Dates
* @param packet the read stanza(/packet) to add to the table
*/
private void addReadPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
String messageType;
Jid from = packet.getFrom();
String type = "";
Icon packetTypeIcon;
receivedPackets++;
if (packet instanceof IQ) {
packetTypeIcon = iqPacketIcon;
messageType = "IQ Received (class=" + packet.getClass().getName() + ")";
type = ((IQ) packet).getType().toString();
receivedIQPackets++;
} else if (packet instanceof Message) {
packetTypeIcon = messagePacketIcon;
messageType = "Message Received";
type = ((Message) packet).getType().toString();
receivedMessagePackets++;
} else if (packet instanceof Presence) {
packetTypeIcon = presencePacketIcon;
messageType = "Presence Received";
type = ((Presence) packet).getType().toString();
receivedPresencePackets++;
} else {
packetTypeIcon = unknownPacketTypeIcon;
messageType = packet.getClass().getName() + " Received";
receivedOtherPackets++;
}
// Check if we need to remove old rows from the table to keep memory consumption low
if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
messagesTable.removeRow(0);
}
messagesTable.addRow(new Object[] { formatXML(packet.toXML().toString()), dateFormatter.format(new Date()), packetReceivedIcon, packetTypeIcon, messageType, packet.getStanzaId(), type, "", from });
// Update the statistics table
updateStatistics();
}
});
}
use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class EnhancedDebugger method addSentPacketToTable.
/**
* Adds the sent stanza(/packet) detail to the messages table.
*
* @param dateFormatter the SimpleDateFormat to use to format Dates
* @param packet the sent stanza(/packet) to add to the table
*/
private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
String messageType;
Jid to = packet.getTo();
String type = "";
Icon packetTypeIcon;
sentPackets++;
if (packet instanceof IQ) {
packetTypeIcon = iqPacketIcon;
messageType = "IQ Sent (class=" + packet.getClass().getName() + ")";
type = ((IQ) packet).getType().toString();
sentIQPackets++;
} else if (packet instanceof Message) {
packetTypeIcon = messagePacketIcon;
messageType = "Message Sent";
type = ((Message) packet).getType().toString();
sentMessagePackets++;
} else if (packet instanceof Presence) {
packetTypeIcon = presencePacketIcon;
messageType = "Presence Sent";
type = ((Presence) packet).getType().toString();
sentPresencePackets++;
} else {
packetTypeIcon = unknownPacketTypeIcon;
messageType = packet.getClass().getName() + " Sent";
sentOtherPackets++;
}
// Check if we need to remove old rows from the table to keep memory consumption low
if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
messagesTable.removeRow(0);
}
messagesTable.addRow(new Object[] { formatXML(packet.toXML().toString()), dateFormatter.format(new Date()), packetSentIcon, packetTypeIcon, messageType, packet.getStanzaId(), type, to, "" });
// Update the statistics table
updateStatistics();
}
});
}
use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class IoTDataManager method requestMomentaryValuesReadOut.
/**
* Try to read out a things momentary values.
*
* @param jid the full JID of the thing to read data from.
* @return a list with the read out data.
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<IoTFieldsExtension> requestMomentaryValuesReadOut(EntityFullJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
final XMPPConnection connection = connection();
final int seqNr = nextSeqNr.incrementAndGet();
IoTDataRequest iotDataRequest = new IoTDataRequest(seqNr, true);
iotDataRequest.setTo(jid);
StanzaFilter doneFilter = new IoTFieldsExtensionFilter(seqNr, true);
StanzaFilter dataFilter = new IoTFieldsExtensionFilter(seqNr, false);
// Setup the IoTFieldsExtension message collectors before sending the IQ to avoid a data race.
StanzaCollector doneCollector = connection.createStanzaCollector(doneFilter);
StanzaCollector.Configuration dataCollectorConfiguration = StanzaCollector.newConfiguration().setStanzaFilter(dataFilter).setCollectorToReset(doneCollector);
StanzaCollector dataCollector = connection.createStanzaCollector(dataCollectorConfiguration);
try {
connection.createStanzaCollectorAndSend(iotDataRequest).nextResultOrThrow();
// Wait until a message with an IoTFieldsExtension and the done flag comes in.
doneCollector.nextResult();
} finally {
// Ensure that the two collectors are canceled in any case.
dataCollector.cancel();
doneCollector.cancel();
}
int collectedCount = dataCollector.getCollectedCount();
List<IoTFieldsExtension> res = new ArrayList<>(collectedCount);
for (int i = 0; i < collectedCount; i++) {
Message message = dataCollector.pollResult();
IoTFieldsExtension iotFieldsExtension = IoTFieldsExtension.from(message);
res.add(iotFieldsExtension);
}
return res;
}
use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class FromMatchesFilterTest method bareCompareMatchingEntityFullJid.
@Test
public void bareCompareMatchingEntityFullJid() {
FromMatchesFilter filter = FromMatchesFilter.createBare(FULL_JID1_R1);
Stanza packet = new Message();
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.Message in project Smack by igniterealtime.
the class FromMatchesFilterTest method fullCompareMatchingEntityFullJid.
@Test
public void fullCompareMatchingEntityFullJid() {
FromMatchesFilter filter = FromMatchesFilter.createFull(FULL_JID1_R1);
Stanza packet = new Message();
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));
}
Aggregations