You can optionally create a GatewayConflictResolver cache plug-in to decide whether a potentially conflicting event that was delivered from another site should be applied to the local cache.
By default, all regions perform consistency checks when a member applies an update received either from another cluster member or from a remote cluster over the WAN. The default consistency checking for WAN events is described in How Consistency Is Achieved in WAN Deployments.
You can override the default consistency checking behavior by writing and configuring a custom GatewayConflictResolver. The GatewayConflictResolver implementation can use the timestamp and distributed system ID included in a WAN update event to determine whether or not to apply the update. For example, you may decide that updates from a particular cluster should always "win" a conflict when the timestamp difference between updates is less than some fixed period of time.
vFabric GemFire installs an example GatewayConflictResolver implementation in the SampleCode\examples\dist\wanActiveActive subdirectory of the GemFire installation.
public void onEvent(TimestampedEntryEvent event, GatewayConflictHelper helper) {
if (event.getOperation().isUpdate()) {
ShoppingCart oldCart = (ShoppingCart)event.getOldValue();
ShoppingCart newCart = (ShoppingCart)event.getNewValue();
oldCart.updateFromConflictingState(newCart);
helper.changeEventValue(oldCart);
}
}
cache.xml
<region name="cart">
<region-attributes ... >
<gateway-conflict-resolver>
<class-name>myPackage.MyConflictResolver</class-name>
</gateway-conflict-resolver>
</region-attributes>
</region>
Java API
// Create or obtain the GemFire cache Cache cache = new CacheFactory().create(); // Create and add a conflict resolver cache.setGatewayConflictResolver(new MyConflictResolver);