Skip to content

Commit 8e040c7

Browse files
committed
Make Client AutoCloseable and close() idempotent
- Make AutoClosable so it can be used in try-with-resources - Removed null check for serverConnection since it cannot be null - Do not shutdown serverConnection or close JAX-RS client if this client is already closed. Signed-off-by: Tony Germano <tony@germano.name>
1 parent 05aacfb commit 8e040c7

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎server/src/com/mirth/connect/client/core/Client.java‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@
131131
importcom.mirth.connect.util.messagewriter.EncryptionType;
132132
importcom.mirth.connect.util.messagewriter.MessageWriterOptions;
133133

134-
publicclassClientimplementsUserServletInterface, ConfigurationServletInterface, ChannelServletInterface, ChannelGroupServletInterface, ChannelStatusServletInterface, ChannelStatisticsServletInterface, EngineServletInterface, MessageServletInterface, EventServletInterface, AlertServletInterface, CodeTemplateServletInterface, DatabaseTaskServletInterface, UsageServletInterface, ExtensionServletInterface {
134+
publicclassClientimplementsUserServletInterface, ConfigurationServletInterface, ChannelServletInterface,
135+
ChannelGroupServletInterface, ChannelStatusServletInterface, ChannelStatisticsServletInterface,
136+
EngineServletInterface, MessageServletInterface, EventServletInterface, AlertServletInterface,
137+
CodeTemplateServletInterface, DatabaseTaskServletInterface, UsageServletInterface, ExtensionServletInterface,
138+
AutoCloseable {
135139

136140
publicstaticfinalintMAX_QUERY_PARAM_COLLECTION_SIZE = 100;
137141

@@ -312,9 +316,9 @@ public void setRecorder(InvocationHandlerRecorder recorder) {
312316
this.recorder = recorder;
313317
}
314318

319+
@Override
315320
publicvoidclose() {
316-
closed.set(true);
317-
if (serverConnection != null) {
321+
if (!closed.getAndSet(true)) {
318322
serverConnection.shutdown();
319323
client.close();
320324
}
@@ -2675,4 +2679,4 @@ public void setPluginProperties(String extensionName, Properties properties, boo
26752679
publicStringgetProperty(Stringgroup, Stringname) throwsClientException {
26762680
returngetServlet(ConfigurationServletInterface.class).getProperty(group, name);
26772681
}
2678-
}
2682+
}

0 commit comments

Comments
 (0)