Class NetResourcesController


  • public class NetResourcesController
    extends java.lang.Object
    The network resources controller.

    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 Detail

      • NetResourcesController

        public NetResourcesController()
        Instantiates a network resource controller.
    • Method Detail

      • reset

        public void reset()
        Resets the controller.
      • onStart

        public void onStart​(SandboxedModule module,
                            OpenSocket openSocket)
                     throws java.lang.SecurityException
        Called when the execution of the open socket action is about to start.

        It checks if the action is allowed to be executed.

        Parameters:
        module - the module which performs the action.
        openSocket - the open socket action.
        Throws:
        java.lang.SecurityException - if the action is not allowed to be performed.
      • onEnd

        public void onEnd​(SandboxedModule module,
                          OpenSocket openSocket,
                          boolean withSuccess)
        Called when the execution of the given open socket action is finished.
        Parameters:
        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.
      • onStart

        public void onStart​(SandboxedModule module,
                            CloseSocket closeSocket)
                     throws java.lang.SecurityException
        Called when the execution of the close socket action is about to start.

        It checks if the action is allowed to be executed.

        Parameters:
        module - the module which performs the action.
        closeSocket - the close socket action.
        Throws:
        java.lang.SecurityException - if the action is not allowed to be performed.
      • onEnd

        public void onEnd​(SandboxedModule module,
                          CloseSocket closeSocket,
                          boolean withSuccess)
        Called when the execution of the given close socket action is finished.
        Parameters:
        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.
      • onStart

        public int onStart​(SandboxedModule module,
                           ReadSocket readSocket)
                    throws java.lang.SecurityException
        Called when the execution of the read socket action is about to start.

        It checks if the action is allowed to be executed and throttles (delays) it if needed.

        Parameters:
        module - the module that performs the action.
        readSocket - the read socket action.
        Returns:
        the number of bytes read.
        Throws:
        java.lang.SecurityException - if the action is not allowed to be performed.
      • onEnd

        public void onEnd​(SandboxedModule module,
                          ReadSocket readSocket,
                          int nbBytesRead)
        Called when the execution of the given read socket action is finished.
        Parameters:
        module - the module which performs the given read socket action.
        readSocket - the read socket action.
        nbBytesRead - number of bytes actually read.
      • onStart

        public void onStart​(SandboxedModule module,
                            WriteSocket writeSocket)
                     throws java.lang.SecurityException
        Called when the execution of the write socket action is about to start.

        It checks if the action is allowed to be executed and throttles (delays) it if needed.

        Parameters:
        module - the module that performs the action.
        writeSocket - the write socket action.
        Throws:
        java.lang.SecurityException - if the action is not allowed to be performed.
      • onEnd

        public void onEnd​(SandboxedModule module,
                          WriteSocket writeSocket,
                          boolean withSuccess)
        Called when the execution of the given write socket action is finished.
        Parameters:
        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.
      • setMaxBandwidth

        public void setMaxBandwidth​(Subnet subnet,
                                    Bandwidth bandwidth)
        Sets the maximum bandwidth for the given subnet.

        Note that if a maximum bandwidth is already assigned for the subnet, this new maximum bandwidth will override the previous one.

        Parameters:
        subnet - the subnet for which the bandwidth is set.
        bandwidth - the maximum bandwidth to set.
      • setMaxOpenedConnections

        public void setMaxOpenedConnections​(int maxOpenedConnections)
        Sets the maximum number of network connections allowed to be opened.
        Parameters:
        maxOpenedConnections - the maximum number of network connections allowed. A negative value means there is no limit.
      • getOpenedConnections

        public java.net.Socket[] getOpenedConnections()
        Returns the current opened connections.
        Returns:
        the current opened connections.
      • getMaxOpenedConnections

        public int getMaxOpenedConnections()
        Returns:
        the maximum number of network connections allowed. A negative value means there is no limit.
      • getNetworkMaxBandwidth

        @Nullable
        public Bandwidth getNetworkMaxBandwidth​(Subnet subnet)
        Parameters:
        subnet - the subnet for which the bandwidth was set.
        Returns:
        the maximum network bandwidth authorized for this module.