Class ResourceManageableAbstract

java.lang.Object
org.cloudbus.cloudsim.resources.ResourceAbstract
org.cloudbus.cloudsim.resources.ResourceManageableAbstract
All Implemented Interfaces:
Resource, ResourceCapacity, ResourceManageable
Direct Known Subclasses:
Bandwidth, PeSimple, Processor, Ram, SimpleStorage

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 Details

    • ResourceManageableAbstract

      public ResourceManageableAbstract(long capacity, String unit)
  • Method Details

    • setCapacity

      public boolean setCapacity(long newCapacity)
      Description copied from interface: ResourceManageable
      Try to set the resource capacity.
      Specified by:
      setCapacity in interface ResourceManageable
      Parameters:
      newCapacity - the new resource capacity
      Returns:
      true if capacity is greater or equal to 0 and capacity greater or equal to current allocated resource, false otherwise
      See Also:
    • 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
    • addCapacity

      public boolean addCapacity(long capacityToAdd)
      Description copied from interface: ResourceManageable
      Try to add a given amount to the resource capacity.
      Specified by:
      addCapacity in interface ResourceManageable
      Parameters:
      capacityToAdd - the amount to add
      Returns:
      true if capacityToAdd is greater than 0, false otherwise
      See Also:
    • 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 is greater than 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:
    • 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 is greater than 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 is greater than 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 is greater than 0 and there is enough resource to deallocate, false otherwise
    • deallocateAllResources

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

      public String toString()
      Overrides:
      toString in class Object