Top Description Methods
org.osgi.service.resourcemonitoring

public Interface ResourceContext

Imports
org.osgi.framework.Bundle

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.

Author
$Id: b7a88c81a050b2536c645e45261a73338aa11c6b $
Version
1.0

Method Summary

Modifier and TypeMethod and Description
public void
addBundle(long
The bundle to add to this resource context
bundleId
)

Adds a bundle to the resource context.

public void
addResourceMonitor(ResourceMonitor<?>
resourceMonitor instance to be added
resourceMonitor
)

Adds a new ResourceMonitor instance monitoring resource for this resource context.

public boolean

Returns:

true if getName().equals(resourceContext.getName()
equals
(Object
resource context
resourceContext
)

A ResourceContext rc1 is equals to ResourceContext rc2 if rc1.getName() is equals to rc2.getName().

public long[]

Returns:

An array of Bundle objects, or an empty array if no bundles are currently members of this context
getBundleIds
()

Returns the bundle identifiers belonging to this Resource Context.

public ResourceMonitor<?>

Returns:

A ResourceMonitor instance, or null, if this resource type is not supported
getMonitor
(String
The resource type, for which a resource monitor is requested
resourceType
)

Returns a ResourceMonitor instance for the specified resource type.

public ResourceMonitor<?>[]

Returns:

an array of ResourceMonitor. May be empty if no ResourceMonitor
getMonitors
()

Retrieves all the existing ResourceMonitor belonging to this context.

public String

Returns:

The resource context name
getName
()

Returns the name of the resource context.

public int

Returns:

hashcode
hashCode
()

Retrieves the hashCode value of a ResourceContext.

public void
removeBundle(long
bundle identifier
bundleId
)

Removes the bundle identified by bundleId from the Resource Context.

public void
removeBundle(long
the identifier of the bundle to be removed from the Resource Context
bundleId
,
ResourceContext
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.
destination
)

Removes the bundle from this resource context.

public void
removeContext(ResourceContext
The ResourceContext where the resources currently allocated by this resource context will be moved.
destination
)

Removes a resource context.

public void
removeResourceMonitor(ResourceMonitor<?>
resource monitor instance to be removed
resourceMonitor
)

Removes a ResourceMonitor instance from the context.

Method Detail

addBundleback to summary
public 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:long

The bundle to add to this resource context

Exceptions
ResourceContextException:
For example, when the bundle can't be added to the ResourceContext.
addResourceMonitorback to summary
public 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<?>

resourceMonitor instance to be added

Exceptions
ResourceContextException:
For example, when the monitor can't be added to the ResourceContext.
equalsback to summary
public boolean equals(Object resourceContext)

A ResourceContext rc1 is equals to ResourceContext rc2 if rc1.getName() is equals to rc2.getName().

Parameters
resourceContext:Object

resource context

Returns:boolean

true if getName().equals(resourceContext.getName()

Annotations
@Override
getBundleIdsback to summary
public long[] getBundleIds()

Returns the bundle identifiers belonging to this Resource Context.

Returns:long[]

An array of Bundle objects, or an empty array if no bundles are currently members of this context

getMonitorback to summary
public 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:String

The resource type, for which a resource monitor is requested

Returns:ResourceMonitor<?>

A ResourceMonitor instance, or null, if this resource type is not supported

Exceptions
ResourceContextException:
For example, when the monitor(s) can't be retrieved from the ResourceContext.
getMonitorsback to summary
public ResourceMonitor<?>[] getMonitors() throws ResourceContextException

Retrieves all the existing ResourceMonitor belonging to this context.

Returns:ResourceMonitor<?>[]

an array of ResourceMonitor. May be empty if no ResourceMonitor

Exceptions
ResourceContextException:
For example, when the monitor(s) can't be retrieved from the ResourceContext.
getNameback to summary
public String getName()

Returns the name of the resource context. Resource context names are unique within a framework instance.

Returns:String

The resource context name

hashCodeback to summary
public 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.

Returns:int

hashcode

Annotations
@Override
removeBundleback to summary
public 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:long

bundle identifier

Exceptions
ResourceContextException:
For example, when the bundle can't be removed from the ResourceContext.
removeBundleback to summary
public 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:long

the identifier of the bundle to be removed from the Resource Context

destination:ResourceContext

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.

Exceptions
ResourceContextException:
For example, when the bundle can't be removed from the ResourceContext.
removeContextback to summary
public 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:ResourceContext

The ResourceContext where the resources currently allocated by this resource context will be moved.

Exceptions
ResourceContextException:
For example, when the resource context can't be removed.
removeResourceMonitorback to summary
public void removeResourceMonitor(ResourceMonitor<?> resourceMonitor) throws ResourceContextException

Removes a ResourceMonitor instance from the context.

Parameters
resourceMonitor:ResourceMonitor<?>

resource monitor instance to be removed

Exceptions
ResourceContextException:
For example, when the monitor can't be removed from the ResourceContext.