當前位置: 首頁>>代碼示例>>Java>>正文


Java ConcurrentHashMap.containsKey方法代碼示例

本文整理匯總了Java中java.util.concurrent.ConcurrentHashMap.containsKey方法的典型用法代碼示例。如果您正苦於以下問題:Java ConcurrentHashMap.containsKey方法的具體用法?Java ConcurrentHashMap.containsKey怎麽用?Java ConcurrentHashMap.containsKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.ConcurrentHashMap的用法示例。


在下文中一共展示了ConcurrentHashMap.containsKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: cacheStatement

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
public boolean cacheStatement(CachedStatement proxy) {
    @SuppressWarnings("unchecked")
    ConcurrentHashMap<CacheKey,CachedStatement> cache =
        (ConcurrentHashMap<CacheKey,CachedStatement>)pcon.getAttributes().get(STATEMENT_CACHE_ATTR);
    if (proxy.getCacheKey()==null) {
        return false;
    } else if (cache.containsKey(proxy.getCacheKey())) {
        return false;
    } else if (cacheSize.get()>=maxCacheSize) {
        return false;
    } else if (cacheSize.incrementAndGet()>maxCacheSize) {
        cacheSize.decrementAndGet();
        return false;
    } else {
        //cache the statement
        cache.put(proxy.getCacheKey(), proxy);
        return true;
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:20,代碼來源:StatementCache.java

示例2: callEvent

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * Invokes all event listeners for the type of this given event instance with the given event instance
 * @param event the event instance
 */
public void callEvent(Event event) {
    ConcurrentHashMap<EventPrio, ArrayList<Listener>> listeners = eventListener.getOrDefault(event.getClass().getName(), new ConcurrentHashMap<>());

    if (listeners.containsKey(EventPrio.LOWEST))
        listeners.get(EventPrio.LOWEST).forEach(listener -> listener.invoke(event));

    if (listeners.containsKey(EventPrio.LOW))
        listeners.get(EventPrio.LOW).forEach(listener -> listener.invoke(event));

    if (listeners.containsKey(EventPrio.NORMAL))
        listeners.get(EventPrio.NORMAL).forEach(listener -> listener.invoke(event));

    if (listeners.containsKey(EventPrio.HIGH))
        listeners.get(EventPrio.HIGHEST).forEach(listener -> listener.invoke(event));

    if (listeners.containsKey(EventPrio.HIGHEST))
        listeners.get(EventPrio.HIGHEST).forEach(listener -> listener.invoke(event));
}
 
開發者ID:Zortax,項目名稱:PraFramework,代碼行數:23,代碼來源:EventManager.java

示例3: isTargetRegistered

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * Is target registered.
 *
 * @param targetObject    the target object.
 * @param targetChannelId the target channel id.
 * @return is target registered.
 */
private boolean isTargetRegistered(Object targetObject, List<String> targetChannelId) {
    Set<String> currentlyRegisteredChannelId = new HashSet<>();
    for (Map.Entry<Class<?>, ConcurrentHashMap<Object, ConcurrentHashMap<String,
            SubscriberHolder>>> mEventsToTargetsMapEntry : mEventsToTargetsMap.entrySet()) {
        ConcurrentHashMap<Object, ConcurrentHashMap<String, SubscriberHolder>> mTargetMap =
                mEventsToTargetsMapEntry.getValue();
        if (mTargetMap.containsKey(targetObject)) {
            ConcurrentHashMap<String, SubscriberHolder> subscribeMethods = mTargetMap.get
                    (targetObject);
            for (Map.Entry<String, SubscriberHolder> subscribeMethodEntry : subscribeMethods.entrySet()) {
                for (String methodChannelID : subscribeMethodEntry.getValue().subscribedChannelID) {
                    currentlyRegisteredChannelId.add(methodChannelID);

                }
            }
        }
    }
    return currentlyRegisteredChannelId.size() > 0 && currentlyRegisteredChannelId.containsAll(targetChannelId);
}
 
開發者ID:MindorksOpenSource,項目名稱:NYBus,代碼行數:27,代碼來源:NYBusDriver.java

示例4: putMessageQueue

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
private void putMessageQueue(String topic, Integer queueId, MessageQueueValue value) {
    if (!mqMap.containsKey(topic)) {
        mqMap.put(topic, new ConcurrentHashMap<>());
    }
    ConcurrentHashMap<Integer, MessageQueueValue> queueMap = mqMap.get(topic);
    if (!queueMap.containsKey(queueId)) {
        queueMap.put(queueId, value);
    }
}
 
開發者ID:taobaorun,項目名稱:LiQ,代碼行數:10,代碼來源:MessageQueueHolder.java

示例5: inspectRegion

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
@Override
public void inspectRegion(Region region) {
    count++;

    ConcurrentHashMap<Long, Region> clientFileRegions = clientFile.getRegions();
    if(clientFileRegions.containsKey(region.getOffset())){
       receivedCount++;
    }
}
 
開發者ID:gaganis,項目名稱:odoxSync,代碼行數:10,代碼來源:ClientMetadataReceivedInspector.java

示例6: queryTopicConsumeByWho

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
public HashSet<String> queryTopicConsumeByWho(final String topic) {
    HashSet<String> groups = new HashSet<String>();
    Iterator<Entry<String, ConsumerGroupInfo>> it = this.consumerTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, ConsumerGroupInfo> entry = it.next();
        ConcurrentHashMap<String, SubscriptionData> subscriptionTable =
                entry.getValue().getSubscriptionTable();
        if (subscriptionTable.containsKey(topic)) {
            groups.add(entry.getKey());
        }
    }

    return groups;
}
 
開發者ID:y123456yz,項目名稱:reading-and-annotate-rocketmq-3.4.6,代碼行數:15,代碼來源:ConsumerManager.java

示例7: testContainsKey_NullPointerException

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * containsKey(null) throws NPE
 */
public void testContainsKey_NullPointerException() {
    ConcurrentHashMap c = new ConcurrentHashMap(5);
    try {
        c.containsKey(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ConcurrentHashMapTest.java

示例8: updateReplicaReassignmentTimestamp

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
public static void updateReplicaReassignmentTimestamp(String brokerZkUrl,
                                                       ReplicaStat replicaStat) {
  if (!replicaReassignmentTimestamps.containsKey(brokerZkUrl)) {
    replicaReassignmentTimestamps.put(brokerZkUrl, new ConcurrentHashMap<>());
  }
  ConcurrentHashMap<TopicPartition, Long> replicaTimestamps =
      replicaReassignmentTimestamps.get(brokerZkUrl);
  TopicPartition topicPartition = new TopicPartition(
      replicaStat.getTopic(), replicaStat.getPartition());

  if (!replicaTimestamps.containsKey(topicPartition) ||
      replicaTimestamps.get(topicPartition) < replicaStat.getTimestamp()) {
    replicaTimestamps.put(topicPartition, replicaStat.getTimestamp());
  }
}
 
開發者ID:pinterest,項目名稱:doctorkafka,代碼行數:16,代碼來源:ReplicaStatsManager.java

示例9: getLastReplicaReassignmentTimestamp

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
private static long getLastReplicaReassignmentTimestamp(String brokerZkUrl,
                                                        TopicPartition topicPartition) {
  long result = 0;
  if (replicaReassignmentTimestamps.containsKey(brokerZkUrl)) {
    ConcurrentHashMap<TopicPartition, Long> replicaTimestamps =
        replicaReassignmentTimestamps.get(brokerZkUrl);
    if (replicaTimestamps.containsKey(topicPartition)) {
      result = replicaTimestamps.get(topicPartition);
    }
  }
  return result;
}
 
開發者ID:pinterest,項目名稱:doctorkafka,代碼行數:13,代碼來源:ReplicaStatsManager.java

示例10: queryTopicConsumeByWho

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
public HashSet<String> queryTopicConsumeByWho(final String topic) {
    HashSet<String> groups = new HashSet<>();
    Iterator<Entry<String, ConsumerGroupInfo>> it = this.consumerTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, ConsumerGroupInfo> entry = it.next();
        ConcurrentHashMap<String, SubscriptionData> subscriptionTable =
            entry.getValue().getSubscriptionTable();
        if (subscriptionTable.containsKey(topic)) {
            groups.add(entry.getKey());
        }
    }
    return groups;
}
 
開發者ID:lyy4j,項目名稱:rmq4note,代碼行數:14,代碼來源:ConsumerManager.java

示例11: addOrUpdateMethodsInTargetMap

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * Add methods in target map.
 *
 * @param targetObject          the target object.
 * @param subscribeMethodHolder the subscribeMethodHolder.
 */
private void addOrUpdateMethodsInTargetMap(Object targetObject,
                                           SubscriberHolder subscribeMethodHolder) {
    ConcurrentHashMap<Object, ConcurrentHashMap<String, SubscriberHolder>> mTargetMap =
            mEventsToTargetsMap.get(subscribeMethodHolder.subscribedMethod.
                    getParameterTypes()[0]);
    if (mTargetMap != null) {
        if (mTargetMap.containsKey(targetObject)) {
            updateMethodInSet(targetObject, subscribeMethodHolder, mTargetMap);
        } else {
            addEntryInTargetMap(targetObject, subscribeMethodHolder, mTargetMap);
        }
    }
}
 
開發者ID:MindorksOpenSource,項目名稱:NYBus,代碼行數:20,代碼來源:NYBusDriver.java

示例12: loadScriptsByJar

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
private AbstractScriptLoader<KEY> loadScriptsByJar(String jarName)
		throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException, ScriptException,
		NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
	File file = new File(jarName);
	if (!file.exists()) {
		throw new IOException("file not exist:" + jarName);
	}
	// 這裏要用係統自帶的loader,不然會造成代碼權限和作用域的問題
	URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
	Method add = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class });
	add.setAccessible(true);
	add.invoke(classLoader, new Object[] { file.toURI().toURL() });
	ConcurrentHashMap<KEY, IScript<KEY>> scriptMap_new = new ConcurrentHashMap<KEY, IScript<KEY>>();
	try (JarFile jarFile = new JarFile(file)) {
		Enumeration<JarEntry> entrys = jarFile.entries();
		while (entrys.hasMoreElements()) {
			JarEntry jarEntry = entrys.nextElement();
			String entryName = jarEntry.getName();
			if (entryName.endsWith(".class")) {
				String className = entryName.replace("/", ".").substring(0, entryName.indexOf(".class"));
				Class<?> clazz = classLoader.loadClass(className);
				log.info("load class:" + className);
				if (clazz == null) {
					throw new ScriptException("class not found:" + className);
				}
				if (className.contains("$")) {
					continue;
				}
				Object newInstance = clazz.newInstance();
				if (newInstance instanceof IScript) {
					if (newInstance instanceof IDynamicCode) {
						continue;
					}
					@SuppressWarnings("unchecked")
					IScript<KEY> script = (IScript<KEY>) newInstance;
					KEY scriptId = script.getScriptId();
					if (scriptMap_new.containsKey(scriptId)) {
						log.error("script id duplicated,source:" + scriptPath.get(scriptId).getName() + ",yours:"
								+ clazz.getName());
					} else {
						scriptMap_new.put(scriptId, script);
						log.info("compile script success:" + clazz.getName());
					}
				} else {
					throw new ScriptException("script file must implement IScript:" + clazz.getName());
				}
			}
		}
		this.scriptMap = scriptMap_new;
	}
	return this;
}
 
