mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-18 17:01:08 +01:00
Use try-with-resources where possible
and make StanzaCollector implement AutoCloseable.
This commit is contained in:
parent
e98d42790a
commit
658fd08d20
10 changed files with 30 additions and 69 deletions
|
|
@ -165,8 +165,7 @@ public class OfflineMessageManager {
|
|||
}
|
||||
});
|
||||
int pendingNodes = nodes.size();
|
||||
StanzaCollector messageCollector = connection.createStanzaCollector(messageFilter);
|
||||
try {
|
||||
try (StanzaCollector messageCollector = connection.createStanzaCollector(messageFilter)) {
|
||||
connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
|
||||
// Collect the received offline messages
|
||||
Message message;
|
||||
|
|
@ -181,10 +180,6 @@ public class OfflineMessageManager {
|
|||
}
|
||||
} while (message != null && pendingNodes > 0);
|
||||
}
|
||||
finally {
|
||||
// Stop queuing offline messages
|
||||
messageCollector.cancel();
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
|
|
@ -206,10 +201,9 @@ public class OfflineMessageManager {
|
|||
|
||||
StanzaCollector resultCollector = connection.createStanzaCollectorAndSend(request);
|
||||
StanzaCollector.Configuration messageCollectorConfiguration = StanzaCollector.newConfiguration().setStanzaFilter(PACKET_FILTER).setCollectorToReset(resultCollector);
|
||||
StanzaCollector messageCollector = connection.createStanzaCollector(messageCollectorConfiguration);
|
||||
|
||||
List<Message> messages;
|
||||
try {
|
||||
try (StanzaCollector messageCollector = connection.createStanzaCollector(messageCollectorConfiguration)) {
|
||||
resultCollector.nextResultOrThrow();
|
||||
// Be extra safe, cancel the message collector right here so that it does not collector
|
||||
// other messages that eventually match (although I've no idea how this could happen in
|
||||
|
|
@ -221,11 +215,6 @@ public class OfflineMessageManager {
|
|||
messages.add(message);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
// Ensure that the message collector is canceled even if nextResultOrThrow threw. It
|
||||
// doesn't matter if we cancel the message collector twice
|
||||
messageCollector.cancel();
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue