Adding transience to MathService

The Deployment Descriptor

Turning a service into a factory of transient services is one the easiest things to do in GT3. What we're going to do is take the example from the first chapter, and add transience to it. To do this, we won't need to modify the service interface and not even the service implementation. The only thing we have to do is modify the deployment descriptor.

In fact, if you've been following the tutorial from the beginning, the deployment descriptor for the MathService factory was already included in the first chapter's WSDD file:

$TUTORIAL_DIR/org/globus/progtutorial/services/core/first/server-deploy.wsdd

So, if you've already compiled and deployed that example, you inadvertently also deployed the MathService factory service (WSDD allows you to deploy more than one service at once). If you haven't, don't worry, the deployment instructions are repeated below for your convenience.

To emphasize the changes that have to be done to turn any service into a factory of transient services, let's review the deployment descriptor from the first chapter:

<?xml version="1.0"?>
<deployment name="defaultServerConfig" xmlns="http://xml.apache.org/axis/wsdd/"
  xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

  <service 
    name="progtutorial/core/first/MathService" provider="Handler" style="wrapped">
    <parameter name="name" value="MathService"/>
    
    <parameter name="baseClassName" value="org.globus.progtutorial.services.core.first.impl.MathImpl"/>
    <parameter name="className" value="org.globus.progtutorial.stubs.MathService.MathPortType"/>
    <parameter name="schemaPath" value="schema/progtutorial/MathService/Math_service.wsdl"/>

    <!-- Start common parameters -->
    <parameter name="allowedMethods" value="*"/>
    <parameter name="persistent" value="true"/>
    <parameter name="handlerClass" value="org.globus.ogsa.handlers.RPCURIProvider"/>
  </service>

</deployment>
[Note]

This is a part of as $TUTORIAL_DIR/org/globus/progtutorial/services/core/first/server-deploy.wsdd

The following is the deployment descriptor for the exact same service using a factory/instance model. Remember: this means that we'll have a persistent factory service which we'll use to create transient MathService instances (i.e. MathServices which we'll be able to create and destroy any time we want)

<?xml version="1.0"?>
<deployment name="defaultServerConfig" xmlns="http://xml.apache.org/axis/wsdd/"
  xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

  <service name="progtutorial/core/first/MathFactoryService" provider="Handler" style="wrapped">
    <parameter name="name" value="MathService Factory"/>
    <parameter name="instance-name" value="MathService Instance"/>
    <parameter name="instance-schemaPath" value="schema/progtutorial/MathService/Math_service.wsdl"/>
    <parameter name="instance-baseClassName" value="org.globus.progtutorial.services.core.first.impl.MathImpl"/>
    <parameter name="instance-className" value="org.globus.progtutorial.stubs.MathService.MathPortType"/>

    <!-- Start common parameters -->
    <parameter name="allowedMethods" value="*"/>
    <parameter name="persistent" value="true"/>
    <parameter name="handlerClass" value="org.globus.ogsa.handlers.RPCURIProvider"/>
    
    <parameter name="className" value="org.gridforum.ogsi.Factory"/>
    <parameter name="baseClassName" value="org.globus.ogsa.impl.ogsi.GridServiceImpl"/>
    <parameter name="schemaPath" value="schema/ogsi/ogsi_factory_service.wsdl"/>
    <parameter name="operationProviders" value="org.globus.ogsa.impl.ogsi.FactoryProvider"/>
    <parameter name="factoryCallback" value="org.globus.ogsa.impl.ogsi.DynamicFactoryCallbackImpl"/>
  </service>

</deployment>
[Note]

This is a part of as $TUTORIAL_DIR/org/globus/progtutorial/services/core/first/server-deploy.wsdd

Let's compare both deployment descriptors. First of all, notice how we've added an "instance-" prefix to the original name, schemaPath, baseClassName, and className parameters. By doing this, we're telling the container that these will be the parameters for the instance services (the transient MathServices we'll create through the factory).

Then, we've added a bunch of parameters in the 'common parameters block'. Notice how schemaPath, baseClassName, and className now refer to factory code (provided by GT3), and not to any code we've programmed ourselves. All the code needed to implement the factory/instance model is already included with GT3, so we don't have to worry about programming it ourselves.

So, adding transience to any of the service's we've written is as simple as adding that new 'common parameters block' and putting the "instance-" prefix on any parameter that refers to our own code.

Finally, remember that if you've already deployed the first example in the tutorial, the factory example was also deployed then, so there's no need to rebuild and redeploy it. However, if you haven't built and deployed the first service, here's the necessary commands in a nutshell:

./tutorial_build.sh \
org/globus/progtutorial/services/core/first \
schema/progtutorial/MathService/Math.gwsdl
ant deploy \
-Dgar.name=$TUTORIAL_DIR/build/lib/org_globus_progtutorial_services_core_first.gar