A simple client

Since the service interface is exactly the same as the one used in the first chapter, we can reuse the MathService client:

$TUTORIAL_DIR/org/globus/progtutorial/clients/MathService/Client.java 

However, this client only works with services that have the MathService interface. In this example, the services that will have the MathService interface will be the transient instances, so we need to create an instance first through the factory service. We'll see how to do this from Java in the next client. Right now, we'll simply use a GT3 command-line client:

ogsi-create-service \
http://127.0.0.1:8080/ogsa/services/progtutorial/core/first/MathFactoryService
[Note]

As with globus-start-container, you need to setup the GT3 command-line clients for this command to work. If you haven't done so yet, take a look at the following section in the How to... appendix: How to... appendix: How to setup the GT3 scripts.

You should see the following:

Service successfully created:
Handle: http://127.0.0.1:8080/ogsa/services/progtutorial/core/first/MathFactoryService/hash-24981262-1078167170769
Termination Time: infinity

The GSH that ogsi-create-service returns is the instance's handle. This is the service that has the MathService interface and which we'll be able to invoke using the MathService client. Notice how the GSH ends with a hash number. This hash number will be different each time you run ogsi-create-service, so be sure to use the GSH returned by that command (i.e. don't copy & paste the GSH as it appears here in the tutorial).

That said, let's try out the MathService client with the instance.

java \
-classpath ./build/classes/:$CLASSPATH \
org.globus.progtutorial.clients.MathService.Client \
http://127.0.0.1:8080/ogsa/services/progtutorial/core/first/MathFactoryService/hash-24981262-1078167170769 \
5

Just like in the first example, you should see the following:

Added 5
Current value: 5

If you create several instances, you'll be able to see that each instance keeps its own particular state. In other words, what we do to one instance affects that instance (and that instance alone). This is why using a factory/instance model is interesting when a client wants to dynamically create a service, use it for a particular task, and destroy the instance once it's done with its work.

You can destroy the instance by using the ogsi-destroy-instance command:

ogsi-destroy-service \
http://127.0.0.1:8080/ogsa/services/progtutorial/core/first/MathFactoryService/hash-24981262-1078167170769