開發者ID:HankXV,項目名稱:Limitart,代碼行數:53,代碼來源:JarScriptLoader.java

示例13: loadScriptsBySourceDir

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * 加載一個目錄下對應的全部腳本(不會加載IDynamicCode相關)
 * 
 * @param dir
 * @param scriptTypes
 * @return
 * @throws IOException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws ScriptException
 */
public AbstractScriptLoader<KEY> loadScriptsBySourceDir(String dir, ScriptFileType... scriptTypes)
		throws IOException, InstantiationException, IllegalAccessException, ScriptException {
	ConcurrentHashMap<KEY, IScript<KEY>> scriptMap_new = new ConcurrentHashMap<>();
	ConcurrentHashMap<KEY, File> scriptPath_new = new ConcurrentHashMap<>();
	try (GroovyClassLoader loader = new GroovyClassLoader(ClassLoader.getSystemClassLoader());) {
		File dir_root = new File(dir);
		if (!dir_root.exists()) {
			throw new IOException("scripts root dir does not exist:" + dir);
		}
		if (!dir_root.isDirectory()) {
			throw new IOException("file is not dir:" + dir);
		}
		String[] types = null;
		if (scriptTypes != null && scriptTypes.length > 0) {
			types = new String[scriptTypes.length];
			for (int i = 0; i < scriptTypes.length; ++i) {
				types[i] = scriptTypes[i].getValue();
			}
		}
		List<File> result = FileUtil.getFiles(dir_root, types);
		for (File file : result) {
			Class<?> parseClass = loader.parseClass(file);
			Object newInstance = parseClass.newInstance();
			if (newInstance instanceof IScript) {
				if (newInstance instanceof IDynamicCode) {
					continue;
				}
				@SuppressWarnings("unchecked")
				IScript<KEY> script = (IScript<KEY>) newInstance;
				KEY scriptId = script.getScriptId();
				if (scriptMap_new.containsKey(scriptId)) {
					log.error("script id duplicated,source:" + scriptPath.get(scriptId).getName() + ",yours:"
							+ file.getName());
				} else {
					scriptMap_new.put(scriptId, script);
					scriptPath_new.put(scriptId, file);
					log.info("compile script success:" + file.getName());
				}
			} else {
				throw new ScriptException("script file must implement IScript:" + file.getName());
			}
		}
		this.scriptMap = scriptMap_new;
		this.scriptPath = scriptPath_new;
	}
	return this;
}
 
