Class ResourceManageableAbstract

  • All Implemented Interfaces:
    Resource, ResourceCapacity, ResourceManageable
    Direct Known Subclasses:
    Bandwidth, PeSimple, Processor, Ram, Storage

    public abstract class ResourceManageableAbstract
    extends ResourceAbstract
    implements ResourceManageable
    A class that represents simple resources such as RAM, CPU, Bandwidth or Pe. It stores, for instance, the resource capacity and amount of free available resource.

    The class is abstract just to ensure there will be an specific subclass for each kind of resource, allowing to differentiate, for example, a RAM Resource from a BW Resource. The VM class also relies on this differentiation for generically getting a required resource.

    Since:
    CloudSim Plus 1.0
    Author:
    Uros Cibej, Anthony Sulistio, Manoel Campos da Silva Filho
    • Constructor Detail

      • ResourceManageableAbstract

        public ResourceManageableAbstract​(long capacity)
    • Method Detail

      • sumCapacity

        public boolean sumCapacity​(long amountToSum)
        Description copied from interface: ResourceManageable
        Sum a given amount (negative or positive) of capacity to the total resource capacity.
        Specified by:
        sumCapacity in interface ResourceManageable
        Parameters:
        amountToSum - the amount to sum in the current total capacity. If given a positive number, increases the total capacity; otherwise, decreases it.
        Returns:
        true if the total capacity was changed; false otherwise
      • removeCapacity

        public boolean removeCapacity​(long capacityToRemove)
        Description copied from interface: ResourceManageable
        Try to remove a given amount to the resource capacity.
        Specified by:
        removeCapacity in interface ResourceManageable
        Parameters:
        capacityToRemove - the amount to remove
        Returns:
        true if capacityToRemove > 0, the current allocated resource is less or equal to the expected new capacity and the capacity to remove is not higher than the current capacity; false otherwise
        See Also:
        Resource.getAllocatedResource()
      • sumAvailableResource

        protected boolean sumAvailableResource​(long amountToSum)
        Sum a given amount (negative or positive) of available (free) resource to the total available resource.
        Parameters:
        amountToSum - the amount to sum in the current total available resource. If given a positive number, increases the total available resource; otherwise, decreases the total available resource.
        Returns:
        true if the total available resource was changed; false otherwise
      • setAvailableResource

        protected final boolean setAvailableResource​(long newAvailableResource)
        Sets the given amount as available resource.
        Parameters:
        newAvailableResource - the new amount of available resource to set
        Returns:
        true if availableResource > 0 and availableResource <= capacity, false otherwise
      • getAvailableResource

        public long getAvailableResource()
        Description copied from interface: Resource
        Gets the amount of the resource that is available (free).
        Specified by:
        getAvailableResource in interface Resource
        Returns:
        the amount of available resource
      • allocateResource

        public boolean allocateResource​(long amountToAllocate)
        Description copied from interface: ResourceManageable
        Try to allocate a given amount of the resource, reducing that amount from the total available resource.
        Specified by:
        allocateResource in interface ResourceManageable
        Parameters:
        amountToAllocate - the amount of resource to be allocated
        Returns:
        true if amountToAllocate > 0 and there is enough resource to allocate, false otherwise
      • setAllocatedResource

        public boolean setAllocatedResource​(long newTotalAllocatedResource)
        Description copied from interface: ResourceManageable
        Try to set the current total amount of allocated resource, changing it to the given value. It doesn't increase the current allocated resource by the given amount, instead, it changes the allocated resource to that specified amount.
        Specified by:
        setAllocatedResource in interface ResourceManageable
        Parameters:
        newTotalAllocatedResource - the new total amount of resource to allocate, changing the allocate resource to this new amount.
        Returns:
        true if newTotalAllocatedResource is not negative and there is enough resource to allocate, false otherwise
      • deallocateAndRemoveResource

        public boolean deallocateAndRemoveResource​(long amountToDeallocate)
        Description copied from interface: ResourceManageable
        Try to deallocate a given amount of the resource and then remove such amount from the total capacity. If the given amount is greater than the total allocated resource, all the resource will be deallocated and that amount will be removed from the total capacity.
        Specified by:
        deallocateAndRemoveResource in interface ResourceManageable
        Parameters:
        amountToDeallocate - the amount of resource to be deallocated and then removed from the total capacity
        Returns:
        true if amountToDeallocate > 0 and there is enough resource to deallocate, false otherwise
      • deallocateResource

        public boolean deallocateResource​(long amountToDeallocate)
        Description copied from interface: ResourceManageable
        Try to deallocate a given amount of the resource.
        Specified by:
        deallocateResource in interface ResourceManageable
        Parameters:
        amountToDeallocate - the amount of resource to be deallocated
        Returns:
        true if amountToDeallocate > 0 and there is enough resource to deallocate, false otherwise
      • deallocateAllResources

        public long deallocateAllResources()
        Description copied from interface: ResourceManageable
        Deallocates all allocated resources, restoring the total available resource to the resource capacity.
        Specified by:
        deallocateAllResources in interface ResourceManageable
        Returns:
        the amount of resource freed