public class SocketMonitor
extends java.lang.Object
implements java.lang.Runnable
SocketMonitor is responsible for monitoring system (Linux or Windows) sockets.
When a socket is detected as opened or closed, the appropriate information about this socket is added
to the queue of opened or closed sockets, respectively. SocketInfoGenerator class. | Modifier and Type | Field and Description |
|---|---|
private java.util.Hashtable<java.lang.Integer,SocketInfo> |
activeSocketsList
List of sockets, which were opened and they are not closed yet.
|
private boolean |
isStarted
Flag used to determine if the thread is fully started.
|
private static org.apache.log4j.Logger |
log
Used to log different events.
|
private SocketInfoGenerator |
mySocketInfoGenerator
Responsible for monitoring system (Linux or Windows) sockets.
|
private SocketMonitorQueue |
mySocketMonitorQueue
Queue containing information about opened or closed sockets.
|
private java.util.Hashtable<java.lang.Integer,SocketInfo> |
openSocketList
List of sockets which were opened, but they can be either open or closed.
|
private boolean |
runFlag
Flag used to stop the thread.
|
private int |
samplingInterval
Interval between checking if new sockets are opened or closed.
|
private java.lang.Thread |
socketMonitorThread
Thread used by this class.
|
| Constructor and Description |
|---|
SocketMonitor()
Constructs the object.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
findClosedSockets()
Finds all closed sockets by comparing
activeSocketList and openSocketList. |
private void |
findOpenSockets()
Looks for information about open sockets.
|
SocketMonitorQueue |
getSocketMonitorQueue()
Gets the queue containing information about opened and closed sockets.
|
boolean |
isAlive()
Checks if
SocketMonitor is alive. |
void |
run()
Runs the thread in loop.
|
void |
setSamplingInterval(int samplingInterval)
Sets interval between checking if new sockets are opened or closed.
|
void |
start()
Starts the thread.
|
void |
stop()
Stops the thread.
|
private static org.apache.log4j.Logger log
private java.lang.Thread socketMonitorThread
private boolean runFlag
private boolean isStarted
private int samplingInterval
private java.util.Hashtable<java.lang.Integer,SocketInfo> activeSocketsList
private java.util.Hashtable<java.lang.Integer,SocketInfo> openSocketList
private SocketInfoGenerator mySocketInfoGenerator
private SocketMonitorQueue mySocketMonitorQueue
public void start()
public void stop()
public boolean isAlive()
SocketMonitor is alive. It means that: isStarted equals true).
This condition is used to check if the thread is fully started or if it needs more time to start.true if the thread is fully started and operational, false otherwisepublic void run()
run in interface java.lang.Runnableprivate void findOpenSockets()
SocketInfoGenerator.
Next, the information is added both to list of opened sockets and list of active sockets.private void findClosedSockets()
activeSocketList and openSocketList.public void setSamplingInterval(int samplingInterval)
samplingInterval - the interval between checking if new sockets are opened or closedpublic SocketMonitorQueue getSocketMonitorQueue()