Interface MultiClusterGigaSpace
- All Superinterfaces:
AutoCloseable, GigaSpace
- All Known Implementing Classes:
DefaultMultiClusterGigaSpace
GigaSpace that fronts several already-deployed remote spaces - one per cluster / site - and
redirects each operation to one or more of them according to the configured MultiClusterGigaSpace.WriteMode,
MultiClusterGigaSpace.ReadMode and MultiClusterGigaSpace.FailoverPolicy.
Because it extends GigaSpace, application code does not change: whatever calls
write / readMultiple / change / execute today keeps compiling and
running. Only the bean or factory that produces the GigaSpace is swapped.
DefaultMultiClusterGigaSpace is the implementation:
construct one directly when the clusters arrive at runtime or a framework needs a plain constructor,
or build one through MultiClusterGigaSpaceConfigurer when the
topology is known up front and should be validated. The interface is the contract defined by PIC-6085;
getStats() and close() are the two additions.
Semantics worth knowing before using it
- Fan-out modes are not a distributed transaction. Inside an active transaction the proxy falls back to the active cluster only (or fails, depending on the configured transaction policy) - there is no cross-cluster two-phase commit.
READ_ROUND_ROBINreads are eventually consistent by construction: a read may land on a cluster that has not yet received the latest write. Read-your-writes requiresMultiClusterGigaSpace.ReadMode.READ_ACTIVE.- Either the proxy fans mutations out, or a WAN Gateway replicates them - doing both applies each mutation twice.
- Two inherited
GigaSpacemethods throwUnsupportedOperationExceptionhere, because what they return would be a live handle onto one cluster and every call on it would bypass the routing above:GigaSpace.getClustered()- use this proxy, orgetCluster(String)when one cluster is what you want - andexecutorBuilder(...), whose builder is bound to the space that created it; useGigaSpace.execute(Task)instead, which is routed and honours the fan-out setting. Narrower handles -getSpace(),getTypeManager(),getTxProvider(),newDataEventSession()- are answered by the active cluster.
Implementations are thread-safe: registration, configuration and failover may run concurrently with space operations.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceNotified on every multi-cluster state change: a cluster added or removed, a cluster failing, and the active cluster switching.static enumWhat happens when the cluster an operation was routed to is unavailable.static enumHow read operations pick a cluster.static enumHow mutations (write,take,change,clear) are distributed. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClusterEventListener(ClusterEventListener listener) Registers a listener that receives the same events with an explicitClusterEventTyperather than the convention below.voidbooleanaddClusterToPriorityList(String clusterName) Makes a cluster a promotion candidate again, appended to the configured order if it was not in it.booleanaddClusterToReadRotation(String clusterName) Puts a cluster back into round-robin reads after it was removed.voidDrops the read pin, soREAD_ACTIVEreads follow the write-active cluster again.voidclose()Releases the resources this proxy owns: background schedulers and the async write queue.voidForcefully triggers failover to the next healthy cluster in the priority list.Returns the currently designated primary active GigaSpace proxy, ornullif none.Returns the name of the currently designated primary active cluster - the one taking mutations - ornullif none.getCluster(String clusterName) Resolves a GigaSpace proxy by its registered cluster name.getClusterName(GigaSpace spaceProxy) Resolves the registered cluster name for a given GigaSpace proxy instance.The order clusters will actually be promoted in: the configured priorities first, then any registered cluster the configuration omits, minus anything removed byremoveClusterFromPriorityList(String)or dropped after a failure.intReturns the consecutive failure threshold.Returns the rolling failure window.The proxy of the clustergetReadActiveClusterName()names, ornull.The clusterMultiClusterGigaSpace.ReadMode.READ_ACTIVEreads go to: the pinned read cluster, or the active cluster when nothing is pinned.The clusters currently eligible forMultiClusterGigaSpace.ReadMode.READ_ROUND_ROBINreads, in registration order.Returns the registered clusters, keyed by name, in registration order.getStats()Per-cluster operation counters, failures and observed latency.booleanisClusterHealthy(String clusterName) Returns true if the cluster identified by name is reachable.booleanisClusterHealthy(GigaSpace spaceProxy) Returns true if the specified GigaSpace cluster instance is reachable.voidregisterCluster(String clusterName, GigaSpace spaceProxy) Registers a GigaSpace cluster proxy target under a named identifier.voidbooleanremoveClusterFromPriorityList(String clusterName) Removes a cluster from failover promotion without unregistering it.booleanremoveClusterFromReadRotation(String clusterName) Takes a cluster out of round-robin reads.voidvoidsetActiveCluster(String clusterName) Sets the primary active cluster by name.voidsetActiveCluster(GigaSpace spaceProxy) Sets the primary active cluster by direct instance reference.voidsetClusterPriorityList(List<String> priorityNames) Sets the ordered fallback list of cluster names for automated promotion.voidvoidsetFailureThreshold(int consecutiveFailuresThreshold) Sets the consecutive failure threshold required before marking a cluster unhealthy.voidsetFailureWindow(Duration failureWindow) Defines the rolling window duration for error threshold evaluation.voidsetReadActiveCluster(String clusterName) PinsMultiClusterGigaSpace.ReadMode.READ_ACTIVEreads toclusterName, separately from the cluster taking mutations - a dedicated read cluster and a dedicated write cluster.voidvoidsetWriteActiveCluster(String clusterName) MakesclusterNamethe write-active cluster: mutations, transactions, task execution and metadata calls go there.voidvoidunregisterCluster(String clusterName) Unregisters a target cluster by name.voidunregisterCluster(GigaSpace spaceProxy) Unregisters a target cluster by its proxy instance.Methods inherited from interface GigaSpace
aggregate, aggregate, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncChange, asyncLoad, asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncTake, asyncTake, asyncTake, asyncTake, asyncTake, asyncTake, asyncTake, asyncTake, asyncTake, asyncTake, asyncTake, asyncTake, change, change, change, change, change, change, change, change, clear, clear, clear, count, count, execute, execute, execute, execute, execute, execute, executeDurable, executeDurable, executorBuilder, getActiveOperations, getClustered, getCurrentTransaction, getDefaultChangeModifiers, getDefaultClearModifiers, getDefaultCountModifiers, getDefaultReadModifiers, getDefaultTakeModifiers, getDefaultWriteModifiers, getExceptionTranslator, getLastOperations, getLastOperations, getName, getSpace, getSpaceName, getTxProvider, getTypeManager, isSecured, iterator, iterator, iterator, iterator, iterator, iterator, iterator, iterator, listDurableTasks, newDataEventSession, newDataEventSession, prepareTemplate, read, read, read, read, read, read, readById, readById, readById, readById, readById, readById, readById, readByIds, readByIds, readByIds, readByIds, readByIds, readByIds, readByIds, readIfExists, readIfExists, readIfExists, readIfExists, readIfExists, readIfExists, readIfExistsById, readIfExistsById, readIfExistsById, readIfExistsById, readIfExistsById, readIfExistsById, readIfExistsById, readMultiple, readMultiple, readMultiple, readMultiple, readMultiple, readMultiple, registerDurableTask, setMVCCGenerationsState, setQuiesceToken, snapshot, take, take, take, take, take, take, takeById, takeById, takeById, takeById, takeById, takeById, takeById, takeByIds, takeByIds, takeByIds, takeByIds, takeByIds, takeByIds, takeByIds, takeIfExists, takeIfExists, takeIfExists, takeIfExists, takeIfExists, takeIfExists, takeIfExistsById, takeIfExistsById, takeIfExistsById, takeIfExistsById, takeIfExistsById, takeIfExistsById, takeIfExistsById, takeMultiple, takeMultiple, takeMultiple, takeMultiple, takeMultiple, takeMultiple, unregisterDurableTask, write, write, write, write, writeMultiple, writeMultiple, writeMultiple, writeMultiple, writeMultiple, writeMultiple, writeMultiple
-
Method Details
-
registerCluster
Registers a GigaSpace cluster proxy target under a named identifier. The first cluster registered becomes the active one unless an active cluster was already chosen.- Throws:
IllegalArgumentException- if the name is blank, already registered, or the same proxy instance is already registered under a different name
-
unregisterCluster
Unregisters a target cluster by name. If it was the active cluster, the next cluster in the priority list is promoted.- Throws:
IllegalArgumentException- if no cluster is registered under that name
-
unregisterCluster
Unregisters a target cluster by its proxy instance. -
setActiveCluster
Sets the primary active cluster by name. It takes the mutations and, with any read pin dropped, theMultiClusterGigaSpace.ReadMode.READ_ACTIVEreads too - reads and writes are back on one cluster.- See Also:
-
setActiveCluster
Sets the primary active cluster by direct instance reference. -
getActiveClusterName
String getActiveClusterName()Returns the name of the currently designated primary active cluster - the one taking mutations - ornullif none. -
getActiveCluster
GigaSpace getActiveCluster()Returns the currently designated primary active GigaSpace proxy, ornullif none. -
setWriteActiveCluster
MakesclusterNamethe write-active cluster: mutations, transactions, task execution and metadata calls go there. UnlikesetActiveCluster(String)it leaves a pinned read cluster alone; with no pin,READ_ACTIVEreads follow the write role as usual.- Throws:
IllegalArgumentException- if no cluster is registered under that name
-
setReadActiveCluster
PinsMultiClusterGigaSpace.ReadMode.READ_ACTIVEreads toclusterName, separately from the cluster taking mutations - a dedicated read cluster and a dedicated write cluster.Reads served there see a write only once the WAN Gateway or a
WRITE_SYNCfan-out has carried it over, so this gives up read-your-writes. Reads inside a transaction still go to the write-active cluster, where the transaction is. If the pinned cluster becomes unreachable the read role fails over on its own, to the next cluster in priority order that is not taking the writes, and the write role is left alone.MultiClusterGigaSpace.ReadMode.READ_ROUND_ROBINreads ignore the pin.- Throws:
IllegalArgumentException- if no cluster is registered under that name
-
clearReadActiveCluster
void clearReadActiveCluster()Drops the read pin, soREAD_ACTIVEreads follow the write-active cluster again. -
getReadActiveClusterName
String getReadActiveClusterName()The clusterMultiClusterGigaSpace.ReadMode.READ_ACTIVEreads go to: the pinned read cluster, or the active cluster when nothing is pinned.nullif there is neither. -
getReadActiveCluster
GigaSpace getReadActiveCluster()The proxy of the clustergetReadActiveClusterName()names, ornull. -
getRegisteredClusters
-
getCluster
Resolves a GigaSpace proxy by its registered cluster name.- Throws:
IllegalArgumentException- if the name is not registered
-
getClusterName
Resolves the registered cluster name for a given GigaSpace proxy instance.- Throws:
IllegalArgumentException- if the proxy is not registered
-
setWriteMode
-
getWriteMode
MultiClusterGigaSpace.WriteMode getWriteMode() -
setReadMode
-
getReadMode
MultiClusterGigaSpace.ReadMode getReadMode() -
setFailoverPolicy
-
getFailoverPolicy
MultiClusterGigaSpace.FailoverPolicy getFailoverPolicy() -
setClusterPriorityList
Sets the ordered fallback list of cluster names for automated promotion. Registered clusters missing from the list keep their registration order behind the listed ones.- Throws:
IllegalArgumentException- if a name is unknown or listed twice
-
getClusterPriorityList
The order clusters will actually be promoted in: the configured priorities first, then any registered cluster the configuration omits, minus anything removed byremoveClusterFromPriorityList(String)or dropped after a failure.It reports what failover will do rather than what was once configured - a cluster removed on failure is gone from this list, and one registered afterwards appears in it.
-
addClusterToPriorityList
Makes a cluster a promotion candidate again, appended to the configured order if it was not in it.- Returns:
trueif this call changed the list
-
removeClusterFromPriorityList
Removes a cluster from failover promotion without unregistering it.A cluster removed this way is not silently re-appended by the fallback ordering, unlike one that was simply never listed - otherwise a cluster dropped after a failure would be re-elected by the next promotion.
- Returns:
trueif this call changed the list
-
getReadRotation
The clusters currently eligible forMultiClusterGigaSpace.ReadMode.READ_ROUND_ROBINreads, in registration order.Registering a cluster puts it in the rotation. A failure takes it out - and leaves it out until this application decides it is ready, which is what
addClusterToReadRotation(String)is for. -
addClusterToReadRotation
Puts a cluster back into round-robin reads after it was removed.- Returns:
trueif this call changed the rotation
-
removeClusterFromReadRotation
Takes a cluster out of round-robin reads. It stays registered, and stays usable as the active cluster: the rotation governs balanced reads only, so removing the active cluster from it does not stop reads reaching that cluster throughMultiClusterGigaSpace.ReadMode.READ_ACTIVE.- Returns:
trueif this call changed the rotation
-
setFailureThreshold
void setFailureThreshold(int consecutiveFailuresThreshold) Sets the consecutive failure threshold required before marking a cluster unhealthy. -
getFailureThreshold
int getFailureThreshold()Returns the consecutive failure threshold. -
setFailureWindow
Defines the rolling window duration for error threshold evaluation. -
getFailureWindow
Duration getFailureWindow()Returns the rolling failure window. -
isClusterHealthy
Returns true if the cluster identified by name is reachable. -
isClusterHealthy
Returns true if the specified GigaSpace cluster instance is reachable. -
failoverToNextCluster
void failoverToNextCluster()Forcefully triggers failover to the next healthy cluster in the priority list.- Throws:
NoAvailableClusterException- if no other cluster is healthy
-
addClusterStateListener
-
removeClusterStateListener
-
addClusterEventListener
Registers a listener that receives the same events with an explicitClusterEventTyperather than the convention below. -
removeClusterEventListener
-
getStats
MultiClusterStats getStats()Per-cluster operation counters, failures and observed latency. -
close
void close()Releases the resources this proxy owns: background schedulers and the async write queue.Cluster proxies are never among them. Whether a cluster arrived as a
GigaSpaceor as aSpaceConfigurerthe configurer built one from, it belongs to the application - close it yourself, the same way you would close theSpaceConfigurerbehind a plainGigaSpace.- Specified by:
closein interfaceAutoCloseable
-