Creating Java Grid Services
by Aaron E. Walsh

Listing One

/* "Counter" interface example provided with Globus Toolkit 3. Refer to
 * guide/src/org/globus/ogsa/guide/impl/Counter.java for complete example.
 */

package org.globus.ogsa.guide.impl.guide;
public interface Counter {
    public int add(int value);
    public int subtract(int value);
    public int getValue();
}


Listing Two

<types>
 ...
<xsd:element name="add">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="value" type="xsd:int"/>
    </xsd:sequence>
  </xsd:complexType>
  </xsd:element>
 ...
</types>
 ...
<message name="AddInputMessage">
  <part name="parameters" element="tns:add"/>
</message>
 ...
<gwsdl:portType name="CounterPortType" extends="ogsi:GridService">
  <operation name="add">
    <input message="tns:AddInputMessage"/>
    <output message="tns:AddOutputMessage"/>
    <fault name="Fault" message="ogsi:FaultMessage"/>
  </operation>
</gwsdl:portType>


Listing Three

<ant antfile="${build.services}" target="generateWSDL">
  <property name="interface.package" value="org.globus.ogsa.guide.impl"/>
  <property name="interface.name" value="Counter"/>
  <property name="generated.dir" value="guide"/>
</ant>


Listing Four

<ant antfile="${build.services}" target="generateStubs">
  <property name="schema.file.dir" value="guide/Counter"/>
  <property name="schema.file" value="counter_service.wsdl"/>
</ant>


Listing Five

/* "Counter" implementation example provided with Globus Toolkit 3. Refer to
 * uide/src/org/globus/ogsa/guide/impl/CounterImpl.java for complete example.
 */

public class CounterImpl extends GridServiceImpl implements CounterPortType {
    private int val = 0;
    public CounterImpl() {
        super("Guide Counter");
    }
    public int add(int val) throws RemoteException {
        this.val = this.val + val;
        return this.val;
    }
    public int subtract(int val) throws RemoteException {
        this.val = this.val - val;
        return this.val;
    }
    public int getValue() throws RemoteException {
        return this.val;
    }
}


Listing Six

<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultServerConfig"
       xmlns="http://xml.apache.org/axis/wsdd/"
       xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
  <service name="guide/counter/CounterProviderFactoryService"
                 provider="Handler" style="wrapped">
  <parameter name="name" value="Guide Counter Provider Factory"/>
  <parameter name="instance-name" value="Guide Counter Proivider Counter"/>
  <parameter name="instance-schemaPath"
                 value="schema/guide/Counter/counter_service.wsdl"/>
  <parameter name="instance-className"
                 value="org.globus.ogsa.guide.Counter.wsdl.CounterPortType"/>
  <parameter name="instance-baseClassName"
                 value="org.globus.ogsa.impl.ogsi.GridServiceImpl"/>
  <parameter name="instance-operationProviders"
                 value="org.globus.ogsa.guide.impl.CounterProvider"/>
  <parameter name="persistent" value="true"/>
  <parameter name="schemaPath"
                 value="schema/ogsi/ogsi_notification_factory_service.wsdl"/>
  <parameter name="baseClassName"
                 value="org.globus.ogsa.impl.ogsi.PersistentGridServiceImpl"/>
  <parameter name="handlerClass"
                 value="org.globus.ogsa.handlers.RPCURIProvider"/>
  <parameter name="className"
                 value="org.gridforum.ogsi.NotificationFactory"/>
  <parameter name="allowedMethods" value="*"/>
  <parameter name="factoryCallback"
                value="org.globus.ogsa.impl.ogsi.DynamicFactoryCallbackImpl"/>
  <parameter name="operationProviders"
                value="org.globus.ogsa.impl.ogsi.FactoryProvider org.
                globus.ogsa.impl.ogsi.NotificationSourceProvider"/>
 </service
</deployment>


Listing Seven

<ant antfile="${build.packages}" target="makeGar">
  <property name="gar.name" value="${build.lib}/guide.gar"/>
  <property name="garlib.dir" value="${build.lib}"/>
  <property name="garserverdeployment.file" value="guide-config.wsdd"/>
  <property name="garschema.origin" value="${build.schema}/guide"/>
  <property name="garschema.path" value="guide"/>
</ant>


Listing Eight

/* "Counter" grid service client JAX-RPC example provided with Globus
 * Toolkit 3. Refer to GT3 Java Programmers Guide Core Framework for details.
 */

OGSIServiceGridLocator gridLocator = new OGSIServiceGridLocator();
Factory factory = gridLocator.getFactoryPort(handle);
GridServiceFactory gridFactory = new GridServiceFactory(factory);
LocatorType locator = gridFactory.createService();
CounterServiceGridLocator counterLocator = new CounterServiceGridLocator();
CounterPortType counter = counterLocator.getCounterPort(locator);
int val = counter.add(2);





