本文整理汇总了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;
}
}
示例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));
}
示例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);
}
示例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);
}
}
示例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++;
}
}
示例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;
}
示例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) {}
}
示例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());
}
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}