Package org.apache.flink.runtime.util
Class ResourceCounter
java.lang.Object
org.apache.flink.runtime.util.ResourceCounter
Counter for
ResourceProfiles. This class is immutable.
ResourceCounter contains a set of ResourceProfiles and their
associated counts. The counts are always positive (> 0).
-
Method Summary
Modifier and TypeMethodDescriptionadd(Map<ResourceProfile, Integer> increment) Adds the given increment to this resource counter value and returns the resulting value.add(ResourceProfile resourceProfile, int increment) Adds increment to the count of resourceProfile and returns the new value.add(ResourceCounter increment) Adds increment to this resource counter value and returns the resulting value.booleancontainsResource(ResourceProfile resourceProfile) Checks whether resourceProfile is contained in this counter.static ResourceCounterempty()Creates an empty resource counter.booleanintgetResourceCount(ResourceProfile resourceProfile) Number of resources with the givenResourceProfile.Gets all storedResourceProfiles.Gets the stored resources and their counts.Computes the total resources in this counter.intComputes the total number of resources in this counter.inthashCode()booleanisEmpty()Checks whether the resource counter is empty.subtract(Map<ResourceProfile, Integer> decrement) Subtracts decrement from this resource counter value and returns the new value.subtract(ResourceProfile resourceProfile, int decrement) Subtracts decrement from the count of the given resourceProfile and returns the new value.subtract(ResourceCounter decrement) Subtracts decrement from this resource counter value and returns the new value.toString()static ResourceCounterwithResource(ResourceProfile resourceProfile, int count) Creates a resource counter with the given resourceProfile and its count.static ResourceCounterwithResources(Map<ResourceProfile, Integer> resources) Creates a resource counter with the specified set of resources.
-
Method Details
-
getResourceCount
Number of resources with the givenResourceProfile.- Parameters:
resourceProfile- resourceProfile for which to look up the count- Returns:
- number of resources with the given resourceProfile or
0if the resource profile does not exist
-
getTotalResourceCount
public int getTotalResourceCount()Computes the total number of resources in this counter.- Returns:
- the total number of resources in this counter
-
getTotalResource
Computes the total resources in this counter.- Returns:
- the total resources in this counter
-
add
Adds increment to this resource counter value and returns the resulting value.- Parameters:
increment- increment to add to this resource counter value- Returns:
- new ResourceCounter containing the result of the addition
-
add
Adds the given increment to this resource counter value and returns the resulting value.- Parameters:
increment- increment ot add to this resource counter value- Returns:
- new ResourceCounter containing the result of the addition
-
add
Adds increment to the count of resourceProfile and returns the new value.- Parameters:
resourceProfile- resourceProfile to which to add incrementincrement- increment is the number by which to increase the resourceProfile- Returns:
- new ResourceCounter containing the result of the addition
-
subtract
Subtracts decrement from this resource counter value and returns the new value.- Parameters:
decrement- decrement to subtract from this resource counter- Returns:
- new ResourceCounter containing the new value
-
subtract
Subtracts decrement from this resource counter value and returns the new value.- Parameters:
decrement- decrement to subtract from this resource counter- Returns:
- new ResourceCounter containing the new value
-
subtract
Subtracts decrement from the count of the given resourceProfile and returns the new value.- Parameters:
resourceProfile- resourceProfile from which to subtract decrementdecrement- decrement is the number by which to decrease resourceProfile- Returns:
- new ResourceCounter containing the new value
-
getResourcesWithCount
Gets the stored resources and their counts. The counts are guaranteed to be positive (> 0).- Returns:
- collection of
ResourceProfileand count pairs
-
containsResource
Checks whether resourceProfile is contained in this counter.- Parameters:
resourceProfile- resourceProfile to check whether it is contained- Returns:
trueif the counter has a positive count for the given resourceProfile; otherwisefalse
-
getResources
Gets all storedResourceProfiles.- Returns:
- collection of stored
ResourceProfiles
-
isEmpty
public boolean isEmpty()Checks whether the resource counter is empty.- Returns:
trueif the counter does not contain any counts; otherwisefalse
-
empty
Creates an empty resource counter.- Returns:
- empty resource counter
-
withResources
Creates a resource counter with the specified set of resources.- Parameters:
resources- resources with which to initialize the resource counter- Returns:
- ResourceCounter which contains the specified set of resources
-
withResource
Creates a resource counter with the given resourceProfile and its count.- Parameters:
resourceProfile- resourceProfile for the given countcount- count of the given resourceProfile- Returns:
- ResourceCounter which contains the specified resourceProfile and its count
-
equals
-
hashCode
public int hashCode() -
toString
-