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();
}
}));
}
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);
}
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;
}
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;
}
}
}
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
}
Aggregations