Remove singleton instances once the client is finished
This can prevent unwanted behavior to happen because of missing initialization
This commit is contained in:
parent
f9fce08e6c
commit
a3b5c94d65
|
@ -139,6 +139,7 @@ public class TCPClient extends StatefulTransportLayerClient {
|
|||
getInStream().close();
|
||||
getOutStream().close();
|
||||
getTcpSocketToServer().close();
|
||||
releaseInstance();
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (IOException e) {
|
||||
getLogger().error("Error occurred while trying to close TCP socket to server", e);
|
||||
|
@ -148,6 +149,10 @@ public class TCPClient extends StatefulTransportLayerClient {
|
|||
}
|
||||
}
|
||||
|
||||
private static void releaseInstance() {
|
||||
uniqueTCPClientInstance = null;
|
||||
}
|
||||
|
||||
public Socket getTcpSocketToServer() {
|
||||
return tcpSocketToServer;
|
||||
}
|
||||
|
|
|
@ -211,6 +211,7 @@ public class TLSClient extends StatefulTransportLayerClient {
|
|||
getInStream().close();
|
||||
getOutStream().close();
|
||||
getTlsSocketToServer().close();
|
||||
releaseInstance();
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (IOException e) {
|
||||
getLogger().error("Error occurred while trying to close TCP socket to server", e);
|
||||
|
@ -220,6 +221,10 @@ public class TLSClient extends StatefulTransportLayerClient {
|
|||
}
|
||||
}
|
||||
|
||||
private static void releaseInstance() {
|
||||
uniqueTLSClientInstance = null;
|
||||
}
|
||||
|
||||
|
||||
public SSLSocket getTlsSocketToServer() {
|
||||
return tlsSocketToServer;
|
||||
|
|
|
@ -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;
|
||||
|
@ -106,6 +106,13 @@ public class UDPClient {
|
|||
|
||||
|
||||
public static UDPClient getInstance() {
|
||||
if (uniqueUDPClientInstance == null) {
|
||||
synchronized (UDPClient.class) {
|
||||
if (uniqueUDPClientInstance == null) {
|
||||
uniqueUDPClientInstance = new UDPClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
return uniqueUDPClientInstance;
|
||||
}
|
||||
|
||||
|
@ -144,6 +151,11 @@ public class UDPClient {
|
|||
public void stop() {
|
||||
getSocketToUDPServer().close();
|
||||
getLogger().debug("UDP client stopped");
|
||||
releaseInstance();
|
||||
}
|
||||
|
||||
private static void releaseInstance() {
|
||||
uniqueUDPClientInstance = null;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue