本文整理汇总了Java中java.util.concurrent.ConcurrentHashMap.get方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentHashMap.get方法的具体用法?Java ConcurrentHashMap.get怎么用?Java ConcurrentHashMap.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ConcurrentHashMap
的用法示例。
在下文中一共展示了ConcurrentHashMap.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getQueryStats
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
protected QueryStats getQueryStats(String sql) {
if (sql==null) sql = "";
ConcurrentHashMap<String,QueryStats> queries = SlowQueryReport.this.queries;
if (queries==null) {
if (log.isWarnEnabled()) log.warn("Connection has already been closed or abandoned");
return null;
}
QueryStats qs = queries.get(sql);
if (qs == null) {
qs = new QueryStats(sql);
if (queries.putIfAbsent(sql,qs)!=null) {
qs = queries.get(sql);
} else {
//we added a new element, see if we need to remove the oldest
if (queries.size() > maxQueries) {
removeOldest(queries);
}
}
}
return qs;
}
示例2: FileTailer
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public FileTailer(IFileTailerListener listener, ConcurrentHashMap<String, String> prop) {
this.listener = listener;
this.prop = prop;
/**
* 对n个source实例,配置n个快照文件
*/
this.snapShotMarkDirPath = prop.get("backupFileDirPath");
this.snapShotMarkPath = prop.get("backupFileDirPath")+File.separator+"mark.txt";
this.backupDB = new MD5File(snapShotMarkDirPath);
this.clearTimeInterval = Long.parseLong(prop.get("clearTimeInterval"));
pattern = Pattern.compile(prop.get("regexFileName"));//必须能匹配上实时文件,也能匹配由实时文件产生的新文件
this.tailFile = new File(prop.get("fileRootDir")+File.separator+prop.get("filePrefix")+prop.get("fileSuffix"));
logger.info("开始执行:initMarkData()");
try {
this.initMarkData();
} catch (IOException e) {
logger.error("加载本地快照文件失败!",e);
}
logger.info("结束执行:initMarkData()");
}
示例3: isLocked
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
private boolean isLocked(final String group, final MessageQueue mq, final String clientId) {
ConcurrentHashMap<MessageQueue, LockEntry> groupValue = this.mqLockTable.get(group);
if (groupValue != null) {
LockEntry lockEntry = groupValue.get(mq);
if (lockEntry != null) {
boolean locked = lockEntry.isLocked(clientId);
if (locked) {
lockEntry.setLastUpdateTimestamp(System.currentTimeMillis());
}
return locked;
}
}
return false;
}
示例4: isLocked
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
* LockEntry 为consumer端 clientId 的实体,该方法用来判断group下的mq是否被
* 指定的clientId锁着,并且获取锁不过时
* @param group
* @param mq
* @param clientId
* @return
*/
private boolean isLocked(final String group, final MessageQueue mq, final String clientId) {
ConcurrentHashMap<MessageQueue, LockEntry> groupValue = this.mqLockTable.get(group);
if (groupValue != null) {
LockEntry lockEntry = groupValue.get(mq);
if (lockEntry != null) {
boolean locked = lockEntry.isLocked(clientId);
if (locked) {
lockEntry.setLastUpdateTimestamp(System.currentTimeMillis());
}
return locked;
}
}
return false;
}
示例5: registerCompositeFont
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
protected static void registerCompositeFont(String compositeName,
String[] componentFileNames,
String[] componentNames,
int numMetricsSlots,
int[] exclusionRanges,
int[] exclusionMaxIndex,
boolean defer,
ConcurrentHashMap<String, Font2D>
altNameCache) {
CompositeFont cf = new CompositeFont(compositeName,
componentFileNames,
componentNames,
numMetricsSlots,
exclusionRanges,
exclusionMaxIndex, defer,
SunFontManager.getInstance());
/* if the cache has an existing composite for this case, make
* its handle point to this new font.
* This ensures that when the altNameCache that is passed in
* is the global mapNameCache - ie we are running as an application -
* that any statically created java.awt.Font instances which already
* have a Font2D instance will have that re-directed to the new Font
* on subsequent uses. This is particularly important for "the"
* default font instance, or similar cases where a UI toolkit (eg
* Swing) has cached a java.awt.Font. Note that if Swing is using
* a custom composite APIs which update the standard composites have
* no effect - this is typically the case only when using the Windows
* L&F where these APIs would conflict with that L&F anyway.
*/
Font2D oldFont =altNameCache.get(compositeName.toLowerCase(Locale.ENGLISH));
if (oldFont instanceof CompositeFont) {
oldFont.handle.font2D = cf;
}
altNameCache.put(compositeName.toLowerCase(Locale.ENGLISH), cf);
}
示例6: getNeighborChildrenCount
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
* we do it in a hack way.
* travel the dom tree, to get how many children does this slider-neighbor have.
*
* @return
*/
private int getNeighborChildrenCount() {
try {
WXDomManager domManager = WXSDKManager.getInstance().getWXDomManager();
Field domRegistriesField = domManager.getClass().getDeclaredField("mDomRegistries");
domRegistriesField.setAccessible(true);
ConcurrentHashMap<String, Object> domRegistriesMap = (ConcurrentHashMap<String, Object>) domRegistriesField.get(domManager);
Object domStatement = domRegistriesMap.get(getInstanceId()); // WXDomStatement
Field mRegistryField = domStatement.getClass().getDeclaredField("mRegistry");
mRegistryField.setAccessible(true);
ConcurrentHashMap<String, WXDomObject> mRegistryMap = (ConcurrentHashMap<String, WXDomObject>) mRegistryField.get(domStatement);
for(WXDomObject domObject : mRegistryMap.values()) {
if(domObject.getType().equalsIgnoreCase(WXBasicComponentType.SLIDER_NEIGHBOR)) {
int sum = 0;
for (int i = 0,count = domObject.getChildCount(); i < count; i++) {
if(domObject.getChild(i) instanceof WXIndicator.IndicatorDomNode) {
continue;
}
sum++;
}
return sum;
}
}
} catch (Exception e) {
// ignore
}
return -1;
}
示例7: updateMethodInSet
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
* Update methods in set.
*
* @param targetObject the target object.
* @param subscribeMethod the subscribe method.
* @param mTargetMap the target map.
*/
private void updateMethodInSet(Object targetObject,
SubscriberHolder subscribeMethod,
ConcurrentHashMap<Object, ConcurrentHashMap<String,
SubscriberHolder>> mTargetMap) {
ConcurrentHashMap<String, SubscriberHolder> methodSet = mTargetMap.get(targetObject);
methodSet.put(subscribeMethod.getKeyForSubscribeHolderMap(), subscribeMethod);
}
示例8: registerCompositeFont
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
protected static void registerCompositeFont(String compositeName,
String[] componentFileNames,
String[] componentNames,
int numMetricsSlots,
int[] exclusionRanges,
int[] exclusionMaxIndex,
boolean defer,
ConcurrentHashMap<String, Font2D>
altNameCache) {
CompositeFont cf = new CompositeFont(compositeName,
componentFileNames,
componentNames,
numMetricsSlots,
exclusionRanges,
exclusionMaxIndex, defer,
SunFontManager.getInstance());
/* if the cache has an existing composite for this case, make
* its handle point to this new font.
* This ensures that when the altNameCache that is passed in
* is the global mapNameCache - ie we are running as an application -
* that any statically created java.awt.Font instances which already
* have a Font2D instance will have that re-directed to the new Font
* on subsequent uses. This is particularly important for "the"
* default font instance, or similar cases where a UI toolkit (eg
* Swing) has cached a java.awt.Font. Note that if Swing is using
* a custom composite APIs which update the standard composites have
* no effect - this is typically the case only when using the Windows
* L&F where these APIs would conflict with that L&F anyway.
*/
Font2D oldFont = (Font2D)
altNameCache.get(compositeName.toLowerCase(Locale.ENGLISH));
if (oldFont instanceof CompositeFont) {
oldFont.handle.font2D = cf;
}
altNameCache.put(compositeName.toLowerCase(Locale.ENGLISH), cf);
}
示例9: queryOffset
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public long queryOffset(final String group, final String topic, final int queueId) {
// [email protected]
String key = topic + TOPIC_GROUP_SEPARATOR + group;
ConcurrentHashMap<Integer, Long> map = this.offsetTable.get(key);
if (null != map) {
Long offset = map.get(queueId);
if (offset != null)
return offset;
}
return -1;
}
示例10: doSubscribe
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@Override
protected void doSubscribe(final URL url, final NotifyListener listener) {
try {
clientLock.lock();
ConcurrentHashMap<NotifyListener, IZkChildListener> childChangeListeners = serviceListeners.get(url);
if (childChangeListeners == null) {
serviceListeners.putIfAbsent(url, new ConcurrentHashMap<NotifyListener, IZkChildListener>());
childChangeListeners = serviceListeners.get(url);
}
IZkChildListener zkChildListener = childChangeListeners.get(listener);
if (zkChildListener == null) {
childChangeListeners.putIfAbsent(listener, new IZkChildListener() {
@Override
public void handleChildChange(String parentPath, List<String> currentChilds) {
listener.notify(getUrl(), childrenNodeToUrls(parentPath, currentChilds));
logger.info(String.format("[ZookeeperRegistry] service list change: path=%s, currentChilds=%s", parentPath, currentChilds.toString()));
}
});
zkChildListener = childChangeListeners.get(listener);
}
// 防止旧节点未正常注销
removeNode(url, ZkNodeType.CLIENT);
createNode(url, ZkNodeType.CLIENT);
String serverTypePath = ZkUtils.toNodeTypePath(url, ZkNodeType.SERVER);
zkClient.subscribeChildChanges(serverTypePath, zkChildListener);
logger.info(String.format("[ZookeeperRegistry] subscribe service: path=%s, info=%s", ZkUtils.toNodePath(url, ZkNodeType.SERVER), url.toFullUri()));
} catch (Throwable e) {
throw new RpcFrameworkException(String.format("Failed to subscribe %s to zookeeper(%s), cause: %s", url, getUrl(), e.getMessage()), e);
} finally {
clientLock.unlock();
}
}
示例11: tryLock
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public boolean tryLock(final String group, final MessageQueue mq, final String clientId) {
if (!this.isLocked(group, mq, clientId)) {
try {
this.lock.lockInterruptibly();
try {
ConcurrentHashMap<MessageQueue, LockEntry> groupValue = this.mqLockTable.get(group);
if (null == groupValue) {
groupValue = new ConcurrentHashMap<>(32);
this.mqLockTable.put(group, groupValue);
}
LockEntry lockEntry = groupValue.get(mq);
if (null == lockEntry) {
lockEntry = new LockEntry();
lockEntry.setClientId(clientId);
groupValue.put(mq, lockEntry);
log.info("tryLock, message queue not locked, I got it. Group: {} NewClientId: {} {}", //
group, //
clientId, //
mq);
}
if (lockEntry.isLocked(clientId)) {
lockEntry.setLastUpdateTimestamp(System.currentTimeMillis());
return true;
}
String oldClientId = lockEntry.getClientId();
if (lockEntry.isExpired()) {
lockEntry.setClientId(clientId);
lockEntry.setLastUpdateTimestamp(System.currentTimeMillis());
log.warn(
"tryLock, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", //
group, //
oldClientId, //
clientId, //
mq);
return true;
}
log.warn(
"tryLock, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", //
group, //
oldClientId, //
clientId, //
mq);
return false;
} finally {
this.lock.unlock();
}
} catch (InterruptedException e) {
log.error("putMessage exception", e);
}
} else {
}
return true;
}
示例12: get
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public V get(K1 key1, K2 key2) {
ConcurrentHashMap<K2, V> k2_v = k1_k2V_map.get(key1);
return k2_v == null ? null : k2_v.get(key2);
}
示例13: updateTmpFm
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
* Update the tmp Fm by using the keyword
* @param keyword
*/
private void updateTmpFm(String keyword) {
tmpFm.emptyAll();
ConcurrentHashMap<String, ConcurrentSkipListSet<Market>> data = fm.getFinancialMarketData();
String marketCode = selectedMarketProperty.getValue().toUpperCase();
String marketType = selectedMarketTypeProperty.getValue();
if (marketCode == null || marketCode.isEmpty()) {
//do nothing
return;
}
else {
if (data.get(marketType) != null) {
Market market = fm.getMarket(selectedMarketTypeProperty.getValue(), marketCode);
if (market == null) {
//do nothing
return;
} else {
Iterator<String> iterator = market.getData().keySet().iterator();
while (iterator.hasNext()) {
String OHLCCode = iterator.next();
if (OHLCCode.startsWith(keyword)){
if (tmpFm.getMarket(selectedMarketTypeProperty.getValue(), marketCode) == null){
Market tmpMarket = new Market(marketCode, market.getChartType(), market.getCountryName());
tmpFm.addMarket(selectedMarketTypeProperty.getValue(), tmpMarket);
}
Iterator<OHLC> ohlcIterator = market.getOHLC(OHLCCode).iterator();
while(ohlcIterator.hasNext()) {
if (tmpFm.getMarket(marketType, marketCode) != null) {
tmpFm.getMarket(marketType, marketCode).addOHLC(OHLCCode, ohlcIterator.next());
}else {
tmpFm.initMarket(marketType, marketCode, market.getCountryName(), market.getChartType());
tmpFm.getMarket(marketType, marketCode).addOHLC(OHLCCode, ohlcIterator.next());
}
}
}
}
}
}
else {
//do nothing
return;
}
}
}
示例14: processUpdateEncryption
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
protected void processUpdateEncryption(TLRPC.TL_updateEncryption update, ConcurrentHashMap<Integer, TLRPC.User> usersDict) {
final TLRPC.EncryptedChat newChat = update.chat;
long dialog_id = ((long) newChat.id) << 32;
TLRPC.EncryptedChat existingChat = MessagesController.getInstance().getEncryptedChatDB(newChat.id);
if (newChat instanceof TLRPC.TL_encryptedChatRequested && existingChat == null) {
int user_id = newChat.participant_id;
if (user_id == UserConfig.getClientUserId()) {
user_id = newChat.admin_id;
}
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null) {
user = usersDict.get(user_id);
}
newChat.user_id = user_id;
final TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
dialog.id = dialog_id;
dialog.unread_count = 0;
dialog.top_message = 0;
dialog.last_message_date = update.date;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().dialogs_dict.put(dialog.id, dialog);
MessagesController.getInstance().dialogs.add(dialog);
MessagesController.getInstance().putEncryptedChat(newChat, false);
MessagesController.getInstance().sortDialogs(null);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
}
});
MessagesStorage.getInstance().putEncryptedChat(newChat, user, dialog);
SecretChatHelper.getInstance().acceptSecretChat(newChat);
} else if (newChat instanceof TLRPC.TL_encryptedChat) {
if (existingChat != null && existingChat instanceof TLRPC.TL_encryptedChatWaiting && (existingChat.auth_key == null || existingChat.auth_key.length == 1)) {
newChat.a_or_b = existingChat.a_or_b;
newChat.user_id = existingChat.user_id;
SecretChatHelper.getInstance().processAcceptedSecretChat(newChat);
} else if (existingChat == null && startingSecretChat) {
delayedEncryptedChatUpdates.add(update);
}
} else {
final TLRPC.EncryptedChat exist = existingChat;
if (exist != null) {
newChat.user_id = exist.user_id;
newChat.auth_key = exist.auth_key;
newChat.key_create_date = exist.key_create_date;
newChat.key_use_count_in = exist.key_use_count_in;
newChat.key_use_count_out = exist.key_use_count_out;
newChat.ttl = exist.ttl;
newChat.seq_in = exist.seq_in;
newChat.seq_out = exist.seq_out;
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (exist != null) {
MessagesController.getInstance().putEncryptedChat(newChat, false);
}
MessagesStorage.getInstance().updateEncryptedChat(newChat);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.encryptedChatUpdated, newChat);
}
});
}
}
示例15: manageCache
import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
private <T> T manageCache(ConcurrentHashMap<Integer, WithUseCount<T>> cache, Accessor<T> accessor, int n, FieldSelector fieldSelector, int limit) throws IOException
{
Integer key = Integer.valueOf(n);
WithUseCount<T> value = cache.get(key);
if (value == null)
{
T made = accessor.get(n, fieldSelector);
value = new WithUseCount<T>(made, n);
cache.put(key, value);
// resize
if (limit >= 0)
{
if (cache.size() >= limit)
{
HashMap<Integer, WithUseCount<T>> keep = new HashMap<Integer, WithUseCount<T>>();
WithUseCount<T>[] existing = new WithUseCount[0];
synchronized (cache)
{
existing = cache.values().toArray(existing);
cache.clear();
}
Arrays.sort(existing);
for (WithUseCount<T> current : existing)
{
keep.put(Integer.valueOf(current.doc), current);
if ((current.count.get() == 0) || (keep.size() > (limit / 4)))
{
break;
}
}
keep.put(key, value);
cache.putAll(keep);
}
}
}
else
{
value.count.getAndIncrement();
}
return value.object;
}
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:45,代码来源:ReferenceCountingReadOnlyIndexReaderFactory.java