ResourceManageable

public interface ResourceManageable extends Resource

An interface to represent a physical or virtual resource (like RAM, CPU or Bandwidth) with features to manage resource capacity and allocation.

Author:Uros Cibej, Anthony Sulistio, Manoel Campos da Silva Filho

Fields

NULL

ResourceManageable NULL

An attribute that implements the Null Object Design Pattern for ResourceManageable objects.

Methods

addCapacity

boolean addCapacity(long capacityToAdd)

Try to add a given amount to the resource capacity.

Parameters:
  • capacityToAdd – the amount to add
Returns:

true if capacityToAdd > 0, false otherwise

See also: .getAllocatedResource()

allocateResource

boolean allocateResource(long amountToAllocate)

Try to allocate a given amount of the resource, reducing that amount from the total available resource.

Parameters:
  • amountToAllocate – the amount of resource to be allocated
Returns:

true if amountToAllocate > 0 and there is enough resource to allocate, false otherwise

allocateResource

boolean allocateResource(Resource resource)

Try to allocate in this resource, the amount of resource specified by the capacity of the given resource. This method is commonly used to allocate a specific amount from a physical resource (this Resource instance) to a virtualized resource (the given Resource).

Parameters:
  • resource – the resource to try to allocate its capacity from the current resource
Returns:

true if required capacity from the given resource > 0 and there is enough resource to allocate, false otherwise

See also: .allocateResource(long)

deallocateAllResources

long deallocateAllResources()

Deallocates all allocated resources, restoring the total available resource to the resource capacity.

Returns:the amount of resource freed

deallocateAndRemoveResource

boolean deallocateAndRemoveResource(long amountToDeallocate)

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.

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

boolean deallocateResource(Resource resource)

Try to deallocate all the capacity of the given resource from this resource. This method is commonly used to deallocate a specific amount of a physical resource (this Resource instance) that was being used by a virtualized resource (the given Resource).

Parameters:
  • resource – the resource that its capacity will be deallocated
Returns:

true if capacity of the given resource > 0 and there is enough resource to deallocate, false otherwise

See also: .deallocateResource(long)

deallocateResource

boolean deallocateResource(long amountToDeallocate)

Try to deallocate a given amount of the resource.

Parameters:
  • amountToDeallocate – the amount of resource to be deallocated
Returns:

true if amountToDeallocate > 0 and there is enough resource to deallocate, false otherwise

isResourceAmountBeingUsed

boolean isResourceAmountBeingUsed(long amountToCheck)

Checks if there is a specific amount of resource being used.

Parameters:
  • amountToCheck – the amount of resource to check if is used.
Returns:

true if the specified amount is being used; false otherwise

isSuitable

boolean isSuitable(long newTotalAllocatedResource)

Checks if it is possible to change the current allocated resource to a new amount, depending on the available resource remaining.

Parameters:
  • newTotalAllocatedResource – the new total amount of resource to allocate.
Returns:

true, if it is possible to allocate the new total resource; false otherwise

removeCapacity

boolean removeCapacity(long capacityToRemove)

Try to remove a given amount to the resource capacity.

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: .getAllocatedResource()

setAllocatedResource

boolean setAllocatedResource(long newTotalAllocatedResource)

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.

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

setAllocatedResource

boolean setAllocatedResource(double newTotalAllocatedResource)

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.

This method is just a shorthand to avoid explicitly converting a double to long.

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

setCapacity

boolean setCapacity(long newCapacity)

Try to set the resource capacity.

Parameters:
  • newCapacity – the new resource capacity
Returns:

true if capacity >= 0 and capacity >= current allocated resource, false otherwise

See also: .getAllocatedResource()