Merge pull request #46 from mrbig/master

Remove singleton instances once the client is finished
This commit is contained in:
Marc Mültin 2020-07-23 17:37:51 +01:00 committed by GitHub
commit b5beeca0db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -139,6 +139,7 @@ public class TCPClient extends StatefulTransportLayerClient {
getInStream().close();
getOutStream().close();
getTcpSocketToServer().close();
uniqueTCPClientInstance = null;
Thread.currentThread().interrupt();
} catch (IOException e) {
getLogger().error("Error occurred while trying to close TCP socket to server", e);

View File

@ -220,6 +220,7 @@ public class TLSClient extends StatefulTransportLayerClient {
getInStream().close();
getOutStream().close();
getTlsSocketToServer().close();
uniqueTLSClientInstance = null;
Thread.currentThread().interrupt();
} catch (IOException e) {
getLogger().error("Error occurred while trying to close TCP socket to server", e);

View File

@ -51,7 +51,7 @@ public class UDPClient {
* access the instance variable -> thread safe.
*/
private Logger logger = LogManager.getLogger(this.getClass().getSimpleName());
private static final UDPClient uniqueUDPClientInstance = new UDPClient();
private static UDPClient uniqueUDPClientInstance = new UDPClient();
private int multicastSocketPort;
private Inet6Address multicastAddress;
private MulticastSocket socketToUDPServer;
@ -105,7 +105,10 @@ public class UDPClient {
}
public static UDPClient getInstance() {
public static synchronized UDPClient getInstance() {
if (uniqueUDPClientInstance == null) {
uniqueUDPClientInstance = new UDPClient();
}
return uniqueUDPClientInstance;
}
@ -144,6 +147,7 @@ public class UDPClient {
public void stop() {
getSocketToUDPServer().close();
getLogger().debug("UDP client stopped");
uniqueUDPClientInstance = null;
}