Interface Resource

  • All Known Implementing Classes:
    ContinuousResource, DiscreteResource

    @Beta
    public interface Resource
    An object that represent a resource in a network. A Resource can represents path-like hierarchical structure with its ID. An ID of resource is composed of a sequence of elementary resources that are not globally identifiable. A Resource can be globally identifiable by its ID. Two types of resource are considered. One is discrete type and the other is continuous type. Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and MPLS label are examples of discrete type resource. Continuous type resource is a resource whose amount is measured as a continuous value. Bandwidth is an example of continuous type resource. A double value is associated with a continuous type value. Users of this class must keep the semantics of resources regarding the hierarchical structure. For example, resource, Device:1/Port:1/VLAN ID:100, is valid, but resource, VLAN ID:100/Device:1/Port:1 is not valid because a link is not a sub-component of a VLAN ID.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      ContinuousResource child​(java.lang.Class<?> child, double value)
      Returns a child resource of this instance with specifying a child object and value.
      DiscreteResource child​(java.lang.Object child)
      Returns a child resource of this instance with specifying the child object.
      ResourceId id()
      Returns the ID of this resource.
      boolean isSubTypeOf​(java.lang.Class<?> ancestor)
      Checks if the type of this instance is the sub-type of the specified type.
      boolean isTypeOf​(java.lang.Class<?> type)
      Checks if the type of this instance is the specified type.
      java.util.Optional<DiscreteResource> parent()
      Returns the parent resource of this instance.
      java.lang.String simpleTypeName()
      Returns the simple type name of this resource.
      <T> java.util.Optional<T> valueAs​(java.lang.Class<T> type)
      Returns value interpreted as the specified type.
    • Method Detail

      • id

        ResourceId id()
        Returns the ID of this resource.
        Returns:
        the ID of this resource
      • simpleTypeName

        java.lang.String simpleTypeName()
        Returns the simple type name of this resource. Example:
        Resource: DeviceId:1/PortNumber:1/VlanId:200
        Simple type name: VlanId
        Returns:
        the simple type name of this resource
      • isTypeOf

        boolean isTypeOf​(java.lang.Class<?> type)
        Checks if the type of this instance is the specified type.
        Parameters:
        type - type of resource to be checked
        Returns:
        true if this resource is the type of the specified type. Otherwise, false.
      • isSubTypeOf

        boolean isSubTypeOf​(java.lang.Class<?> ancestor)
        Checks if the type of this instance is the sub-type of the specified type.
        Parameters:
        ancestor - type of resource to be checked.
        Returns:
        true if this resource is under the resource whose type is the given type.
      • valueAs

        <T> java.util.Optional<T> valueAs​(java.lang.Class<T> type)
        Returns value interpreted as the specified type. If the specified type is incompatible with the underlying value, an empty instance is returned.
        Type Parameters:
        T - type of the return value
        Parameters:
        type - class instance specifying the type of return value
        Returns:
        the value of this resource as the specified type. If type mismatches, returns an empty instance.
      • parent

        java.util.Optional<DiscreteResource> parent()
        Returns the parent resource of this instance. E.g. if this resource is Link:1/VLAN ID:100, the return value is the resource for Link:1.
        Returns:
        the parent resource of this instance. If there is no parent, empty instance will be returned.
      • child

        DiscreteResource child​(java.lang.Object child)
        Returns a child resource of this instance with specifying the child object. It is not allowed that a continuous type resource has a child. If the instance is ContinuousResource, UnsupportedOperationException is thrown. If the given object is a Class instance, IllegalArgumentException is thrown.
        Parameters:
        child - child object
        Returns:
        a child resource
        Throws:
        java.lang.IllegalArgumentException - if the given object is a Class instance.
      • child

        ContinuousResource child​(java.lang.Class<?> child,
                                 double value)
        Returns a child resource of this instance with specifying a child object and value. It is not allowed that a continuous type resource has a child. If the instance is ContinuousResource, UnsupportedOperationException is thrown.
        Parameters:
        child - child object
        value - value
        Returns:
        a child resource