Resource

public interface Resource extends ResourceCapacity

An interface to represent a physical or virtual resource (like RAM, CPU or Bandwidth) that doesn’t provide direct features to change allocated amount of resource. Objects that directly implement this interface are supposed to define the capacity and amount of allocated resource in their constructors.

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

Fields

NULL

Resource NULL

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

Methods

getAllocatedResource

long getAllocatedResource()

Gets the current total amount of allocated resource.

Returns:amount of allocated resource

getAvailableResource

long getAvailableResource()

Gets the amount of the resource that is available (free).

Returns:the amount of available resource

getPercentUtilization

double getPercentUtilization()

Gets the current percentage of resource utilization in scale from 0 to 1. It is the percentage of the total resource capacity that is currently allocated.

Returns:current resource utilization (allocation) percentage in scale from 0 to 1

isAmountAvailable

boolean isAmountAvailable(Resource resource)

Checks if there the capacity required for the given resource is available (free) at this resource. This method is commonly used to check if there is a specific amount of resource free at a physical resource (this Resource instance) that is required by a virtualized resource (the given Resource).

Parameters:
  • resource – the resource to check if its capacity is available at the current resource
Returns:

true if the capacity required by the given Resource is free; false otherwise

See also: .isAmountAvailable(long)

isAmountAvailable

boolean isAmountAvailable(long amountToCheck)

Checks if there is a specific amount of resource available (free).

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

true if the specified amount is free; false otherwise

isAmountAvailable

boolean isAmountAvailable(double amountToCheck)

Checks if there is a specific amount of resource available (free), where such amount is a double value that will be converted to long.

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

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

true if the specified amount is free; false otherwise

See also: .isAmountAvailable(long)

isFull

boolean isFull()

Checks if the resource is full or not.

Returns:true if the storage is full, false otherwise

isObjectSubClassOf

static boolean isObjectSubClassOf(Object object, Class classWanted)

Checks if a given object is instance of a given class.

Parameters:
  • object – the object to check
  • classWanted – the class to verify if the object is instance of
Returns:

true if the object is instance of the given class, false otherwise

isObjectSubClassOf

boolean isObjectSubClassOf(Class classWanted)

Checks if this object is instance of a given class.

Parameters:
  • classWanted – the class to verify if the object is instance of
Returns:

true if the object is instance of the given class, false otherwise