After you define a resource pool component, other Nucleus components can use that resource pool to check out resources and check them back in when they are done. A component that needs to use the resource pool can be passed a pointer to the resource pool through a properties file. It defines a property for that resource pool as follows:

ResourcePool resourcePool;
public ResourcePool getResourcePool ()
{ return resourcePool; }
public void setResourcePool (ResourcePool resourcePool)
{ this.resourcePool = resourcePool; }

When the component requires a resource from the pool, it calls checkOut:

try {
  // Get a resource
  ResourceObject resource =
    getResourcePool ().checkOut (getAbsoluteName ());
catch (ResourcePoolException exc) {
  if (isLoggingError ()) logError (exc);
}

This line gets the resource pool and checks out a resource from the pool. When it calls checkOut, it must pass an identifying string, in this case the name of the service checking out the resource. This is required so that the administrator can look at the resource pool and see which parts of the application are using which resources.

The object returned by checkOut is of type ResourceObject. This object contains the resource you wanted in the first place. You obtain the resource by calling getResource:

try {
  // Get a resource
  ResourceObject resource =
    getResourcePool ().checkOut (getAbsoluteName ());
  ReallyExpensiveObject obj = (ReallyExpensiveObject)
    resource.getResource ();
}
catch (ResourcePoolException exc) {
  if (isLoggingError ()) logError (exc);
}

After you obtain the resource, it is yours to use. You can work on the assumption that no one else uses the resource at the same time.

When you are done with the resource, you must check it back in:

try {
  // Get a resource
  ResourceObject resource =
    getResourcePool ().checkOut (getAbsoluteName ());
  ReallyExpensiveObject obj = (ReallyExpensiveObject)
    resource.getResource ();

  ...

  getResourcePool ().checkIn (resource);
}
catch (ResourcePoolException exc) {
  if (isLoggingError ()) logError (exc);
}

After checking in the resource, you are expected to no longer use that resource. If you need the resource again, you must check out another resource from the pool.