Open topic with navigation

TIBCO GridServer® 7.1.0

# 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 GridServer® 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`

| • | `setMemory`

Although both methods update the state, TIBCO GridServer® has to handle them differently to ensure that the state is properly maintained. `addToMemory` refers to the previous value of `memory`, whereas `setMemory` does not. TIBCO GridServer® denotes the first type of method as an `appendStateMethod`, and the second type as `setStateMethod`.

When a Service instance is created on an Engine, the Engine replays all state-changing methods from the last `setStateMethod`, or from the beginning if there have been no `setStateMethods`. Depending on the duration of the request, it might be worthwhile to follow `appendStateMethods` with `setStateMethods` periodically, to save memory on the Manager.

These special state-changing methods have to be identified when the Service is registered in TIBCO GridServer®. Within the Service configuration of the `JavaCalculatorExample`, 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 only access them through the `updateState` functions. These functions behave in a similar way to `execute` functions. They take three input arguments:

| • | `methodName` — the name of the method to invoke;

| • | `data` — the input data;

| • | `append` — a Boolean signifying whether it is an `appendStateMethod` and 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.

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO GridServer®

Copyright © 2001-2022. TIBCO Software Inc. All Rights Reserved.