mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 09:09:38 +02: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
|
@ -192,9 +192,9 @@ public final class IoTDataManager extends IoTManager {
|
|||
doneCollector.nextResult();
|
||||
}
|
||||
finally {
|
||||
// Ensure that the two collectors are canceled in any case.
|
||||
// Canceling dataCollector will also cancel the doneCollector since it is configured as dataCollector's
|
||||
// collector to reset.
|
||||
dataCollector.cancel();
|
||||
doneCollector.cancel();
|
||||
}
|
||||
|
||||
int collectedCount = dataCollector.getCollectedCount();
|
||||
|
|
|
@ -546,17 +546,15 @@ public final class MamManager extends Manager {
|
|||
|
||||
StanzaCollector.Configuration resultCollectorConfiguration = StanzaCollector.newConfiguration()
|
||||
.setStanzaFilter(new MamResultFilter(mamQueryIq)).setCollectorToReset(mamFinIQCollector);
|
||||
StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration);
|
||||
|
||||
try {
|
||||
StanzaCollector cancelledResultCollector;
|
||||
try (StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration)) {
|
||||
connection.sendStanza(mamQueryIq);
|
||||
mamFinIQ = mamFinIQCollector.nextResultOrThrow();
|
||||
} finally {
|
||||
mamFinIQCollector.cancel();
|
||||
resultCollector.cancel();
|
||||
cancelledResultCollector = resultCollector;
|
||||
}
|
||||
|
||||
return new MamQueryPage(resultCollector, mamFinIQ);
|
||||
return new MamQueryPage(cancelledResultCollector, mamFinIQ);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue