Module java.base

Class ResourceType


  • public class ResourceType
    extends Object
    Enumeration of Constraint's type.

    class is used instead of enum to provide extensibility. Implementation of resource management can define its resource type. Below is an example of extension ResourceType:

         public class MyResourceType extends ResourceType {
             public final static ResourceType CPU_CFS = new MyResourceType();
    
             public MyResourceType() {}
         }
     

    CPU_CFS is an instance of ResourceType, so it can be used wherever ResourceType is handled.

    The descriptions and parameters of each public final static value need to be documented in detail.

    • Field Detail

      • CPU_PERCENT

        public static final ResourceType CPU_PERCENT
        Throttling the CPU usage by CPU percentage.

        param #1: CPU usage measured in a percentage granularity. The value ranges from 0 to CPU_COUNT * 100. For example, 150 means that ResourceContainer can use up to 1.5 CPU cores.

      • HEAP_RETAINED

        public static final ResourceType HEAP_RETAINED
        Throttling the max heap usage.

        param #1: maximum heap size in bytes

    • Constructor Detail

      • ResourceType

        protected ResourceType​(String name)
    • Method Detail

      • newConstraint

        public Constraint newConstraint​(long... values)
        Creates a Constraint with this ResourceType and the given values.
        Parameters:
        values - constraint values
        Returns:
        newly-created Constraint
        Throws:
        IllegalArgumentException - when parameter check fails
      • validate

        protected void validate​(long... values)
                         throws IllegalArgumentException
        Checks the validity of parameters. Since a long [] is used to express the configuration, a length and range check is required.

        Each ResourceType instance can implement its own validate() method through Override, for example:

         public final static ResourceType MY_RESOURCE =
             new ResourceType() {
                 protected void validate(long[] values) throws IllegalArgumentException {
                      // the check logic
                 }
             };
         
        Parameters:
        values - parameter value
        Throws:
        IllegalArgumentException - if validation failed