Java Code Examples for java.util.concurrent.ConcurrentHashMap#keys()

The following examples show how to use java.util.concurrent.ConcurrentHashMap#keys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheUtil.java    From FHIR with Apache License 2.0 6 votes vote down vote up
/**
 * Takes the contents of one of the JDBC PL caches and represents the contents in a format suitable for logging.
 * @param cacheName - The name of the JDBC PL cache to be dumped.
 * @param mapOfMaps - The contents of the multi-datastore cache.
 * @return String - A formatted representation of the cache contents.
 */
public static String dumpCacheContents(String cacheName, ConcurrentHashMap<String,ConcurrentHashMap<String,Integer>> mapOfMaps) {
    
    String cacheKey;
    Enumeration<String> cacheKeys = mapOfMaps.keys();
    ConcurrentHashMap<String,Integer> dbCache;
    StringBuffer dumpedCache = new StringBuffer();
    
    dumpedCache.append(NEWLINE).append("Contents of ").append(cacheName).append(NEWLINE);
    while(cacheKeys.hasMoreElements()) {
        cacheKey = cacheKeys.nextElement();
        dbCache = mapOfMaps.get(cacheKey);
        dumpedCache.append(cacheName).append(" for datastoreid: " + cacheKey).append(NEWLINE);
        dumpedCache.append(dbCache.toString().replaceAll(",", NEWLINE)).append(NEWLINE);
    }
    
    return dumpedCache.toString();
}
 
Example 2
Source File: KhanSessionManager.java    From khan-session with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Cleanup all sessions
 *
 */
public void cleanup() {
    ConcurrentHashMap<String, Long> sessionIds = sessionIdStore.getSessionStore(appName);
    Enumeration<String> keys = sessionIds.keys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        String storeMetaKey = KhanSessionKeyGenerator.generate(khanSessionConfig.getNamespace(), key, KhanHttpSession.METADATA_KEY);
        String storeAttrKey = KhanSessionKeyGenerator.generate(khanSessionConfig.getNamespace(), key, KhanHttpSession.ATTRIBUTES_KEY);

        if( log.isDebugEnabled() ) {
            log.debug("key=" + key);
            log.debug("storeMetaKey=" + storeMetaKey);
            log.debug("storeAttrKey=" + storeAttrKey);
        }

        Object attr = sessionStore.get(storeAttrKey);
        Object meta = sessionStore.get(storeMetaKey);

        if( log.isDebugEnabled() ) {
            log.debug("attr,meta=" + attr + "," + meta);
        }
        if (attr == null && meta == null) {
            sessionIds.remove(key);
        }
    }
}
 
Example 3
Source File: ParameterDynamicZookeeper.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private void syncFromZooKeeper() throws ZkException, IOException {
    ConcurrentHashMap<String/*zk path*/, Set<IZkDataListener>> listeners = zkClient.getDataListener();
    Enumeration<String> paths = listeners.keys();
    while (paths.hasMoreElements()) {
        String path = paths.nextElement();
        initPathData(path);
    }
}
 
Example 4
Source File: ParameterDynamicZookeeper.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private void syncFromZooKeeper() throws ZkException, IOException {
    ConcurrentHashMap<String/*zk path*/, Set<IZkDataListener>> listeners = zkClient.getDataListener();
    Enumeration<String> paths = listeners.keys();
    while (paths.hasMoreElements()) {
        String path = paths.nextElement();
        initPathData(path);
    }
}
 
Example 5
Source File: ConcurrentHashMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * keys returns an enumeration containing all the keys from the map
 */
public void testKeys() {
    ConcurrentHashMap map = map5();
    Enumeration e = map.keys();
    int count = 0;
    while (e.hasMoreElements()) {
        count++;
        e.nextElement();
    }
    assertEquals(5, count);
}
 
Example 6
Source File: HashJoin.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
public CloseableIteration<RyaIRI, RyaDAOException> join(C conf, Map.Entry<RyaIRI, RyaType>... predObjs) throws RyaDAOException {
    ConcurrentHashMap<RyaIRI, Integer> ht = new ConcurrentHashMap<RyaIRI, Integer>();
    int count = 0;
    boolean first = true;
    for (Map.Entry<RyaIRI, RyaType> predObj : predObjs) {
        count++;
        RyaIRI pred = predObj.getKey();
        RyaType obj = predObj.getValue();
        //query
        CloseableIteration<RyaStatement, RyaDAOException> results = ryaQueryEngine.query(new RyaStatement(null, pred, obj), null);
        //add to hashtable
        while (results.hasNext()) {
            RyaIRI subject = results.next().getSubject();
            if (!first) {
                if (!ht.containsKey(subject)) {
                    continue; //not in join
                }
            }
            ht.put(subject, count);
        }
        //remove from hashtable values that are under count
        if (first) {
            first = false;
        } else {
            for (Map.Entry<RyaIRI, Integer> entry : ht.entrySet()) {
                if (entry.getValue() < count) {
                    ht.remove(entry.getKey());
                }
            }
        }
    }
    return new EnumerationWrapper<RyaIRI, RyaDAOException>(ht.keys());
}
 
Example 7
Source File: ConcurrentHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * keys returns an enumeration containing all the keys from the map
 */
public void testKeys() {
    ConcurrentHashMap map = map5();
    Enumeration e = map.keys();
    int count = 0;
    while (e.hasMoreElements()) {
        count++;
        e.nextElement();
    }
    assertEquals(5, count);
}
 
Example 8
Source File: LoggingRegistry.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Helper Method that determines a LogChannelFileWriterBuffer invoked by getLogChannelFileWriterBuffer and returns 1.
 * @param possibleWriters  Map to search from.
 * @return LogChannelFileWriterBuffer, null if could not be determined.
 */
private LogChannelFileWriterBuffer determineLogChannelFileWriterBuffer( ConcurrentHashMap<LogChannelFileWriterBuffer,
  List<String>> possibleWriters ) {

  // Just one writer so just return it
  if ( possibleWriters.size() == 1 ) {
    return possibleWriters.keys().nextElement();
  } else {

    // Several possibilities, so, lets get the writer among them that is the "lowest in the chain",
    // meaning, the one that is not a parent of the others
    Enumeration<LogChannelFileWriterBuffer> possibleWritersIds = possibleWriters.keys();
    while ( possibleWritersIds.hasMoreElements() ) {
      LogChannelFileWriterBuffer writer = possibleWritersIds.nextElement();

      for ( Map.Entry<LogChannelFileWriterBuffer, List<String>> entry : possibleWriters.entrySet() ) {
        if ( entry.getKey().equals( writer ) ) {
          continue;
        }
        if ( !entry.getValue().contains( writer.getLogChannelId() ) ) {
          return entry.getKey();
        }
      }
    }
  }

  return null;
}
 
Example 9
Source File: LongConcurrentHashMapWrap.java    From jane with GNU Lesser General Public License v3.0 4 votes vote down vote up
private KeyIterator(ConcurrentHashMap<Long, V> map)
{
	it = map.keys();
}