mirror of
https://github.com/fluencelabs/jabci
synced 2025-03-16 19:20:50 +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";
|
||||
|
||||
private final HashSet<SocketHandler> runningThreads = new HashSet<>();
|
||||
|
||||
private long lastConnectedSocketTime = -1;
|
||||
|
||||
private boolean continueRunning = true;
|
||||
|
||||
@ -78,6 +80,7 @@ public class TSocket extends ASocket {
|
||||
try (ServerSocket serverSocket = new ServerSocket(portNumber)) {
|
||||
while (continueRunning) {
|
||||
Socket clientSocket = serverSocket.accept();
|
||||
lastConnectedSocketTime = System.currentTimeMillis();
|
||||
String socketName = socketNameForCount(++socketcount);
|
||||
TSOCKET_LOG.debug("starting socket with: {}", socketName);
|
||||
SocketHandler t = (socketName != null) ? new SocketHandler(clientSocket, socketName) : new SocketHandler(clientSocket);
|
||||
@ -122,7 +125,17 @@ public class TSocket extends ASocket {
|
||||
runningThreads.clear();
|
||||
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 {
|
||||
|
||||
private final Socket socket;
|
||||
@ -168,6 +181,7 @@ public class TSocket extends ASocket {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
runningThreads.remove(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user