mirror of
https://github.com/fluencelabs/jabci
synced 2025-05-12 07:17:18 +00:00
make counting of open sockets possible + last time a socket was opened
This commit is contained in:
parent
a8f9ee0d28
commit
c0346319e0
@ -56,6 +56,8 @@ public class TSocket extends ASocket {
|
|||||||
public static final String CONSENSUS_SOCKET = "-Consensus";
|
public static final String CONSENSUS_SOCKET = "-Consensus";
|
||||||
|
|
||||||
private final HashSet<SocketHandler> runningThreads = new HashSet<>();
|
private final HashSet<SocketHandler> runningThreads = new HashSet<>();
|
||||||
|
|
||||||
|
private long lastConnectedSocketTime = -1;
|
||||||
|
|
||||||
private boolean continueRunning = true;
|
private boolean continueRunning = true;
|
||||||
|
|
||||||
@ -78,6 +80,7 @@ public class TSocket extends ASocket {
|
|||||||
try (ServerSocket serverSocket = new ServerSocket(portNumber)) {
|
try (ServerSocket serverSocket = new ServerSocket(portNumber)) {
|
||||||
while (continueRunning) {
|
while (continueRunning) {
|
||||||
Socket clientSocket = serverSocket.accept();
|
Socket clientSocket = serverSocket.accept();
|
||||||
|
lastConnectedSocketTime = System.currentTimeMillis();
|
||||||
String socketName = socketNameForCount(++socketcount);
|
String socketName = socketNameForCount(++socketcount);
|
||||||
TSOCKET_LOG.debug("starting socket with: {}", socketName);
|
TSOCKET_LOG.debug("starting socket with: {}", socketName);
|
||||||
SocketHandler t = (socketName != null) ? new SocketHandler(clientSocket, socketName) : new SocketHandler(clientSocket);
|
SocketHandler t = (socketName != null) ? new SocketHandler(clientSocket, socketName) : new SocketHandler(clientSocket);
|
||||||
@ -122,7 +125,17 @@ public class TSocket extends ASocket {
|
|||||||
runningThreads.clear();
|
runningThreads.clear();
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @return the amount of connected sockets, this should usually be 3: info,mempool and consensus
|
||||||
|
*/
|
||||||
|
public int sizeOfConnectedABCISockets() {
|
||||||
|
return runningThreads.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastConnectedTime() {
|
||||||
|
return lastConnectedSocketTime;
|
||||||
|
}
|
||||||
|
|
||||||
class SocketHandler extends Thread {
|
class SocketHandler extends Thread {
|
||||||
|
|
||||||
private final Socket socket;
|
private final Socket socket;
|
||||||
@ -168,6 +181,7 @@ public class TSocket extends ASocket {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
|
runningThreads.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user