List of usage examples for java.util.concurrent ConcurrentHashMap containsKey
public boolean containsKey(Object key)
From source file:com.newlandframework.avatarmq.consumer.ConsumerContext.java
public static List<ConsumerClusters> selectByTopic(String topic) { List<ConsumerClusters> clusters = new ArrayList<ConsumerClusters>(); for (int i = 0; i < relationArray.size(); i++) { ConcurrentHashMap<String, SubscriptionData> subscriptionTable = relationArray.get(i).getClusters() .getSubMap();//from w ww . j a va 2s . co m if (subscriptionTable.containsKey(topic)) { clusters.add(relationArray.get(i).getClusters()); } } return clusters; }
From source file:org.exoplatform.addons.lecko.social.rest.api.EntityBuilder.java
private static void updateCachedEtagValue(int etagValue) { ApplicationContext ac = ApplicationContextImpl.getCurrent(); Map<String, String> properties = ac.getProperties(); ConcurrentHashMap<String, String> props = new ConcurrentHashMap<String, String>(properties); if (props.containsKey(RestProperties.ETAG)) { props.remove(RestProperties.ETAG); }/*from w ww . j a va 2 s. c o m*/ if (props.containsKey(RestProperties.UPDATE_DATE)) { props.remove(RestProperties.UPDATE_DATE); } ac.setProperty(RestProperties.ETAG, String.valueOf(etagValue)); ApplicationContextImpl.setCurrent(ac); }
From source file:org.exoplatform.addons.lecko.social.rest.api.EntityBuilder.java
private static void updateCachedLastModifiedValue(Date lastModifiedDate) { ApplicationContext ac = ApplicationContextImpl.getCurrent(); Map<String, String> properties = ac.getProperties(); ConcurrentHashMap<String, String> props = new ConcurrentHashMap<String, String>(properties); if (props.containsKey(RestProperties.UPDATE_DATE)) { props.remove(RestProperties.UPDATE_DATE); }//from w ww. j a va 2 s .c om if (props.containsKey(RestProperties.ETAG)) { props.remove(RestProperties.ETAG); } ac.setProperty(RestProperties.UPDATE_DATE, String.valueOf(lastModifiedDate.getTime())); ApplicationContextImpl.setCurrent(ac); }
From source file:org.objectweb.proactive.core.remoteobject.RemoteObjectSet.java
/** * Helper method used to sort the list of protocols * @param input//from w w w. j ava 2 s.c o m * @param defOrder * @param benchmarkRes * @param defUri * @return */ public static ArrayList<URI> sortProtocols(Collection<URI> input, final List<String> defOrder, final ConcurrentHashMap<URI, Integer> benchmarkRes, final URI defUri) { ArrayList<URI> output = new ArrayList<URI>(); output.addAll(input); Collections.sort(output, new Comparator<URI>() { @Override public int compare(URI o1, URI o2) { // unreachable uri, they are put at the end of the list if (benchmarkRes.containsKey(o1) && benchmarkRes.get(o1) == UNREACHABLE_VALUE) { return 1; } if (benchmarkRes.containsKey(o2) && benchmarkRes.get(o2) == UNREACHABLE_VALUE) { return -1; } // sort accordingly to fixed order if (defOrder.contains(o1.getScheme()) && defOrder.contains(o2.getScheme())) { return defOrder.indexOf(o1.getScheme()) - defOrder.indexOf(o2.getScheme()); } // the following code means that any protocol present in the default order // is preferred to any other protocol, currently this behavior is deactivated if (defOrder.contains(o1.getScheme())) { return -1; } if (defOrder.contains(o2.getScheme())) { return 1; } if (benchmarkRes.containsKey(o1) && benchmarkRes.containsKey(o2)) { // sort accordingly to benchmark results if (benchmarkRes.get(o1) > benchmarkRes.get(o2)) { return -1; } else if (benchmarkRes.get(o2) > benchmarkRes.get(o1)) { return 1; } return 0; } // undetermined, we have no info return 0; } }); // finally remove unreachable protocols for (ListIterator<URI> it = output.listIterator(output.size()); it.hasPrevious();) { URI reachableOrNot = it.previous(); if (benchmarkRes.containsKey(reachableOrNot) && benchmarkRes.get(reachableOrNot) == UNREACHABLE_VALUE) { if (!reachableOrNot.equals(defUri)) { it.remove(); } } else { // we exit the loop at the first reachable protocol break; } } return output; }
From source file:ca.uhn.fhir.jaxrs.server.util.JaxRsMethodBindings.java
/** * Get the binding // w ww . j av a2 s.com * * @param operationType the type of operation * @param theBindingKey the binding key * @return the binding defined * @throws NotImplementedOperationException cannot be found */ public BaseMethodBinding<?> getBinding(RestOperationTypeEnum operationType, String theBindingKey) { String bindingKey = StringUtils.defaultIfBlank(theBindingKey, DEFAULT_METHOD_KEY); ConcurrentHashMap<String, BaseMethodBinding<?>> map = operationBindings.get(operationType); if (map == null || !map.containsKey(bindingKey)) { throw new NotImplementedOperationException("Operation not implemented"); } else { return map.get(bindingKey); } }
From source file:ca.uhn.fhir.jaxrs.server.util.JaxRsMethodBindings.java
private void addMethodBinding(String key, BaseMethodBinding<?> binding) { ConcurrentHashMap<String, BaseMethodBinding<?>> mapByOperation = getMapForOperation( binding.getRestOperationType()); if (mapByOperation.containsKey(key)) { throw new IllegalArgumentException("Multiple Search Method Bindings Found : " + mapByOperation.get(key) + " -- " + binding.getMethod()); }//from ww w . j a v a 2 s . c o m mapByOperation.put(key, binding); }
From source file:org.wso2.carbon.governance.metadata.Util.java
private static Map<String, VersionBaseProvider> getVersionBaseProviderMap() throws MetadataException { if (versionBaseProviderMap != null) { return versionBaseProviderMap; }//from w ww . ja va 2s . com ConcurrentHashMap<String, VersionBaseProvider> providerMap = new ConcurrentHashMap<String, VersionBaseProvider>(); try { FileInputStream fileInputStream = new FileInputStream(getConfigFile()); StAXOMBuilder builder = new StAXOMBuilder(fileInputStream); OMElement configElement = builder.getDocumentElement(); OMElement metadataProviders = configElement.getFirstChildWithName(new QName("metadataProviders")) .getFirstChildWithName(new QName("versionBaseProviders")); Iterator<OMElement> itr = metadataProviders.getChildrenWithLocalName("provider"); while (itr.hasNext()) { OMElement metadataProvider = itr.next(); String providerClass = metadataProvider.getAttributeValue(new QName("class")).trim(); String mediaType = metadataProvider.getAttributeValue(new QName(Constants.ATTRIBUTE_MEDIA_TYPE)); ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class<VersionBaseProvider> classObj = (Class<VersionBaseProvider>) Class.forName(providerClass, true, loader); if (!providerMap.containsKey(mediaType)) { providerMap.put(mediaType, (VersionBaseProvider) classObj.getConstructors()[0].newInstance(mediaType)); } else { // log.error("Classification URI already exists") } } } catch (Exception e) { throw new MetadataException(e.getMessage(), e); } return Util.versionBaseProviderMap = providerMap; }
From source file:com.taobao.diamond.server.service.GroupService.java
/** * ip/*from w w w.j a v a 2 s. co m*/ * * @param address * @param dataId * @param group */ @Deprecated public boolean addAddress2GroupMapping(String address, String dataId, String group) { synchronized (this) { if (this.addressGroupCache.containsKey(address)) { ConcurrentHashMap<String, GroupInfo> subMap = this.addressGroupCache.get(address); if (subMap != null && subMap.containsKey(dataId)) return false; } ConcurrentHashMap<String, GroupInfo> dataIdGroupMap = this.addressGroupCache.get(address); if (dataIdGroupMap == null) { dataIdGroupMap = new ConcurrentHashMap<String, GroupInfo>(); ConcurrentHashMap<String, GroupInfo> oldMap = this.addressGroupCache.putIfAbsent(address, dataIdGroupMap); if (oldMap != null) { dataIdGroupMap = oldMap; } } GroupInfo groupInfo = new GroupInfo(address, dataId, group); this.persistService.addGroupInfo(groupInfo); // id groupInfo = this.persistService.findGroupInfoByAddressDataId(address, dataId); dataIdGroupMap.put(dataId, groupInfo); } // this.notifyService.notifyGroupChanged(); return true; }
From source file:com.taobao.diamond.server.service.GroupService.java
/** * , IP/* w w w . ja v a 2 s. c om*/ * * @param address * @param dataId * @param group * @param srcIp * @param srcUser * @return */ public boolean addAddress2GroupMapping(String address, String dataId, String group, String srcIp, String srcUser) { synchronized (this) { if (this.addressGroupCache.containsKey(address)) { ConcurrentHashMap<String, GroupInfo> subMap = this.addressGroupCache.get(address); if (subMap != null && subMap.containsKey(dataId)) return false; } ConcurrentHashMap<String, GroupInfo> dataIdGroupMap = this.addressGroupCache.get(address); if (dataIdGroupMap == null) { dataIdGroupMap = new ConcurrentHashMap<String, GroupInfo>(); ConcurrentHashMap<String, GroupInfo> oldMap = this.addressGroupCache.putIfAbsent(address, dataIdGroupMap); if (oldMap != null) { dataIdGroupMap = oldMap; } } GroupInfo groupInfo = new GroupInfo(address, dataId, group); // Timestamp currentTime = DiamondUtils.getCurrentTime(); this.persistService.addGroupInfo(srcIp, srcUser, currentTime, groupInfo); // id groupInfo = this.persistService.findGroupInfoByAddressDataId(address, dataId); dataIdGroupMap.put(dataId, groupInfo); } // this.notifyService.notifyGroupChanged(); return true; }
From source file:org.apache.stratos.aws.extension.AWSStatisticsReader.java
@Override public int getInFlightRequestCount(String clusterId) { int inFlightRequestCount = 0; ConcurrentHashMap<String, LoadBalancerInfo> clusterIdToLoadBalancerMap = AWSLoadBalancer .getClusterIdToLoadBalancerMap(); // Check if load balancer info is available for this cluster. // If yes, then find difference between total requests made to the load balancer and // total responses generated by instances attached to it. if (clusterIdToLoadBalancerMap.containsKey(clusterId)) { LoadBalancerInfo loadBalancerInfo = clusterIdToLoadBalancerMap.get(clusterId); String loadBalancerName = loadBalancerInfo.getName(); String region = loadBalancerInfo.getRegion(); // In flight request count = total requests - total responses inFlightRequestCount = awsHelper.getRequestCount(loadBalancerName, region, awsHelper.getStatisticsInterval()) - awsHelper.getAllResponsesCount(loadBalancerName, region, awsHelper.getStatisticsInterval()); if (inFlightRequestCount < 0) inFlightRequestCount = 0;/* ww w . j ava 2 s . c o m*/ } return inFlightRequestCount; }