The resource home has to be modified, but still remains relatively simple because, as in the previous chapter, our resource class extends from a Globus-supplied class. In the previous chapter, we extended from SingletonResourceHome
, a Globus-supplied class that provided most of the functionality of a resource home for a single resource. Now we will extend from ResourceHomeImpl
, another Globus-supplied class for resource homes that manage several resources.
The only method we have to implement is the create
method, where we will create a new resource and return its identifier. All the other methods we would expect in a resource home (such as a find
method to retrieve a resource given a certain key) are already implemented for us in ResourceHomeImpl
.
package org.globus.examples.services.core.factory.impl; import org.globus.wsrf.ResourceKey; import org.globus.wsrf.impl.ResourceHomeImpl; import org.globus.wsrf.impl.SimpleResourceKey; public class MathResourceHome extends ResourceHomeImpl { public ResourceKey create() throws Exception { // Create a resource and initialize it MathResource mathResource = (MathResource) createNewInstance(); mathResource.initialize(); // Get key ResourceKey key = new SimpleResourceKey(keyTypeName, mathResource .getID()); // Add the resource to the list of resources in this home add(key, mathResource); return key; } }
This file is
|
Now is another good moment to review Figure 5.3, “Sequence diagram for resource creation”. |
There's more to the resource home that meets the eye... | |
---|---|
The resource home shown above, along with the one seen in the previous chapter, covers the simplest possible case of resources: in-memory resources, or resources which reside in main memory while the container is running. However, resource homes can also be used to manage persistent resources, or resources that are stored in disk so they can survive container restarts. To do this, our resource must implement the Another thing we can do to a resource home is to override its |