Search in sources :

Example 1 with SplitBrainProtectionOn

use of com.hazelcast.splitbrainprotection.SplitBrainProtectionOn in project hazelcast by hazelcast.

the class SplitBrainProtectionServiceImpl method ensureNoSplitBrain.

public void ensureNoSplitBrain(@Nullable String splitBrainProtectionName, @Nonnull SplitBrainProtectionOn requiredSplitBrainProtectionPermissionType) {
    checkNotNull(requiredSplitBrainProtectionPermissionType, "requiredSplitBrainProtectionPermissionType cannot be null!");
    if (isInactive() || splitBrainProtectionName == null) {
        return;
    }
    SplitBrainProtectionImpl definedSplitBrainProtection = splitBrainProtections.get(splitBrainProtectionName);
    if (definedSplitBrainProtection == null) {
        return;
    }
    SplitBrainProtectionOn definedSplitBrainProtectionOn = definedSplitBrainProtection.getConfig().getProtectOn();
    switch(requiredSplitBrainProtectionPermissionType) {
        case WRITE:
            if (definedSplitBrainProtectionOn.equals(WRITE) || definedSplitBrainProtectionOn.equals(READ_WRITE)) {
                definedSplitBrainProtection.ensureNoSplitBrain();
            }
            break;
        case READ:
            if (definedSplitBrainProtectionOn.equals(READ) || definedSplitBrainProtectionOn.equals(READ_WRITE)) {
                definedSplitBrainProtection.ensureNoSplitBrain();
            }
            break;
        case READ_WRITE:
            if (definedSplitBrainProtectionOn.equals(READ_WRITE)) {
                definedSplitBrainProtection.ensureNoSplitBrain();
            }
            break;
        default:
            throw new IllegalStateException("Unhandled split brain protection type: " + requiredSplitBrainProtectionPermissionType);
    }
}
Also used : SplitBrainProtectionOn(com.hazelcast.splitbrainprotection.SplitBrainProtectionOn)

Aggregations

SplitBrainProtectionOn (com.hazelcast.splitbrainprotection.SplitBrainProtectionOn)1