com.wiley.posa3.resourcelifecyclemanager
Class ResourceLifecycleManager

java.lang.Object
  extended bycom.wiley.posa3.resourcelifecyclemanager.ResourceLifecycleManager

public class ResourceLifecycleManager
extends java.lang.Object

The ResourceLifecycleManager class provides the primary interface for the RLM pattern. Using this class, one can acquire and release resources of different types. The RLM, makes use of multiple resource pools to manage the lifecycle of resources. If a resource is not found in the appropriate pool, a factory is used to create the resource. Once a resource has been created, it must be added to a resourceGroup by the user to allow it to be properly managed. It is assumed that each resource belongs to at least one group

Version:
1.0
Author:
Michael Kircher, Prashant Jain

Constructor Summary
ResourceLifecycleManager()
          Default Constructor
 
Method Summary
 Resource acquire(ResourceType type)
          This method tries to acquire a resource of the given type.
 void addResourceToGroup(ManagedResource resource, ResourceGroup group)
          Add a resource to an existing group.
 ResourceGroup createGroup(java.lang.String groupID, ManagedResource[] resources)
          Create a group and add all the resources to that group
 void release(ManagedResource resource)
          Release the resource as well as any dependent resources.
 boolean release(ResourceGroup group)
          Release all resources belonging to the ResourceGroup.
 void setFactory(ResourceType type, ResourceFactory factory)
          Set the factory for the type of resource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceLifecycleManager

public ResourceLifecycleManager()
Default Constructor

Method Detail

acquire

public Resource acquire(ResourceType type)
This method tries to acquire a resource of the given type. The method first finds the resource pool corresponding to the given type. It tries to fetch the resource from the pool, if available. If a resource is not available in the pool, the method finds the appropriate factory for the resource type and uses it to create the resource. Note that it is up to the factory to be configured with different strategies and policies pertaining to when the resource is actually created/acquired. Note that the resource must be added to a group by the user for it to be managed by the RLM.

Parameters:
type - the type of resource to acquire
Returns:
Resource the acquired resource

createGroup

public ResourceGroup createGroup(java.lang.String groupID,
                                 ManagedResource[] resources)
Create a group and add all the resources to that group

Parameters:
groupID - the id to assign to the new group
resources - [] an array of resources to add to the group
Returns:
ResrouceGroup the newly created resource group

addResourceToGroup

public void addResourceToGroup(ManagedResource resource,
                               ResourceGroup group)
Add a resource to an existing group.

Parameters:
resource - the resource to add to the group
group - the resource group to which the resouce should be added

release

public boolean release(ResourceGroup group)
Release all resources belonging to the ResourceGroup. The RLM internally uses the Coordinator pattern to ensure that either all resources are released or none are. Each resource acts as a participant in the two-phase protocol initiated by the RLM, which acts as the Coordinator

Parameters:
group - the group whose resources should be released.
Returns:
boolean true if all resources are released, false otherwise

release

public void release(ManagedResource resource)
Release the resource as well as any dependent resources. The dependent resources are those that belong to the ResourceGroup to which the resource belongs to

Parameters:
resource - the resource that should be released.

setFactory

public void setFactory(ResourceType type,
                       ResourceFactory factory)
Set the factory for the type of resource

Parameters:
type - the type of the resource
factory - the factory to set


Copyright 2004 John Wiley and Sons. All Rights Reserved.