Interface ResourceContext


public interface ResourceContext
Logical 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 get ResourceMonitor instances 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 ResourceMonitoringService OSGi service.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addBundle(long bundleId)
    Adds a bundle to the resource context.
    void
    addResourceMonitor(ResourceMonitor<?> resourceMonitor)
    Adds a new ResourceMonitor instance monitoring resource for this resource context.
    boolean
    equals(Object resourceContext)
    A ResourceContext rc1 is equals to ResourceContext rc2 if rc1.getName() is equals to rc2.getName().
    long[]
    Returns the bundle identifiers belonging to this Resource Context.
    getMonitor(String resourceType)
    Returns a ResourceMonitor instance for the specified resource type.
    Retrieves all the existing ResourceMonitor belonging to this context.
    Returns the name of the resource context.
    int
    Retrieves the hashCode value of a ResourceContext.
    void
    removeBundle(long bundleId)
    Removes the bundle identified by bundleId from the Resource Context.
    void
    removeBundle(long bundleId, ResourceContext destination)
    Removes the bundle from this resource context.
    void
    Removes a resource context.
    void
    Removes a ResourceMonitor instance from the context.
  • Method Details

    • getName

      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 Bundle objects, or an empty array if no bundles are currently members of this context
    • addBundle

      void addBundle(long bundleId) throws ResourceContextException
      Adds 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 with removeBundle(long) method or removeBundle(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 ResourceContextEvent with type ResourceContextEvent.BUNDLE_ADDED will 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 ResourceContextException
      Removes 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 ResourceContextException
      Removes the bundle from this resource context. If a destination context 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 ResourceContextEvent with type ResourceContextEvent.BUNDLE_REMOVED will be sent.

      Parameters:
      bundleId - the identifier of the bundle to be removed from the Resource Context
      destination - 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(String resourceType) throws ResourceContextException
      Returns a ResourceMonitor instance for the specified resource type. If the ResourceMonitoringService implementation 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 the destination context. If destination is null, these resources will no longer be monitored.

      A ResourceContextEvent with type ResourceContextEvent.RESOURCE_CONTEXT_REMOVED will be sent.

      Parameters:
      destination - The ResourceContext where 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(Object resourceContext)
      A ResourceContext rc1 is equals to ResourceContext rc2 if rc1.getName() is equals to rc2.getName().
      Overrides:
      equals in class 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:
      hashCode in class Object
      Returns:
      hashcode