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.

    Version:
    1.0
    Author:
    $Id: b7a88c81a050b2536c645e45261a73338aa11c6b $
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      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​(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.String getName()
      Returns the name of the resource context.
      int hashCode()
      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 removeContext​(ResourceContext destination)
      Removes a resource context.
      void removeResourceMonitor​(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 Bundle objects, or an empty array if no bundles are currently members of this context
      • 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​(java.lang.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.
      • equals

        boolean equals​(java.lang.Object resourceContext)
        A ResourceContext rc1 is equals to ResourceContext rc2 if rc1.getName() is equals to rc2.getName().
        Overrides:
        equals in class java.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:
        hashCode in class java.lang.Object
        Returns:
        hashcode