Package org.onosproject.net.resource
Interface ResourceStore
-
- All Superinterfaces:
Store<ResourceEvent,ResourceStoreDelegate>
@Beta public interface ResourceStore extends Store<ResourceEvent,ResourceStoreDelegate>
Service for storing resource and consumer information.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
allocate(java.util.List<? extends Resource> resources, ResourceConsumer consumer)
Allocates the specified resources to the specified consumer in transactional way.<T> java.util.Collection<Resource>
getAllocatedResources(DiscreteResourceId parent, java.lang.Class<T> cls)
Returns a collection of the resources which are children of the specified parent and whose type is the specified class.java.util.Set<Resource>
getChildResources(DiscreteResourceId parent)
Returns a set of the child resources of the specified parent.<T> java.util.Set<Resource>
getChildResources(DiscreteResourceId parent, java.lang.Class<T> cls)
Returns a set of the child resources of the specified parent and whose type is the specified class.java.util.List<ResourceAllocation>
getResourceAllocations(ResourceId id)
Returns the resource consumers to whom the specified resource is allocated.java.util.Collection<Resource>
getResources(ResourceConsumer consumer)
Returns a collection of the resources allocated to the specified consumer.boolean
isAvailable(Resource resource)
Returns the availability of the specified resource.boolean
register(java.util.List<? extends Resource> resources)
Registers the resources in transactional way.boolean
release(java.util.List<ResourceAllocation> allocations)
Releases the specified allocated resources in transactional way.boolean
unregister(java.util.List<? extends ResourceId> ids)
Unregisters the resources in transactional way.-
Methods inherited from interface org.onosproject.store.Store
hasDelegate, setDelegate, unsetDelegate
-
-
-
-
Method Detail
-
register
boolean register(java.util.List<? extends Resource> resources)
Registers the resources in transactional way. Resource registration must be done before resource allocation. The state after completion of this method is all the resources are registered, or none of the given resources is registered. The whole registration fails when any one of the resource can't be registered.- Parameters:
resources
- resources to be registered- Returns:
- true if the registration succeeds, false otherwise
-
unregister
boolean unregister(java.util.List<? extends ResourceId> ids)
Unregisters the resources in transactional way. The state after completion of this method is all the resources are unregistered, or none of the given resources is unregistered. The whole unregistration fails when any one of the resource can't be unregistered.- Parameters:
ids
- resources to be unregistered- Returns:
- true if the registration succeeds, false otherwise
-
allocate
boolean allocate(java.util.List<? extends Resource> resources, ResourceConsumer consumer)
Allocates the specified resources to the specified consumer in transactional way. The state after completion of this method is all the resources are allocated to the consumer, or no resource is allocated to the consumer. The whole allocation fails when any one of the resource can't be allocated.- Parameters:
resources
- resources to be allocatedconsumer
- resource consumer which the resources are allocated to- Returns:
- true if the allocation succeeds, false otherwise.
-
release
boolean release(java.util.List<ResourceAllocation> allocations)
Releases the specified allocated resources in transactional way. The state after completion of this method is all the resources are released from the consumer, or no resource is released. The whole release fails when any one of the resource can't be released. The size of the list of resources and that of consumers must be equal. The resource and consumer with the same position from the head of each list correspond to each other.- Parameters:
allocations
- allocaitons to be released- Returns:
- true if succeeds, otherwise false
-
getResourceAllocations
java.util.List<ResourceAllocation> getResourceAllocations(ResourceId id)
Returns the resource consumers to whom the specified resource is allocated. The return value is a list having only one element when the given resource is discrete type. The return value may have multiple elements when the given resource is continuous type.- Parameters:
id
- ID of the resource whose allocated consumer to be returned- Returns:
- resource consumers who are allocated the resource. Returns empty list if there is no such consumer.
-
isAvailable
boolean isAvailable(Resource resource)
Returns the availability of the specified resource.- Parameters:
resource
- resource to check the availability- Returns:
- true if available, otherwise false
-
getResources
java.util.Collection<Resource> getResources(ResourceConsumer consumer)
Returns a collection of the resources allocated to the specified consumer.- Parameters:
consumer
- resource consumer whose allocated resource are searched for- Returns:
- a collection of the resources allocated to the specified consumer
-
getChildResources
java.util.Set<Resource> getChildResources(DiscreteResourceId parent)
Returns a set of the child resources of the specified parent.- Parameters:
parent
- ID of the parent of the resource to be returned- Returns:
- a set of the child resources of the specified resource
-
getChildResources
<T> java.util.Set<Resource> getChildResources(DiscreteResourceId parent, java.lang.Class<T> cls)
Returns a set of the child resources of the specified parent and whose type is the specified class.- Type Parameters:
T
- type of the resource- Parameters:
parent
- ID of the parent of the resources to be returnedcls
- class instance of the children- Returns:
- a set of the child resources of the specified parent and whose type is the specified class
-
getAllocatedResources
<T> java.util.Collection<Resource> getAllocatedResources(DiscreteResourceId parent, java.lang.Class<T> cls)
Returns a collection of the resources which are children of the specified parent and whose type is the specified class.- Type Parameters:
T
- type of the resource- Parameters:
parent
- ID of the parent of the resources to be returnedcls
- class instance of the children- Returns:
- a collection of the resources which belongs to the specified subject and whose type is the specified class.
-
-