Java Code Examples for java.util.concurrent.ConcurrentHashMap

The following are top voted examples for showing how to use java.util.concurrent.ConcurrentHashMap. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: magate   File: MaGateRecorder.java View source code Vote up 7 votes
/**
 * Logging remote-node reputation list of each participating node
 * 
 * @param resultPerScenario
 */
private static void nodeTrustAnalysis(LinkedList<MaGateStorage> resultPerScenario) {
	
	Format formatter = new SimpleDateFormat("yyyy.MM.dd 'at' HH.mm.ss");
	
	String nodeTrustRecord = "\n\n\n------------------------ \n\n" +
		"ScenarioId: " + MaGateParam.currentScenarioId + " | Number of experiments: " + MaGateParam.countOfExperiment +  
		"; Real-SysStartTime: " + formatter.format(GlobalStorage.systemStartTime) + 
		"; Real-SystEndTime: " + formatter.format(new Date()) + "\n";


	// print statistic of node networking
	nodeTrustRecord += "\n------------------------\n   each participating node's remote-node reputation list   \n------------------------\n\n";

	for(MaGateStorage perMaGateStorage : resultPerScenario) {
		
		String currentNodeId = perMaGateStorage.getMaGateIdentity();
		double numOfGoodNode = 0.0;
		ConcurrentHashMap<String, RemoteNodeReputationItem> currentRemoteNodeReputation = perMaGateStorage.get_remoteNodeReputationList();
		
		String reputationLogString = "Node: " + currentNodeId + "\n";
		for(Map.Entry<String, RemoteNodeReputationItem> entry: currentRemoteNodeReputation.entrySet()) {
			String remoteNodeId = entry.getKey();
			double remoteNodeReputation = entry.getValue().getRemodeNodeReputation();
			
			reputationLogString += remoteNodeId + ": " + remoteNodeReputation + "; ";
			if(remoteNodeReputation >= 0.6) {
				numOfGoodNode++;
			}
		}
		
		nodeTrustRecord += reputationLogString;
		nodeTrustRecord += "\n[CF node probability (reputation >= 0.6)]: " + (numOfGoodNode / currentRemoteNodeReputation.size());
		nodeTrustRecord += "\nNumber of interacted nodes: " + currentRemoteNodeReputation.size();
		nodeTrustRecord +=  "\n\n\n";
	}
	
	MaGateToolkit.writeResult(GlobalStorage.trustTopologyLogFile, nodeTrustRecord);
}
 
Example 2
Project: fiji   File: FeatureModel.java View source code Vote up 6 votes
public synchronized void putEdgeFeature(DefaultWeightedEdge edge, final String featureName, final Double featureValue) {
	ConcurrentHashMap<String, Double> map = edgeFeatureValues.get(edge);
	if (null == map) {
		map = new ConcurrentHashMap<String, Double>();
		edgeFeatureValues.put(edge, map);
	}
	map.put(featureName, featureValue);
}
 
Example 3
Project: AIDR   File: ChannelBufferManager.java View source code Vote up 6 votes
private int deleteMapRecordsForCollection(final String deleteCollectionCode, ConcurrentHashMap<CounterKey, Object> dataMap) {
	int count = 0;
	Iterator<CounterKey> itr = dataMap.keySet().iterator();
	while (itr.hasNext()) {
		CounterKey keyVal = itr.next();
		MapRecord data = (MapRecord) dataMap.get(keyVal);
		if (keyVal.getCrisisCode().equals(deleteCollectionCode) && data != null && data.isCountZeroForAllGranularity()) {
			synchronized (dataMap) {		// prevent modification while deletion attempt
				dataMap.remove(keyVal);
				++count;
			}
		}
	}
	return count;
}
 
Example 4
Project: Roid-Library   File: PersistentCookieStore.java View source code Vote up 6 votes
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
}
 
Example 5
Project: hazelcast-archive   File: EntryListenerManager.java View source code Vote up 6 votes
public synchronized void registerListener(String name, Object key, boolean includeValue, EntryListener<?, ?> entryListener) {
    ConcurrentHashMap<Object, List<EntryListenerHolder>> map = entryListeners.get(name);
    key = toKey(key);
    if (map == null) {
        map = new ConcurrentHashMap<Object, List<EntryListenerHolder>>();
        final ConcurrentHashMap<Object, List<EntryListenerHolder>> map2 = entryListeners.putIfAbsent(name, map);
        if (map2 != null) {
            map = map2;
        }
    }
    if (!map.contains(key)) {
        map.putIfAbsent(key, new CopyOnWriteArrayList<EntryListenerHolder>());
    }
    map.get(key).add(new EntryListenerHolder(entryListener, includeValue));
}
 
