com.gemstone.gemfire.cache.LossAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.cache;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import java.io.*;
import java.util.*;
/**
* Specifies how access to the region is affected when one or more required
* roles are lost. A role is lost when it is are offline and no longer
* present in the system membership.
* The LossAction
is specified when configuring a region's
* {@link com.gemstone.gemfire.cache.MembershipAttributes}.
*
* @author Kirk Lund
* @since 5.0
*/
public class LossAction implements Serializable {
private static final long serialVersionUID = -832035480397447797L;
// NOTE: to change/add these files are impacted:
// LossAction, package.html
/**
* The region is unavailable when required roles are missing. All operations
* including read and write access are denied. All read and write operations
* on the region will result in {@link RegionAccessException} while any
* required roles are absent. Basic administration of the region is allowed,
* including {@linkplain Region#close close} and
* {@linkplain Region#localDestroyRegion() localDestroyRegion}.
*/
public static final LossAction NO_ACCESS =
new LossAction("NO_ACCESS");
/**
* Only local access to the region is allowed when required roles are
* missing. All distributed write operations on the region will throw
* {@link RegionAccessException} while any required roles are absent.
* Reads which result in a netSearch behave normally, while any attempt
* to invoke a netLoad is not allowed.
*/
public static final LossAction LIMITED_ACCESS =
new LossAction("LIMITED_ACCESS");
/**
* Access to the region is unaffected when required roles are missing.
*/
public static final LossAction FULL_ACCESS =
new LossAction("FULL_ACCESS");
/**
* Loss of required roles causes the entire cache to be closed. In addition,
* this process will disconnect from the DistributedSystem and then
* reconnect. Attempting to use any existing references to the regions
* or cache will throw a {@link CacheClosedException}.
*/
public static final LossAction RECONNECT =
new LossAction("RECONNECT");
/** The name of this mirror type. */
private final transient String name;
// The 4 declarations below are necessary for serialization
/** byte used as ordinal to represent this Scope */
public final byte ordinal = nextOrdinal++;
private static byte nextOrdinal = 0;
private static final LossAction[] PRIVATE_VALUES =
{ NO_ACCESS, LIMITED_ACCESS, FULL_ACCESS, RECONNECT };
/** List of all LossAction values */
public static final List VALUES =
Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES));
private Object readResolve() throws ObjectStreamException {
return PRIVATE_VALUES[ordinal]; // Canonicalize
}
/** Creates a new instance of LossAction. */
private LossAction(String name) {
this.name = name;
}
/** Return the LossAction represented by specified ordinal */
public static LossAction fromOrdinal(byte ordinal) {
return PRIVATE_VALUES[ordinal];
}
/** Return the LossAction specified by name */
public static LossAction fromName(String name) {
if (name == null || name.length() == 0) {
throw new IllegalArgumentException(LocalizedStrings.LossAction_INVALID_LOSSACTION_NAME_0.toLocalizedString(name));
}
for (int i = 0; i < PRIVATE_VALUES.length; i++) {
if (name.equals(PRIVATE_VALUES[i].name)) {
return PRIVATE_VALUES[i];
}
}
throw new IllegalArgumentException(LocalizedStrings.LossAction_INVALID_LOSSACTION_NAME_0.toLocalizedString(name));
}
/** Returns true if this is NO_ACCESS
. */
public boolean isNoAccess() {
return this == NO_ACCESS;
}
/** Returns true if this is LIMITED_ACCESS
. */
public boolean isLimitedAccess() {
return this == LIMITED_ACCESS;
}
/** Returns true if this is FULL_ACCESS
. */
public boolean isAllAccess() {
return this == FULL_ACCESS;
}
/** Returns true if this is RECONNECT
. */
public boolean isReconnect() {
return this == RECONNECT;
}
/**
* Returns a string representation for this loss action.
* @return the name of this loss action
*/
@Override
public String toString() {
return this.name;
}
}