List of usage examples for java.util.concurrent ConcurrentHashMap get
public V get(Object key)
From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java
public Long getSumForRowColumnKey(final String rowKey, final String columnKey) { if (StringUtils.isBlank(rowKey) || StringUtils.isBlank(columnKey)) { return Long.valueOf(0L); }/* w w w . jav a 2 s . com*/ ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>> row = table.get(rowKey); if (row == null) { return Long.valueOf(0L); } ConcurrentSkipListMap<String, ConcurrentSet<T>> column = row.get(columnKey); if (column == null) { return Long.valueOf(0L); } return column.values().parallelStream().mapToLong(k -> k.size()).sum(); }
From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java
private void pruneCache() { String expireTime = LocalDateTime.now().minusHours(ttl).format(Util.timeFormatter); log.info("{expireTime:{}}", expireTime); for (String rowKey : table.keySet()) { ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>> rowMap = table.get(rowKey); for (String columnKey : rowMap.keySet()) { ConcurrentSkipListMap<String, ConcurrentSet<T>> columnMap = rowMap.get(columnKey); Iterator<String> iterator = columnMap.keySet().iterator(); while (iterator.hasNext()) { String timesplices = iterator.next(); if (timesplices.compareTo(expireTime) < 0) { columnMap.get(timesplices).clear(); iterator.remove();//w ww. j a v a 2 s . c o m } else { break; } } } } }
From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java
public List<T> get(final String rowKey, final String columnKey, final String timesplice) { Preconditions.checkState(StringUtils.isNotBlank(rowKey), "rowKey is blank"); Preconditions.checkState(StringUtils.isNotBlank(columnKey), "columnKey is blank"); Preconditions.checkState(StringUtils.isNotBlank(timesplice), "timesplice is blank"); ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>> row = table.get(rowKey); if (row == null) { return Arrays.asList(); }/* www . j a va2 s .com*/ ConcurrentSkipListMap<String, ConcurrentSet<T>> column = row.get(columnKey); if (column == null) { return Arrays.asList(); } ConcurrentSet<T> values = column.get(timesplice); if (values == null) { return Arrays.asList(); } return values.stream().collect(Collectors.toList()); }
From source file:com.taobao.diamond.server.service.GroupService.java
/** * ip/*from w ww.j a va2 s. com*/ * * @param address * @param dataId * @param clientGroup * * @return */ public String getGroupByAddress(String address, String dataId, String clientGroup) { ConcurrentHashMap<String, GroupInfo> dataIdGroupMap = addressGroupCache.get(address); if (dataIdGroupMap != null) { GroupInfo groupInfo = dataIdGroupMap.get(dataId); if (groupInfo != null) { return groupInfo.getGroup(); } else { return defaultGroupOrClientGroup(clientGroup); } } else { return defaultGroupOrClientGroup(clientGroup); } // /* * ConcurrentHashMap<String, GroupInfo> dataIdGroupMap = * addressGroupCache.get(address); if (dataIdGroupMap != null) { * GroupInfo groupInfo = dataIdGroupMap.get(dataId); if (groupInfo != * null) { return groupInfo.getGroup(); } else { return * wildCardGroup(address, dataId, clientGroup); } } else { // , * return wildCardGroup(address, dataId, clientGroup); } */ }
From source file:com.taobao.diamond.server.service.GroupService.java
@SuppressWarnings("unused") private String wildCardGroup(String address, String dataId, String clientGroup) { for (String key : addressGroupCache.keySet()) { if (key.endsWith(WILDCARD_CHAR)) { String keyPrefix = key.substring(0, key.indexOf(WILDCARD_CHAR)); if (address.startsWith(keyPrefix)) { ConcurrentHashMap<String, GroupInfo> dataIdGroupMap = addressGroupCache.get(key); if (dataIdGroupMap != null) { GroupInfo groupInfo = dataIdGroupMap.get(dataId); if (groupInfo != null) { return groupInfo.getGroup(); }/*from ww w . ja va 2 s. co m*/ } } } } return defaultGroupOrClientGroup(clientGroup); }
From source file:org.wso2.carbon.event.input.adaptor.file.FileEventAdaptorType.java
@Override public void unsubscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration, InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration, String subscriptionId) {//from w w w. jav a 2 s . c o m ConcurrentHashMap<String, FileTailerManager> tailerManagerConcurrentHashMap = tailerMap .get(inputEventAdaptorConfiguration.getName()); FileTailerManager fileTailerManager = null; if (tailerManagerConcurrentHashMap != null) { fileTailerManager = tailerManagerConcurrentHashMap.get(inputEventAdaptorMessageConfiguration .getInputMessageProperties().get(FileEventAdaptorConstants.EVENT_ADAPTOR_CONF_FILEPATH)); } if (fileTailerManager != null) { fileTailerManager.getListener().removeListener(subscriptionId); if (fileTailerManager.getListener().hasNoSubscriber()) { fileTailerManager.getTailer().stop(); tailerMap.remove(inputEventAdaptorConfiguration.getName()); } } }
From source file:org.apache.falcon.entity.store.ConfigurationStore.java
private synchronized void updateInternal(EntityType type, Entity entity) throws FalconException { try {//from w w w .j ava 2 s . co m if (get(type, entity.getName()) != null) { persist(type, entity); ConcurrentHashMap<String, Entity> entityMap = dictionary.get(type); Entity oldEntity = entityMap.get(entity.getName()); onChange(oldEntity, entity); entityMap.put(entity.getName(), entity); } else { throw new FalconException(entity.toShortString() + " doesn't exist"); } } catch (IOException e) { throw new StoreAccessException(e); } AUDIT.info(type + "/" + entity.getName() + " is replaced into config store"); }
From source file:org.wso2.carbon.event.input.adaptor.kafka.KafkaEventAdaptorType.java
@Override public void unsubscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration, InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration, String subscriptionId) {// www .j a v a2 s . c om if (consumerAdaptorMap != null) { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); ConcurrentHashMap<String, ConsumerKafkaAdaptor> tenantSpecificAdaptorMap = consumerAdaptorMap .get(tenantId); if (tenantSpecificAdaptorMap != null) { ConsumerKafkaAdaptor consumerKafkaAdaptor = tenantSpecificAdaptorMap.get(subscriptionId); if (consumerKafkaAdaptor != null) { consumerKafkaAdaptor.shutdown(); tenantSpecificAdaptorMap.remove(subscriptionId); } } } }
From source file:com.taobao.diamond.server.service.GroupService.java
@Deprecated public boolean updateAddress2GroupMapping(long id, String newGroup) { synchronized (this) { GroupInfo groupInfo = this.persistService.findGroupInfoByID(id); if (groupInfo == null) return false; ConcurrentHashMap<String, GroupInfo> dataIdGroupMap = this.addressGroupCache .get(groupInfo.getAddress()); if (dataIdGroupMap == null) return false; if (dataIdGroupMap.get(groupInfo.getDataId()) == null) return false; this.persistService.updateGroup(id, newGroup); dataIdGroupMap.get(groupInfo.getDataId()).setGroup(newGroup); }//from w ww . j a v a 2s .c o m this.notifyService.notifyGroupChanged(); return true; }
From source file:com.taobao.diamond.server.service.GroupService.java
/** * , IP/*from w w w .j a va 2 s . c o m*/ * * @param id * @param newGroup * @param srcIp * @param srcUser * @return */ public boolean updateAddress2GroupMapping(long id, String newGroup, String srcIp, String srcUser) { synchronized (this) { GroupInfo groupInfo = this.persistService.findGroupInfoByID(id); if (groupInfo == null) return false; ConcurrentHashMap<String, GroupInfo> dataIdGroupMap = this.addressGroupCache .get(groupInfo.getAddress()); if (dataIdGroupMap == null) return false; if (dataIdGroupMap.get(groupInfo.getDataId()) == null) return false; Timestamp currentTime = DiamondUtils.getCurrentTime(); this.persistService.updateGroup(id, srcIp, srcUser, currentTime, newGroup); dataIdGroupMap.get(groupInfo.getDataId()).setGroup(newGroup); } this.notifyService.notifyGroupChanged(); return true; }