Package org.cloudbus.cloudsim.resources
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
-
Field Summary
Fields inherited from class org.cloudbus.cloudsim.resources.ResourceAbstract
capacity
Fields inherited from interface org.cloudbus.cloudsim.resources.ResourceManageable
NULL
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addCapacity
(long capacityToAdd) Try to add a given amount to theresource capacity
.boolean
allocateResource
(long amountToAllocate) Try to allocate a given amount of the resource, reducing that amount from the total available resource.long
De-allocates all allocated resources, restoring the total available resource to the resource capacity.boolean
deallocateAndRemoveResource
(long amountToDeallocate) Try to deallocate a given amount of the resource and then remove such amount from the total capacity.boolean
deallocateResource
(long amountToDeallocate) Try to deallocate a given amount of the resource.long
Gets the amount of the resource that is available (free).boolean
removeCapacity
(long capacityToRemove) Try to remove a given amount to theresource capacity
.boolean
setAllocatedResource
(long newTotalAllocatedResource) Try to set the current total amount of allocated resource, changing it to the given value.protected final boolean
setAvailableResource
(long newAvailableResource) Sets the given amount as available resource.boolean
setCapacity
(long newCapacity) Try to set theresource capacity
.protected boolean
sumAvailableResource
(long amountToSum) Sum a given amount (negative or positive) of available (free) resource to the total available resource.boolean
sumCapacity
(long amountToSum) Sum a given amount (negative or positive) of capacity to the total resource capacity.toString()
Methods inherited from class org.cloudbus.cloudsim.resources.ResourceAbstract
getAllocatedResource, getCapacity, getUnit, isAmountAvailable, isAmountAvailable, isResourceAmountBeingUsed, isSuitable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.cloudbus.cloudsim.resources.Resource
getAllocatedResource, getPercentUtilization, getUnit, isAmountAvailable, isAmountAvailable, isAmountAvailable, isFull, isSubClassOf
Methods inherited from interface org.cloudbus.cloudsim.resources.ResourceCapacity
getCapacity
Methods inherited from interface org.cloudbus.cloudsim.resources.ResourceManageable
allocateResource, deallocateResource, isResourceAmountBeingUsed, isSuitable, setAllocatedResource
-
Constructor Details
-
ResourceManageableAbstract
-
-
Method Details
-
setCapacity
public boolean setCapacity(long newCapacity) Description copied from interface:ResourceManageable
Try to set theresource capacity
.- Specified by:
setCapacity
in interfaceResourceManageable
- 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 interfaceResourceManageable
- 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 theresource capacity
.- Specified by:
addCapacity
in interfaceResourceManageable
- 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 theresource capacity
.- Specified by:
removeCapacity
in interfaceResourceManageable
- 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 interfaceResource
- 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 interfaceResourceManageable
- 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 interfaceResourceManageable
- 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 interfaceResourceManageable
- 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 interfaceResourceManageable
- 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 interfaceResourceManageable
- Returns:
- the amount of resource freed
-
toString
-