Example 6
Project: visuwall   File: SessionTrackerImpl.java View source code Vote up 6 votes
public SessionTrackerImpl(SessionExpirer expirer,
        ConcurrentHashMap<Long, Integer> sessionsWithTimeout, int tickTime,
        long sid)
{
    super("SessionTracker");
    this.expirer = expirer;
    this.expirationInterval = tickTime;
    this.sessionsWithTimeout = sessionsWithTimeout;
    nextExpirationTime = roundToInterval(System.currentTimeMillis());
    this.nextSessionId = initializeNextSession(sid);
    for (Entry<Long, Integer> e : sessionsWithTimeout.entrySet()) {
        addSession(e.getKey(), e.getValue());
    }
}
 
Example 7
Project: ServiceFramework   File: API.java View source code Vote up 6 votes
public synchronized void statusIncrement(Method api, int status) {
    if (!enable() || api == null) return;
    ConcurrentHashMap<Integer, AtomicLong> chm = APISTATUS.get(api);
    if (!chm.containsKey(status)) {
        chm.put(status, new AtomicLong());
    }
    chm.get(status).incrementAndGet();
}
 
Example 8
Project: Dempsy   File: Router.java View source code Vote up 6 votes
public void stop()
{
   // stop the MpClusterSession first so that ClusterRouters wont
   //  be notified after their stopped.
   try { if(mpClusterSession != null) mpClusterSession.stop(); }
   catch(Throwable th) 
   {
      logger.error("Stopping the cluster session " + SafeString.objectDescription(mpClusterSession) + " caused an exception:", th);
   }

   // flatten out then stop all of the ClusterRouters
   ConcurrentHashMap<Class<?>, Set<ClusterRouter>> map = routerMap;
   routerMap = null;
   Set<ClusterRouter> routers = new HashSet<ClusterRouter>();
   for (Collection<ClusterRouter> curRouters : map.values())
      routers.addAll(curRouters);
   for (ClusterRouter router : routers)
      router.stop();
   for (RoutingStrategy.Outbound ob : outbounds)
      ob.stop();
}
 
Example 9
Project: gluu-opendj   File: LockManager.java View source code Vote up 6 votes
/**
 * Recreates the lock table.  This should be called only in the
 * case that the Directory Server is in the process of an in-core
 * restart because it will destroy the existing lock table.
 */
public synchronized static void reinitializeLockTable()
{
  ConcurrentHashMap<DN,ReentrantReadWriteLock> oldTable = lockTable;

  DirectoryEnvironmentConfig environmentConfig =
       DirectoryServer.getEnvironmentConfig();
  lockTable = new ConcurrentHashMap<DN,ReentrantReadWriteLock>(
       environmentConfig.getLockManagerTableSize(),
       DEFAULT_LOAD_FACTOR,
       environmentConfig.getLockManagerConcurrencyLevel());

  if  (! oldTable.isEmpty())
  {
    for (DN dn : oldTable.keySet())
    {
      try
      {
        ReentrantReadWriteLock lock = oldTable.get(dn);
        if (lock.isWriteLocked())
        {
          TRACER.debugWarning("Found stale write lock on " +
                              dn.toString());
        }
        else if (lock.getReadLockCount() > 0)
        {
          TRACER.debugWarning("Found stale read lock on " +
                              dn.toString());
        }
        else
        {
          TRACER.debugWarning("Found stale unheld lock on " +
                              dn.toString());
        }
      }
      catch (Exception e)
      {
        if (debugEnabled())
        {
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }
      }
    }

    oldTable.clear();
  }

  fair = environmentConfig.getLockManagerFairOrdering();
}
 
Example 10
Project: keycloak   File: InfinispanCacheUserProviderFactory.java View source code Vote up 6 votes
public void remove(String realm, String key) {
    ConcurrentHashMap<String, String> map = lookup.get(realm);
    if (map != null) {
        map.remove(key);
        if (map.isEmpty()) {
            lookup.remove(realm);
        }
    }
}
 
Example 11
Project: esb-java   File: ESBSessionUtils.java View source code Vote up 6 votes
/**
 * ?Session?????????????????
 *
 * @Description ?Session?????????????????
 * @param data
 *            ???????
 * @history ??????????????????????
 */
public static void putTempDataIntoSystemContext(Map<Object, Object> data) {
    if (data == null) {
        return;
    }

    BaseSession session = ESBServerContext.getSession();
    ConcurrentHashMap<Object, Object> context = session.getSystemContext();
    if (context == null) {
        synchronized (session) {
            context = session.getSystemContext();
            if (context == null) {
                context = new ConcurrentHashMap<Object, Object>(5);
                session.setSystemContext(context);
            }
        }
    }
    context.putAll(data);
}