Setting up the Service

The Service in this example simulates a simple calculator, with functions for the four operators, plus a memory function. The Java source code is available in the GridServer SDK, in /GridServerSDK-win32/examples/service/calculator/service/java/.

The JavaCalculator class has a floating-point field called memory, and the following methods:

add, subtract, multiply, divide — each takes two strings representing floating-point numbers, and returns a string representing the result of the arithmetic operation.
addToMemory — takes in one string argument representing a floating-point number, and stores the sum of the input and memory values back in memory.
setMemory — takes in one string argument representing a floating-point number and sets the memory field equal to it.
getMemory — takes in a string argument, and returns the value of memory. (The argument is unused, but is required by the Services API.)

Before the client can access the Service, we have to register a Service Type and deploy the Service resources. Make sure the Service Type is registered under the name JavaCalculatorExample in the GridServer Service Type Registry; this is how we reference the Service from the client. The Service is automatically registered when GridServer is installed.

If the Grid Library has not been deployed, build and deploy it from GridServerSDK-win32/examples/service/calculator/ by running build-and-deploy.bat.

To find out more about writing, registering, and deploying a Service, see the TIBCO GridServer® Service-Oriented Integration Tutorial.