use of org.apache.geode.cache.ResumptionAction in project geode by apache.
the class CacheXmlParser method endMembershipAttributes.
/**
* When a <code>membership-attributes</code> element is finished, the arguments for constructing
* the MembershipAttributes are on the stack.
*/
private void endMembershipAttributes() {
Set roles = new HashSet();
Object obj = null;
while (!(obj instanceof Object[])) {
obj = stack.pop();
if (obj instanceof String) {
// found a required-role name
roles.add(obj);
}
}
Object[] attrs = (Object[]) obj;
String laName = ((String) attrs[0]).toUpperCase().replace('-', '_');
String raName = ((String) attrs[1]).toUpperCase().replace('-', '_');
LossAction laction = LossAction.fromName(laName);
ResumptionAction raction = ResumptionAction.fromName(raName);
MembershipAttributes ra = new MembershipAttributes((String[]) roles.toArray(new String[roles.size()]), laction, raction);
RegionAttributesCreation rattrs = (RegionAttributesCreation) stack.peek();
rattrs.setMembershipAttributes(ra);
}
use of org.apache.geode.cache.ResumptionAction in project geode by apache.
the class CacheXml66DUnitTest method testMembershipAttributes.
/**
* Test xml support of MembershipAttributes.
*/
@Test
public void testMembershipAttributes() throws Exception {
final String MY_ROLES = "Foo, Bip, BAM";
final String[][] roles = new String[][] { { "Foo" }, { "Bip", "BAM" } };
final LossAction[] policies = (LossAction[]) LossAction.VALUES.toArray(new LossAction[LossAction.VALUES.size()]);
final ResumptionAction[] actions = (ResumptionAction[]) ResumptionAction.VALUES.toArray(new ResumptionAction[ResumptionAction.VALUES.size()]);
CacheCreation cache = new CacheCreation();
// for each policy, try each action and each role...
for (int policy = 0; policy < policies.length; policy++) {
for (int action = 0; action < actions.length; action++) {
for (int role = 0; role < roles.length; role++) {
String[] theRoles = roles[role];
LossAction thePolicy = policies[policy];
ResumptionAction theAction = actions[action];
// if (theRoles.length == 0 && (thePolicy != LossAction.NONE || theAction !=
// ResumptionAction.NONE
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
MembershipAttributes ra = new MembershipAttributes(theRoles, thePolicy, theAction);
attrs.setMembershipAttributes(ra);
String region = "rootMEMBERSHIP_ATTRIBUTES_" + policy + "_" + action + "_" + role;
cache.createRegion(region, attrs);
}
}
}
{
// make our system play the roles used by this test so the create regions
// will not think the a required role is missing
Properties config = new Properties();
config.setProperty(ROLES, MY_ROLES);
this.xmlProps = config;
}
DistributedRegion.ignoreReconnect = true;
try {
testXml(cache);
} finally {
this.xmlProps = null;
try {
preTearDown();
} finally {
DistributedRegion.ignoreReconnect = false;
}
}
}
use of org.apache.geode.cache.ResumptionAction in project geode by apache.
the class DistributedRegion method asyncResumeReliability.
/**
* Handles asynchronous ResumptionActions such as region reinitialize.
*/
private void asyncResumeReliability(final InternalDistributedMember id, final Set newlyAcquiredRoles) throws RejectedExecutionException {
final ResumptionAction ra = getMembershipAttributes().getResumptionAction();
getDistributionManager().getWaitingThreadPool().execute(new Runnable() {
@Override
public void run() {
try {
if (ra.isReinitialize()) {
if (logger.isDebugEnabled()) {
logger.debug("Reliability resumption for action of reinitialize");
}
if (!isDestroyed() && !cache.isClosed()) {
RegionEventImpl event = new RegionEventImpl(DistributedRegion.this, Operation.REGION_REINITIALIZE, null, false, getMyId(), generateEventID());
reinitialize(null, event);
}
synchronized (missingRequiredRoles) {
// any number of threads may be waiting on missingRequiredRoles
missingRequiredRoles.notifyAll();
if (hasListener() && id != null) {
// fire afterRoleGain event
RoleEventImpl relEvent = new RoleEventImpl(DistributedRegion.this, Operation.REGION_CREATE, null, true, id, newlyAcquiredRoles);
dispatchListenerEvent(EnumListenerEvent.AFTER_ROLE_GAIN, relEvent);
}
}
}
} catch (Exception e) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.DistributedRegion_UNEXPECTED_EXCEPTION), e);
}
}
});
}
Aggregations