Set the initial state of an ObjectGrid with the ObjectGrid
configuration XML file. You can use the initialState attribute
on an ObjectGrid to indicate its startup state. Normally, when an
ObjectGrid completes initialization, it is available for routing.
The state can later be changed to prevent traffic from routing to
an ObjectGrid. If the ObjectGrid needs to be initialized, but not
immediately available, you can use the initialState attribute.
The
initialState attribute is set on the ObjectGrid configuration XML
file. The default state is ONLINE. Valid values include:
- ONLINE
(default)
- PRELOAD
- OFFLINE
See ObjectGrid descriptor XML file for more information
about the initialState attribute.If the initialState
attribute is set on an ObjectGrid, the state must be explicitly set
back to online or the ObjectGrid will remain unavailable. An AvailabilityException
exception results if the ObjectGrid is not in the ONLINE state.
See AvailabilityState API documentation for
more information.
Using the initialState attribute
for preloading
If the ObjectGrid is preloaded with data,
there can be a period of time between when the ObjectGrid is available
and switching to a preload state to block client traffic. To avoid
this time period, the initial state on an ObjectGrid can be set to
PRELOAD. The ObjectGrid still completes all the necessary initialization,
but it blocks traffic until the state has changed and allows the preload
to occur.
The PRELOAD and OFFLINE states both block traffic,
but you must use the PRELOAD state if you want to initiate a preload.
Failover
and balancing behavior
If a replica data grid is promoted
to be a primary data grid, the replica does not use the initialState setting.
If the primary data grid is moved for a rebalance, the initialState setting
is not used because the data is copied to the new primary location
before the move is completed. If replication is not configured, then
the primary goes into the initialState setting
if failover occurs, and a new primary must be placed.
Change the availability state with the StateManager interface. Use the StateManager interface to set
the availability state of an ObjectGrid. To set the availability state
of an ObjectGrid running on the servers, pass a corresponding ObjectGrid
client to the StateManager interface. The following
code demonstrates how to change the availability state of an ObjectGrid.
ClientClusterContext client = ogManager.connect("localhost:2809", null, null);
ObjectGrid myObjectGrid = ogManager.getObjectGrid(client, "myObjectGrid");
StateManager stateManager = StateManagerFactory.getStateManager();
stateManager.setObjectGridState(AvailabilityState.OFFLINE, myObjectGrid);
Each shard of the ObjectGrid transitions to the desired
state when the
setObjectGridState method is called
on the
StateManager interface. When the method
returns, all shards within the ObjectGrid should be in the proper
state.
Use an ObjectGridEventListener plug-in to change the
availability state of a server side ObjectGrid. Only change the availability
state of a server-side ObjectGrid when the ObjectGrid has a single
partition. If the ObjectGrid has multiple partitions, the shardActivated method
is called on each primary, which results in superfluous calls to change
the state of the ObjectGrid
public class OGListener implements ObjectGridEventListener,
ObjectGridEventGroup.ShardEvents {
public void shardActivated(ObjectGrid grid) {
StateManager stateManager = StateManagerFactory.getStateManager();
stateManager.setObjectGridState(AvailabilityState.PRELOAD, grid);
}
}
Because QUIESCE is a transitional state, you cannot
use the StateManager interface to put an ObjectGrid
into the QUIESCE state. An ObjectGrid passes through this state on
its way to the OFFLINE state.