開發者ID:HankXV,項目名稱:Limitart,代碼行數:59,代碼來源:FileScriptLoader.java

示例14: loadAllClass

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
	public final void loadAllClass(){
		if(isLoading)
		{
			return;
		}
		isLoading=true;
		classLoader = new ScriptClassLoader();
		final ConcurrentHashMap<Integer, Class<? extends T>> codeMap=new ConcurrentHashMap<Integer, Class<? extends T>>();
		for (Entry<String,ClassFile> entry : scriptFilePaths.entrySet()) 
		{
			ClassFile classFile = entry.getValue();
			try {
				Class<T> scriptClass=null;
				Class<?> clazz=loadClass(classLoader, classFile);
				if(clazz!=null)
				{//類型轉換
					scriptClass=(Class<T>)clazz;
				}
				if(scriptClass!=null)
				{
					boolean isAbstract=Modifier.isAbstract(scriptClass.getModifiers());//是否是抽象類
					if(isAbstract)
					{//抽象類
//						_log.info("loaded abstractScript:" + classFile.getFilePath());
					}else
					{
						T script=scriptClass.newInstance();
						int code=script.getMessageCode();
						if(codeMap.containsKey(code))
						{//如果已經存在相同code的腳步則不加載
							_log.error("find Repeat code script,addingScript:"+script.getClass()+",existScript:"+codeMap.get(code));
						}else
						{
							_log.info("**********LoadRegistClass<" + classFile.getClassName()+">**********");
							codeMap.put(code,scriptClass);
							_log.info("loaded codeScript,code="+code+"(0x"+Integer.toHexString(code)+"),path=" + classFile.getFilePath());
						}
					}
					//如果相同腳步的類文件發生改變後可能code會不一致,所以即使有相同code的腳步依然要記錄時間
					classFile.setLastModifyTime(new File(classFile.getFilePath()).lastModified());//更新時間
				}
			} catch (Exception e) {
				_log.error(e.getMessage(),e);
			}
		}
		this.codeMap.putAll(codeMap);
		isLoading=false;
	}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:50,代碼來源:AbstractScriptFactory.java

示例15: add

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
public void add(Hit h, SparseString gi, int frame) {

		if (!hitMap.containsKey(gi))
			hitMap.put(gi, new ConcurrentHashMap<Integer, Vector<Hit>>());
		ConcurrentHashMap<Integer, Vector<Hit>> frameMap = hitMap.get(gi);

		if (!frameMap.containsKey(frame))
			frameMap.put(frame, new Vector<Hit>());
		Vector<Hit> hits = frameMap.get(frame);

		hits.add(h);

	}
 
開發者ID:BenjaminAlbrecht84,項目名稱:DAA_Converter,代碼行數:14,代碼來源:ReadHits.java


注:本文中的java.util.concurrent.ConcurrentHashMap.containsKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。