Stateful Service Operations
To better understand how to manage state from the client side, let us take a quick look at how Services on TIBCO DataSynapse GridServer® Manager manage it. Let’s consider our
JavaCalculatorExample Service.
The state maintained by the Service is a field called
memory. There are two methods that are responsible for updating the state:
-
addToMemory -
setMemoryAlthough both methods update the state, TIBCO DataSynapse GridServer® Manager has to handle them differently to ensure that the state is properly maintained.addToMemoryrefers to the previous value ofmemory, whereassetMemorydoes not. TIBCO DataSynapse GridServer® Manager denotes the first type of method as anappendStateMethod, and the second type assetStateMethod.When a Service instance is created on an Engine, the Engine replays all state-changing methods from the lastsetStateMethod, or from the beginning if there have been nosetStateMethods. Depending on the duration of the request, it might be worthwhile to followappendStateMethodswithsetStateMethodsperiodically, to save memory on the Manager.These special state-changing methods have to be identified when the Service is registered in TIBCO DataSynapse GridServer® Manager. Within the Service configuration of theJavaCalculatorExample, under the section ContainerBinding, these method names must be included in the fields titled appendStateMethods and setStateMethods.Once the methods have been registered on the Service, a client can access them only through theupdateStatefunctions. These functions behave similar to theexecutefunctions. They take three input arguments: -
methodName— the name of the method to invoke. -
data— the input data. -
append— a Boolean signifying whether it is anappendStateMethodand updates the state accordingly.
These functions do not return output arguments.
In the same manner as
execute and submit, one of two updateState methods are more suitable depending on the number of input arguments that the Service function takes. These functions are: updateState and updateStateWithArray.
The following Visual Basic code updates the
memory of the JavaCalculatorExample:
service.updateState "setToMemory", "25", False
service.updateState "addToMemory", "75", True
The resultant value of
memory is 100.
Related information