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 <[email protected]>
1 parent 05aacfb commit 8e040c7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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
import com.mirth.connect.util.messagewriter.EncryptionType;
132132
import com.mirth.connect.util.messagewriter.MessageWriterOptions;
133133

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

136140
public static final int MAX_QUERY_PARAM_COLLECTION_SIZE = 100;
137141

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

319+
@Override
315320
public void close() {
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
public String getProperty(String group, String name) throws ClientException {
26762680
return getServlet(ConfigurationServletInterface.class).getProperty(group, name);
26772681
}
2678-
}
2682+
}

0 commit comments

Comments
 (0)