public class NetResourcesController extends Object
It controls the numbers of opened connections and the network bandwidth. By default, there are no limits on the network resources usage.
When an application tries to perform a network operation (open/read/write), the controller checks if a network limit setting is defined for the application and denies the operation if its execution will lead to exceeding one of the limits.
Constructor and Description |
---|
NetResourcesController()
Instantiates a network resource controller.
|
Modifier and Type | Method and Description |
---|---|
int |
getMaxOpenedConnections() |
Bandwidth |
getNetworkMaxBandwidth(Subnet subnet) |
Socket[] |
getOpenedConnections()
Returns the current opened connections.
|
void |
onEnd(SandboxedModule module,
CloseSocket closeSocket,
boolean withSuccess)
Called when the execution of the given close socket action is finished.
|
void |
onEnd(SandboxedModule module,
OpenSocket openSocket,
boolean withSuccess)
Called when the execution of the given open socket action is finished.
|
void |
onEnd(SandboxedModule module,
ReadSocket readSocket,
int nbBytesRead)
Called when the execution of the given read socket action is finished.
|
void |
onEnd(SandboxedModule module,
WriteSocket writeSocket,
boolean withSuccess)
Called when the execution of the given write socket action is finished.
|
void |
onStart(SandboxedModule module,
CloseSocket closeSocket)
Called when the execution of the close socket action is about to start.
|
void |
onStart(SandboxedModule module,
OpenSocket openSocket)
Called when the execution of the open socket action is about to start.
|
int |
onStart(SandboxedModule module,
ReadSocket readSocket)
Called when the execution of the read socket action is about to start.
|
void |
onStart(SandboxedModule module,
WriteSocket writeSocket)
Called when the execution of the write socket action is about to start.
|
void |
reset()
Resets the controller.
|
void |
setMaxBandwidth(Subnet subnet,
Bandwidth bandwidth)
Sets the maximum bandwidth for the given subnet.
|
void |
setMaxOpenedConnections(int maxOpenedConnections)
Sets the maximum number of network connections allowed to be opened.
|
public NetResourcesController()
public int getMaxOpenedConnections()
@Nullable public Bandwidth getNetworkMaxBandwidth(Subnet subnet)
subnet
- the subnet for which the bandwidth was set.public Socket[] getOpenedConnections()
public void onEnd(SandboxedModule module, CloseSocket closeSocket, boolean withSuccess)
module
- the module which performs the given close socket action.closeSocket
- the close socket action.withSuccess
- true if the execution of the action was ended with success; false otherwise.public void onEnd(SandboxedModule module, OpenSocket openSocket, boolean withSuccess)
module
- the module which performs the given open socket action.openSocket
- the open socket action.withSuccess
- true if the execution of the action was ended with success; false otherwise.public void onEnd(SandboxedModule module, ReadSocket readSocket, int nbBytesRead)
module
- the module which performs the given read socket action.readSocket
- the read socket action.nbBytesRead
- number of bytes actually read.public void onEnd(SandboxedModule module, WriteSocket writeSocket, boolean withSuccess)
module
- the module which performs the given write socket action.writeSocket
- the write socket action.withSuccess
- true if the execution of the action was ended with success; false otherwise.public void onStart(SandboxedModule module, CloseSocket closeSocket) throws SecurityException
It checks if the action is allowed to be executed.
module
- the module which performs the action.closeSocket
- the close socket action.SecurityException
- if the action is not allowed to be performed.public void onStart(SandboxedModule module, OpenSocket openSocket) throws SecurityException
It checks if the action is allowed to be executed.
module
- the module which performs the action.openSocket
- the open socket action.SecurityException
- if the action is not allowed to be performed.public int onStart(SandboxedModule module, ReadSocket readSocket) throws SecurityException
It checks if the action is allowed to be executed and throttles (delays) it if needed.
module
- the module that performs the action.readSocket
- the read socket action.SecurityException
- if the action is not allowed to be performed.public void onStart(SandboxedModule module, WriteSocket writeSocket) throws SecurityException
It checks if the action is allowed to be executed and throttles (delays) it if needed.
module
- the module that performs the action.writeSocket
- the write socket action.SecurityException
- if the action is not allowed to be performed.public void reset()
public void setMaxBandwidth(Subnet subnet, Bandwidth bandwidth)
Note that if a maximum bandwidth is already assigned for the subnet, this new maximum bandwidth will override the previous one.
subnet
- the subnet for which the bandwidth is set.bandwidth
- the maximum bandwidth to set.public void setMaxOpenedConnections(int maxOpenedConnections)
maxOpenedConnections
- the maximum number of network connections allowed. A negative value means there is no limit.