下面列出了java.util.concurrent.ConcurrentHashMap#keys ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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();
}
/**
* 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);
}
}
}
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);
}
}
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);
}
}
/**
* 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);
}
@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());
}
/**
* 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);
}
/**
* 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;
}
private KeyIterator(ConcurrentHashMap<Long, V> map)
{
it = map.keys();
}