Package org.apache.flink.runtime.util
Class ResourceCounter
- java.lang.Object
-
- org.apache.flink.runtime.util.ResourceCounter
-
public final class ResourceCounter extends Object
Counter forResourceProfiles
. This class is immutable.ResourceCounter contains a set of
ResourceProfiles
and their associated counts. The counts are always positive (> 0).
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ResourceCounter
add(Map<ResourceProfile,Integer> increment)
Adds the given increment to this resource counter value and returns the resulting value.ResourceCounter
add(ResourceProfile resourceProfile, int increment)
Adds increment to the count of resourceProfile and returns the new value.ResourceCounter
add(ResourceCounter increment)
Adds increment to this resource counter value and returns the resulting value.boolean
containsResource(ResourceProfile resourceProfile)
Checks whether resourceProfile is contained in this counter.static ResourceCounter
empty()
Creates an empty resource counter.boolean
equals(Object o)
int
getResourceCount(ResourceProfile resourceProfile)
Number of resources with the givenResourceProfile
.Set<ResourceProfile>
getResources()
Gets all storedResourceProfiles
.Collection<Map.Entry<ResourceProfile,Integer>>
getResourcesWithCount()
Gets the stored resources and their counts.ResourceProfile
getTotalResource()
Computes the total resources in this counter.int
getTotalResourceCount()
Computes the total number of resources in this counter.int
hashCode()
boolean
isEmpty()
Checks whether the resource counter is empty.ResourceCounter
subtract(Map<ResourceProfile,Integer> decrement)
Subtracts decrement from this resource counter value and returns the new value.ResourceCounter
subtract(ResourceProfile resourceProfile, int decrement)
Subtracts decrement from the count of the given resourceProfile and returns the new value.ResourceCounter
subtract(ResourceCounter decrement)
Subtracts decrement from this resource counter value and returns the new value.String
toString()
static ResourceCounter
withResource(ResourceProfile resourceProfile, int count)
Creates a resource counter with the given resourceProfile and its count.static ResourceCounter
withResources(Map<ResourceProfile,Integer> resources)
Creates a resource counter with the specified set of resources.
-
-
-
Method Detail
-
getResourceCount
public int getResourceCount(ResourceProfile resourceProfile)
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
0
if 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
public ResourceProfile getTotalResource()
Computes the total resources in this counter.- Returns:
- the total resources in this counter
-
add
public ResourceCounter add(ResourceCounter increment)
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
public ResourceCounter add(Map<ResourceProfile,Integer> increment)
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
public ResourceCounter add(ResourceProfile resourceProfile, int increment)
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
public ResourceCounter subtract(ResourceCounter decrement)
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
public ResourceCounter subtract(Map<ResourceProfile,Integer> decrement)
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
public ResourceCounter subtract(ResourceProfile resourceProfile, int decrement)
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
public Collection<Map.Entry<ResourceProfile,Integer>> getResourcesWithCount()
Gets the stored resources and their counts. The counts are guaranteed to be positive (> 0).- Returns:
- collection of
ResourceProfile
and count pairs
-
containsResource
public boolean containsResource(ResourceProfile resourceProfile)
Checks whether resourceProfile is contained in this counter.- Parameters:
resourceProfile
- resourceProfile to check whether it is contained- Returns:
true
if the counter has a positive count for the given resourceProfile; otherwisefalse
-
getResources
public Set<ResourceProfile> getResources()
Gets all storedResourceProfiles
.- Returns:
- collection of stored
ResourceProfiles
-
isEmpty
public boolean isEmpty()
Checks whether the resource counter is empty.- Returns:
true
if the counter does not contain any counts; otherwisefalse
-
empty
public static ResourceCounter empty()
Creates an empty resource counter.- Returns:
- empty resource counter
-
withResources
public static ResourceCounter withResources(Map<ResourceProfile,Integer> resources)
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
public static ResourceCounter withResource(ResourceProfile resourceProfile, int count)
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
-
-