Interface ResourceContext
-
public interface ResourceContextLogical entity for resource accounting. A resource context has a group of member bundles, and a bundle can be a member of 0 or 1 resource context.Resource Monitoring Clients can use the
ResourceMonitoringService.createContext(String, ResourceContext)method to create ResourceContext instances.Resource Monitoring Clients can use the
getMonitor(String)method to getResourceMonitorinstances for the supported resource types. These instances can then be used to monitor the usage of the resources, or the set usage limits.ResourceContexts are retrieved through the
ResourceMonitoringServiceOSGi service.- Version:
- 1.0
- Author:
- $Id: b7a88c81a050b2536c645e45261a73338aa11c6b $
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddBundle(long bundleId)Adds a bundle to the resource context.voidaddResourceMonitor(ResourceMonitor<?> resourceMonitor)Adds a new ResourceMonitor instance monitoring resource for this resource context.booleanequals(java.lang.Object resourceContext)A ResourceContext rc1 is equals to ResourceContext rc2 if rc1.getName() is equals to rc2.getName().long[]getBundleIds()Returns the bundle identifiers belonging to this Resource Context.ResourceMonitor<?>getMonitor(java.lang.String resourceType)Returns a ResourceMonitor instance for the specified resource type.ResourceMonitor<?>[]getMonitors()Retrieves all the existing ResourceMonitor belonging to this context.java.lang.StringgetName()Returns the name of the resource context.inthashCode()Retrieves the hashCode value of a ResourceContext.voidremoveBundle(long bundleId)Removes the bundle identified by bundleId from the Resource Context.voidremoveBundle(long bundleId, ResourceContext destination)Removes the bundle from this resource context.voidremoveContext(ResourceContext destination)Removes a resource context.voidremoveResourceMonitor(ResourceMonitor<?> resourceMonitor)Removes a ResourceMonitor instance from the context.
-
-
-
Method Detail
-
getName
java.lang.String getName()
Returns the name of the resource context. Resource context names are unique within a framework instance.- Returns:
- The resource context name
-
getBundleIds
long[] getBundleIds()
Returns the bundle identifiers belonging to this Resource Context.- Returns:
- An array of
Bundleobjects, or an empty array if no bundles are currently members of this context
-
addBundle
void addBundle(long bundleId) throws ResourceContextExceptionAdds a bundle to the resource context. The bundle will be a member of the context until it is uninstalled, or explicitly removed from the context withremoveBundle(long)method orremoveBundle(long, ResourceContext)method.Resources previously allocated by this bundle (in another resource context) will not be moved to this resource context. The change applies only for future allocations.
A
ResourceContextEventwith typeResourceContextEvent.BUNDLE_ADDEDwill be sent.- Parameters:
bundleId- The bundle to add to this resource context- Throws:
ResourceContextException- For example, when the bundle can't be added to the ResourceContext.
-
removeBundle
void removeBundle(long bundleId) throws ResourceContextExceptionRemoves the bundle identified by bundleId from the Resource Context. The bundle is no longer to this Resource Context.- Parameters:
bundleId- bundle identifier- Throws:
ResourceContextException- For example, when the bundle can't be removed from the ResourceContext.
-
removeBundle
void removeBundle(long bundleId, ResourceContext destination) throws ResourceContextExceptionRemoves the bundle from this resource context. If adestinationcontext is specified, the bundle will be added in it.Resources previously allocated by this bundle will not be removed from the resource context. The change applies only for future allocations.
A
ResourceContextEventwith typeResourceContextEvent.BUNDLE_REMOVEDwill be sent.- Parameters:
bundleId- the identifier of the bundle to be removed from the Resource Contextdestination- A resource context in which to add the bundle, after removing it from this context. If no destination is provided (that is null), the bundle is not associated to a new Resource Context.- Throws:
ResourceContextException- For example, when the bundle can't be removed from the ResourceContext.
-
getMonitor
ResourceMonitor<?> getMonitor(java.lang.String resourceType) throws ResourceContextException
Returns a ResourceMonitor instance for the specified resource type. If theResourceMonitoringServiceimplementation does not support this resource type, null is returned- Parameters:
resourceType- The resource type, for which a resource monitor is requested- Returns:
- A ResourceMonitor instance, or null, if this resource type is not supported
- Throws:
ResourceContextException- For example, when the monitor(s) can't be retrieved from the ResourceContext.
-
getMonitors
ResourceMonitor<?>[] getMonitors() throws ResourceContextException
Retrieves all the existing ResourceMonitor belonging to this context.- Returns:
- an array of ResourceMonitor. May be empty if no ResourceMonitor
- Throws:
ResourceContextException- For example, when the monitor(s) can't be retrieved from the ResourceContext.
-
addResourceMonitor
void addResourceMonitor(ResourceMonitor<?> resourceMonitor) throws ResourceContextException
Adds a new ResourceMonitor instance monitoring resource for this resource context. This method should be called only by ResourceMonitorFactory instance.- Parameters:
resourceMonitor- resourceMonitor instance to be added- Throws:
ResourceContextException- For example, when the monitor can't be added to the ResourceContext.
-
removeResourceMonitor
void removeResourceMonitor(ResourceMonitor<?> resourceMonitor) throws ResourceContextException
Removes a ResourceMonitor instance from the context.- Parameters:
resourceMonitor- resource monitor instance to be removed- Throws:
ResourceContextException- For example, when the monitor can't be removed from the ResourceContext.
-
removeContext
void removeContext(ResourceContext destination) throws ResourceContextException
Removes a resource context. All resources allocated in this resource context will be moved to thedestinationcontext. Ifdestinationisnull, these resources will no longer be monitored.A
ResourceContextEventwith typeResourceContextEvent.RESOURCE_CONTEXT_REMOVEDwill be sent.- Parameters:
destination- TheResourceContextwhere the resources currently allocated by this resource context will be moved.- Throws:
ResourceContextException- For example, when the resource context can't be removed.
-
equals
boolean equals(java.lang.Object resourceContext)
A ResourceContext rc1 is equals to ResourceContext rc2 if rc1.getName() is equals to rc2.getName().- Overrides:
equalsin classjava.lang.Object- Parameters:
resourceContext- resource context- Returns:
- true if getName().equals(resourceContext.getName()
-
hashCode
int hashCode()
Retrieves the hashCode value of a ResourceContext. The hashCode value of a ResourceContext is only based on the hashcode value of the name of the context.- Overrides:
hashCodein classjava.lang.Object- Returns:
- hashcode
-
-