Search in sources :

Example 76 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project hadoop by apache.

the class InstrumentationService method init.

@Override
@SuppressWarnings("unchecked")
public void init() throws ServiceException {
    timersSize = getServiceConfig().getInt(CONF_TIMERS_SIZE, 10);
    counterLock = new ReentrantLock();
    timerLock = new ReentrantLock();
    variableLock = new ReentrantLock();
    samplerLock = new ReentrantLock();
    Map<String, VariableHolder> jvmVariables = new ConcurrentHashMap<String, VariableHolder>();
    counters = new ConcurrentHashMap<String, Map<String, AtomicLong>>();
    timers = new ConcurrentHashMap<String, Map<String, Timer>>();
    variables = new ConcurrentHashMap<String, Map<String, VariableHolder>>();
    samplers = new ConcurrentHashMap<String, Map<String, Sampler>>();
    samplersList = new ArrayList<Sampler>();
    all = new LinkedHashMap<String, Map<String, ?>>();
    all.put("os-env", System.getenv());
    all.put("sys-props", (Map<String, ?>) (Map) System.getProperties());
    all.put("jvm", jvmVariables);
    all.put("counters", (Map) counters);
    all.put("timers", (Map) timers);
    all.put("variables", (Map) variables);
    all.put("samplers", (Map) samplers);
    jvmVariables.put("free.memory", new VariableHolder<Long>(new Instrumentation.Variable<Long>() {

        @Override
        public Long getValue() {
            return Runtime.getRuntime().freeMemory();
        }
    }));
    jvmVariables.put("max.memory", new VariableHolder<Long>(new Instrumentation.Variable<Long>() {

        @Override
        public Long getValue() {
            return Runtime.getRuntime().maxMemory();
        }
    }));
    jvmVariables.put("total.memory", new VariableHolder<Long>(new Instrumentation.Variable<Long>() {

        @Override
        public Long getValue() {
            return Runtime.getRuntime().totalMemory();
        }
    }));
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 77 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project OpenAM by OpenRock.

the class OpenAMTokenStoreTest method shouldReadAccessToken.

@Test
public void shouldReadAccessToken() throws Exception {
    //Given
    JsonValue token = json(object(field("tokenName", Collections.singleton("access_token")), field("realm", Collections.singleton("/testrealm"))));
    given(tokenStore.read("TOKEN_ID")).willReturn(token);
    ConcurrentHashMap<String, Object> attributes = new ConcurrentHashMap<String, Object>();
    attributes.put("realm", "/testrealm");
    given(request.getAttributes()).willReturn(attributes);
    given(realmNormaliser.normalise("/testrealm")).willReturn("/testrealm");
    OAuth2Request request = oAuth2RequestFactory.create(this.request);
    //When
    AccessToken accessToken = openAMtokenStore.readAccessToken(request, "TOKEN_ID");
    //Then
    assertThat(accessToken).isNotNull();
    assertThat(request.getToken(AccessToken.class)).isSameAs(accessToken);
}
Also used : RestletOAuth2Request(org.forgerock.oauth2.restlet.RestletOAuth2Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) AccessToken(org.forgerock.oauth2.core.AccessToken) JsonValue(org.forgerock.json.JsonValue) BDDMockito.anyString(org.mockito.BDDMockito.anyString) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 78 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project pcgen by PCGen.

the class BonusManager method getPartialStatBonusFor.

public int getPartialStatBonusFor(PCStat stat, boolean useTemp, boolean useEquip) {
    String statAbbr = stat.getKeyName();
    final String prefix = "STAT." + statAbbr;
    Map<String, String> bonusMap = new HashMap<>();
    Map<String, String> nonStackMap = new ConcurrentHashMap<>();
    Map<String, String> stackMap = new ConcurrentHashMap<>();
    for (BonusObj bonus : getActiveBonusList()) {
        if (pc.isApplied(bonus) && bonus.getBonusName().equals("STAT")) {
            boolean found = false;
            Object co = getSourceObject(bonus);
            for (Object element : bonus.getBonusInfoList()) {
                if (element instanceof PCStat && element.equals(stat)) {
                    found = true;
                    break;
                }
                // parisng.
                if (element instanceof MissingObject) {
                    String name = ((MissingObject) element).getObjectName();
                    if (("%LIST".equals(name) || "LIST".equals(name)) && co instanceof CDOMObject) {
                        CDOMObject creator = (CDOMObject) co;
                        for (String assoc : pc.getConsolidatedAssociationList(creator)) {
                            //TODO Case sensitivity?
                            if (assoc.contains(statAbbr)) {
                                found = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (!found) {
                continue;
            }
            // The bonus has been applied to the target stat
            // Should it be included?
            boolean addIt = false;
            if (co instanceof Equipment || co instanceof EquipmentModifier) {
                addIt = useEquip;
            } else if (co instanceof Ability) {
                List<String> types = ((Ability) co).getTypes();
                if (types.contains("Equipment")) {
                    addIt = useEquip;
                } else {
                    addIt = true;
                }
            } else if (tempBonusBySource.containsKey(bonus)) {
                addIt = useTemp;
            } else {
                addIt = true;
            }
            if (addIt) {
                // bonuses with the stacking rules applied.
                for (BonusPair bp : getStringListFromBonus(bonus)) {
                    if (bp.fullyQualifiedBonusType.startsWith(prefix)) {
                        setActiveBonusStack(bp.resolve(pc).doubleValue(), bp.fullyQualifiedBonusType, nonStackMap, stackMap);
                        totalBonusesForType(nonStackMap, stackMap, bp.fullyQualifiedBonusType, bonusMap);
                    }
                }
            }
        }
    }
    // Sum the included bonuses to the stat to get our result.
    int total = 0;
    for (String bKey : bonusMap.keySet()) {
        total += Float.parseFloat(bonusMap.get(bKey));
    }
    return total;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BonusPair(pcgen.core.bonus.BonusPair) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) MissingObject(pcgen.core.bonus.util.MissingObject) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MissingObject(pcgen.core.bonus.util.MissingObject)

Example 79 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project pcgen by PCGen.

the class BonusManager method buildActiveBonusMap.

/**
	 * Build the bonus HashMap from all active BonusObj's
	 */
void buildActiveBonusMap() {
    activeBonusMap = new ConcurrentHashMap<>();
    cachedActiveBonusSumsMap = new ConcurrentHashMap<>();
    Map<String, String> nonStackMap = new ConcurrentHashMap<>();
    Map<String, String> stackMap = new ConcurrentHashMap<>();
    Set<BonusObj> processedBonuses = new WrappedMapSet<>(IdentityHashMap.class);
    //Logging.log(Logging.INFO, "=== Start bonus processing.");
    //
    // We do a first pass of just the "static" bonuses
    // as they require less computation and no recursion
    List<BonusObj> bonusListCopy = new ArrayList<>();
    bonusListCopy.addAll(getActiveBonusList());
    for (BonusObj bonus : bonusListCopy) {
        if (!bonus.isValueStatic()) {
            continue;
        }
        final Object source = getSourceObject(bonus);
        if (source == null) {
            if (Logging.isDebugMode()) {
                Logging.debugPrint("BONUS: " + bonus + " ignored due to no creator");
            }
            continue;
        }
        // Keep track of which bonuses have been calculated
        //Logging.log(Logging.INFO, "Processing bonus " + bonus + " - static.");
        processedBonuses.add(bonus);
        for (BonusPair bp : getStringListFromBonus(bonus)) {
            final double iBonus = bp.resolve(pc).doubleValue();
            setActiveBonusStack(iBonus, bp.fullyQualifiedBonusType, nonStackMap, stackMap);
            totalBonusesForType(nonStackMap, stackMap, bp.fullyQualifiedBonusType, activeBonusMap);
            if (Logging.isDebugMode()) {
                String id;
                if (source instanceof CDOMObject) {
                    id = ((CDOMObject) source).getDisplayName();
                } else {
                    id = source.toString();
                }
                Logging.debugPrint("BONUS: " + id + " : " + iBonus + " : " + bp.fullyQualifiedBonusType);
            }
        }
    }
    //
    // Now we do all the BonusObj's that require calculations
    bonusListCopy = new ArrayList<>();
    bonusListCopy.addAll(getActiveBonusList());
    for (BonusObj bonus : getActiveBonusList()) {
        if (processedBonuses.contains(bonus)) {
            continue;
        }
        final CDOMObject anObj = (CDOMObject) getSourceObject(bonus);
        if (anObj == null) {
            continue;
        }
        try {
            processBonus(bonus, new WrappedMapSet<>(IdentityHashMap.class), processedBonuses, nonStackMap, stackMap);
        } catch (Exception e) {
            Logging.errorPrint(e.getLocalizedMessage(), e);
            continue;
        }
    }
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) BonusPair(pcgen.core.bonus.BonusPair) CDOMObject(pcgen.cdom.base.CDOMObject) WrappedMapSet(pcgen.base.util.WrappedMapSet) CDOMObject(pcgen.cdom.base.CDOMObject) MissingObject(pcgen.core.bonus.util.MissingObject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 80 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project OpenAM by OpenRock.

the class OpenAMTokenStoreTest method shouldNotReadOtherRealmsAccessToken.

@Test(expectedExceptions = InvalidGrantException.class)
public void shouldNotReadOtherRealmsAccessToken() throws Exception {
    //Given
    JsonValue token = json(object(field("tokenName", Collections.singleton("access_token")), field("realm", Collections.singleton("/otherrealm"))));
    given(tokenStore.read("TOKEN_ID")).willReturn(token);
    given(realmNormaliser.normalise("/otherrealm")).willReturn("/otherrealm");
    ConcurrentHashMap<String, Object> attributes = new ConcurrentHashMap<String, Object>();
    given(request.getAttributes()).willReturn(attributes);
    attributes.put("realm", "/testrealm");
    OAuth2Request request = oAuth2RequestFactory.create(this.request);
    //When
    AccessToken accessToken = openAMtokenStore.readAccessToken(request, "TOKEN_ID");
//Then
// expect InvalidGrantException
}
Also used : RestletOAuth2Request(org.forgerock.oauth2.restlet.RestletOAuth2Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) AccessToken(org.forgerock.oauth2.core.AccessToken) JsonValue(org.forgerock.json.JsonValue) BDDMockito.anyString(org.mockito.BDDMockito.anyString) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)420 Map (java.util.Map)106 Test (org.junit.Test)102 HashMap (java.util.HashMap)75 ArrayList (java.util.ArrayList)73 CountDownLatch (java.util.concurrent.CountDownLatch)53 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)49 IOException (java.io.IOException)47 List (java.util.List)38 Set (java.util.Set)36 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)33 HashSet (java.util.HashSet)31 AtomicLong (java.util.concurrent.atomic.AtomicLong)29 ConcurrentMap (java.util.concurrent.ConcurrentMap)28 Random (java.util.Random)25 ExecutorService (java.util.concurrent.ExecutorService)23 Collection (java.util.Collection)20 UUID (java.util.UUID)20 Iterator (java.util.Iterator)19 Configuration (org.apache.hadoop.conf.Configuration)17