Search in sources :

Example 1 with LossAction

use of org.apache.geode.cache.LossAction 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);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LossAction(org.apache.geode.cache.LossAction) ResumptionAction(org.apache.geode.cache.ResumptionAction) HashSet(java.util.HashSet) MembershipAttributes(org.apache.geode.cache.MembershipAttributes)

Example 2 with LossAction

use of org.apache.geode.cache.LossAction 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;
        }
    }
}
Also used : LossAction(org.apache.geode.cache.LossAction) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Properties(java.util.Properties) ResumptionAction(org.apache.geode.cache.ResumptionAction) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) Test(org.junit.Test)

Aggregations

LossAction (org.apache.geode.cache.LossAction)2 MembershipAttributes (org.apache.geode.cache.MembershipAttributes)2 ResumptionAction (org.apache.geode.cache.ResumptionAction)2 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)1 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)1 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)1 Test (org.junit.Test)1