View Javadoc

1   package org.astrogrid.ogsa.echo;
2   
3   import java.net.URL;
4   import java.util.GregorianCalendar;
5   import org.astrogrid.ogsa.echo.EchoServiceLocator;
6   import org.astrogrid.ogsa.echo.EchoPortType;
7   import org.gridforum.ogsi.Factory;
8   import org.gridforum.ogsi.LocatorType;
9   import org.gridforum.ogsi.OGSIServiceLocator;
10  import org.globus.ogsa.utils.GridServiceFactory;
11  
12  /***
13   * Exercises an echo servcie with a series of 100 invocations.
14   */
15  public class TestMultipleEcho {
16  
17    public static void main (String[] args) throws Exception {
18  
19      if (args.length != 2) {
20        System.err.println("usage: echo <string> <factory-URL>");
21        return;
22      }
23  
24      // Get access to the factory port.  Use the GridServiceFactory
25      // wrapper to the port to simplify the interface of the
26      // createService method.
27      OGSIServiceLocator factoryLocator = new OGSIServiceLocator();
28      Factory factory = factoryLocator.getFactoryPort(new URL(args[1]));
29      GridServiceFactory gridFactory = new GridServiceFactory(factory);
30          
31      // Create a service instance and locate its echo port.
32      // Set a ten-minute timeout.
33      GregorianCalendar timeout = new GregorianCalendar();
34      timeout.add(GregorianCalendar.MINUTE, 10);
35      LocatorType instanceLocator = gridFactory.createService(timeout);
36      EchoServiceGridLocator portLocator = new EchoServiceGridLocator();
37      EchoPortType port = portLocator.getEchoPortType(instanceLocator);
38          
39      // Invoke the echo port.
40      for (int i = 1; i <= 100; i++) {
41         System.out.println(i + ": " + port.echo(args[0]));
42      } 
43    }
44  
45  }