List of usage examples for java.util.concurrent ConcurrentHashMap get
public V get(Object key)
From source file:com.yahoo.elide.core.EntityDictionary.java
/** * If a relationship is bidirectional, returns the name of the peer relationship in the peer entity. * @param cls the cls/*from w w w. j a va2 s. c om*/ * @param relation the relation * @return relation inverse */ public String getRelationInverse(Class<?> cls, String relation) { final ConcurrentHashMap<String, String> mappings = entityBinding(cls).relationshipToInverse; if (mappings != null) { final String mapping = mappings.get(relation); if (mapping != null && !mapping.equals("")) { return mapping; } } /* * This could be the owning side of the relation. Let's see if the entity referenced in the relation * has a bidirectional reference that is mapped to the given relation. */ final Class<?> inverseType = getParameterizedType(cls, relation); final ConcurrentHashMap<String, String> inverseMappings = entityBinding(inverseType).relationshipToInverse; for (Map.Entry<String, String> inverseMapping : inverseMappings.entrySet()) { String inverseRelationName = inverseMapping.getKey(); String inverseMappedBy = inverseMapping.getValue(); if (relation.equals(inverseMappedBy) && getParameterizedType(inverseType, inverseRelationName).equals(lookupEntityClass(cls))) { return inverseRelationName; } } return ""; }
From source file:org.wso2.carbon.device.mgt.iot.output.adapter.ui.UIEventAdapter.java
@Override public void init() throws OutputEventAdapterException { tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); //ExecutorService will be assigned if it is null if (executorService == null) { int minThread; int maxThread; long defaultKeepAliveTime; int jobQueSize; //If global properties are available those will be assigned else constant values will be assigned if (globalProperties.get(UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) { minThread = Integer/*from w w w.ja va2s. c om*/ .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME)); } else { minThread = UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE; } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) { maxThread = Integer .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME)); } else { maxThread = UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE; } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) { defaultKeepAliveTime = Integer .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME)); } else { defaultKeepAliveTime = UIEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS; } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) { jobQueSize = Integer.parseInt( globalProperties.get(UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME)); } else { jobQueSize = UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE; } executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize)); } streamId = eventAdapterConfiguration.getOutputStreamIdOfWso2eventMessageFormat(); if (streamId == null || streamId.isEmpty()) { throw new OutputEventAdapterRuntimeException("UI event adapter needs a output stream id"); } // fetch the "streamDefinition" corresponding to the "streamId" and then fetch the different attribute types // of the streamDefinition corresponding to the event's streamId. They are required when validating values in // the events against the streamDef attributes. StreamDefinition streamDefinition = getStreamDefinition(streamId); streamMetaAttributes = streamDefinition.getMetaData(); streamCorrelationAttributes = streamDefinition.getCorrelationData(); streamPayloadAttributes = streamDefinition.getPayloadData(); ConcurrentHashMap<Integer, ConcurrentHashMap<String, String>> tenantSpecifcEventOutputAdapterMap = UIEventAdaptorServiceDataHolder .getTenantSpecificOutputEventStreamAdapterMap(); ConcurrentHashMap<String, String> streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); if (streamSpecifAdapterMap == null) { streamSpecifAdapterMap = new ConcurrentHashMap<>(); if (null != tenantSpecifcEventOutputAdapterMap.putIfAbsent(tenantId, streamSpecifAdapterMap)) { streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); } } String adapterName = streamSpecifAdapterMap.get(streamId); if (adapterName != null) { throw new OutputEventAdapterException(("An Output ui event adapter \"" + adapterName + "\" is already" + " exist for stream id \"" + streamId + "\"")); } else { streamSpecifAdapterMap.put(streamId, eventAdapterConfiguration.getName()); ConcurrentHashMap<Integer, ConcurrentHashMap<String, LinkedBlockingDeque<Object>>> tenantSpecificStreamMap = UIEventAdaptorServiceDataHolder .getTenantSpecificStreamEventMap(); ConcurrentHashMap<String, LinkedBlockingDeque<Object>> streamSpecificEventsMap = tenantSpecificStreamMap .get(tenantId); if (streamSpecificEventsMap == null) { streamSpecificEventsMap = new ConcurrentHashMap<>(); if (null != tenantSpecificStreamMap.putIfAbsent(tenantId, streamSpecificEventsMap)) { streamSpecificEventsMap = tenantSpecificStreamMap.get(tenantId); } } streamSpecificEvents = streamSpecificEventsMap.get(streamId); if (streamSpecificEvents == null) { streamSpecificEvents = new LinkedBlockingDeque<>(); if (null != streamSpecificEventsMap.putIfAbsent(streamId, streamSpecificEvents)) { streamSpecificEvents = streamSpecificEventsMap.get(streamId); } } } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME) != null) { try { queueSize = Integer .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME)); } catch (NumberFormatException e) { log.error("String does not have the appropriate format for conversion." + e.getMessage()); queueSize = UIEventAdapterConstants.EVENTS_QUEUE_SIZE; } } else { queueSize = UIEventAdapterConstants.EVENTS_QUEUE_SIZE; } }
From source file:org.apache.falcon.entity.store.ConfigurationStore.java
/** * @param type - Entity type that is being retrieved * @param name - Name as it appears in the entity xml definition * @param <T> - Actual Entity object type * @return - Entity object from internal dictionary, If the object is not * loaded in memory yet, it will retrieve it from persistent store * just in time. On startup all the entities will be added to the * dictionary with null reference. * @throws FalconException/*from w ww. j a va 2s. c om*/ */ @SuppressWarnings("unchecked") public <T extends Entity> T get(EntityType type, String name) throws FalconException { ConcurrentHashMap<String, Entity> entityMap = dictionary.get(type); if (entityMap.containsKey(name)) { if (updatesInProgress.get() != null && updatesInProgress.get().getEntityType() == type && updatesInProgress.get().getName().equals(name)) { return (T) updatesInProgress.get(); } T entity = (T) entityMap.get(name); if (entity == NULL && shouldPersist) { // Object equality being checked try { entity = this.restore(type, name); } catch (IOException e) { throw new StoreAccessException(e); } entityMap.put(name, entity); return entity; } else { return entity; } } else { return null; } }
From source file:com.weibo.api.motan.registry.zookeeper.ZookeeperRegistry.java
@Override protected void subscribeCommand(final URL url, final CommandListener commandListener) { try {/*w ww .j a va2s.c o m*/ clientLock.lock(); ConcurrentHashMap<CommandListener, IZkDataListener> dataChangeListeners = commandListeners.get(url); if (dataChangeListeners == null) { commandListeners.putIfAbsent(url, new ConcurrentHashMap<CommandListener, IZkDataListener>()); dataChangeListeners = commandListeners.get(url); } IZkDataListener zkDataListener = dataChangeListeners.get(commandListener); if (zkDataListener == null) { dataChangeListeners.putIfAbsent(commandListener, new IZkDataListener() { @Override public void handleDataChange(String dataPath, Object data) throws Exception { commandListener.notifyCommand(url, (String) data); LoggerUtil .info(String.format("[ZookeeperRegistry] command data change: path=%s, command=%s", dataPath, (String) data)); } @Override public void handleDataDeleted(String dataPath) throws Exception { commandListener.notifyCommand(url, null); LoggerUtil.info(String.format("[ZookeeperRegistry] command deleted: path=%s", dataPath)); } }); zkDataListener = dataChangeListeners.get(commandListener); } String commandPath = ZkUtils.toCommandPath(url); zkClient.subscribeDataChanges(commandPath, zkDataListener); LoggerUtil.info(String.format("[ZookeeperRegistry] subscribe command: path=%s, info=%s", commandPath, url.toFullStr())); } catch (Throwable e) { throw new MotanFrameworkException(String.format("Failed to subscribe %s to zookeeper(%s), cause: %s", url, getUrl(), e.getMessage()), e); } finally { clientLock.unlock(); } }
From source file:com.yahoo.elide.core.EntityDictionary.java
/** * Get the type of relationship from a relation. * * @param cls Entity class/*from w w w . jav a 2s .c om*/ * @param relation Name of relationship field * @return Relationship type. RelationshipType.NONE if is none found. */ public RelationshipType getRelationshipType(Class<?> cls, String relation) { final ConcurrentHashMap<String, RelationshipType> types = entityBinding(cls).relationshipTypes; if (types == null) { return RelationshipType.NONE; } final RelationshipType type = types.get(relation); return (type == null) ? RelationshipType.NONE : type; }
From source file:com.weibo.api.motan.registry.zookeeper.ZookeeperRegistry.java
@Override protected void subscribeService(final URL url, final ServiceListener serviceListener) { try {//w w w . ja v a 2s . c om clientLock.lock(); ConcurrentHashMap<ServiceListener, IZkChildListener> childChangeListeners = serviceListeners.get(url); if (childChangeListeners == null) { serviceListeners.putIfAbsent(url, new ConcurrentHashMap<ServiceListener, IZkChildListener>()); childChangeListeners = serviceListeners.get(url); } IZkChildListener zkChildListener = childChangeListeners.get(serviceListener); if (zkChildListener == null) { childChangeListeners.putIfAbsent(serviceListener, new IZkChildListener() { @Override public void handleChildChange(String parentPath, List<String> currentChilds) { serviceListener.notifyService(url, getUrl(), nodeChildsToUrls(url, parentPath, currentChilds)); LoggerUtil.info( String.format("[ZookeeperRegistry] service list change: path=%s, currentChilds=%s", parentPath, currentChilds.toString())); } }); zkChildListener = childChangeListeners.get(serviceListener); } // removeNode(url, ZkNodeType.CLIENT); createNode(url, ZkNodeType.CLIENT); String serverTypePath = ZkUtils.toNodeTypePath(url, ZkNodeType.AVAILABLE_SERVER); zkClient.subscribeChildChanges(serverTypePath, zkChildListener); LoggerUtil.info(String.format("[ZookeeperRegistry] subscribe service: path=%s, info=%s", ZkUtils.toNodePath(url, ZkNodeType.AVAILABLE_SERVER), url.toFullStr())); } catch (Throwable e) { throw new MotanFrameworkException(String.format("Failed to subscribe %s to zookeeper(%s), cause: %s", url, getUrl(), e.getMessage()), e); } finally { clientLock.unlock(); } }
From source file:com.yahoo.elide.core.EntityDictionary.java
/** * Retrieve the parameterized type for the given field. * * @param entityClass the entity class/*from ww w . ja v a 2s . c o m*/ * @param identifier the identifier * @param paramIndex the index of the parameterization * @return Entity type for field otherwise null. */ public Class<?> getParameterizedType(Class<?> entityClass, String identifier, int paramIndex) { ConcurrentHashMap<String, AccessibleObject> fieldOrMethods = entityBinding(entityClass).fieldsToValues; if (fieldOrMethods == null) { return null; } AccessibleObject fieldOrMethod = fieldOrMethods.get(identifier); if (fieldOrMethod == null) { return null; } Type type; if (fieldOrMethod instanceof Method) { type = ((Method) fieldOrMethod).getGenericReturnType(); } else { type = ((Field) fieldOrMethod).getGenericType(); } if (type instanceof ParameterizedType) { return (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[paramIndex]; } return getType(entityClass, identifier); }
From source file:com.taobao.tddl.common.StatMonitor.java
void visitMap0(SortedSet<Item> sortedSet, ConcurrentHashMap<String, Value1> map0, String key1, String key2, String key3) {//w w w. java2s .c o m if ("*".equals(key1)) { for (Map.Entry<String, Value1> entry : map0.entrySet()) { visitMap1(sortedSet, entry.getValue().map1, entry.getKey(), key2, key3); } } else { Value1 value1 = map0.get(key1); if (value1 != null) { visitMap1(sortedSet, value1.map1, key1, key2, key3); } } }
From source file:com.taobao.tddl.common.StatMonitor.java
void visitMap1(SortedSet<Item> sortedSet, ConcurrentHashMap<String, Value2> map1, String key1, String key2, String key3) {/*from w w w. j a va2s . c o m*/ if ("*".equals(key2)) { for (Map.Entry<String, Value2> entry : map1.entrySet()) { visitMap2(sortedSet, entry.getValue().map2, key1, entry.getKey(), key3); } } else { Value2 value2 = map1.get(key2); if (value2 != null) { visitMap2(sortedSet, value2.map2, key1, key2, key3); } } }
From source file:org.wso2.carbon.event.output.adaptor.wso2event.WSO2EventAdaptorType.java
/** * @param outputEventAdaptorMessageConfiguration * - topic name to publish messages * @param message - is and Object[]{Event, EventDefinition} * @param outputEventAdaptorConfiguration * * @param tenantId/*ww w . j a v a2s. co m*/ */ public void publish(OutputEventAdaptorMessageConfiguration outputEventAdaptorMessageConfiguration, Object message, OutputEventAdaptorConfiguration outputEventAdaptorConfiguration, int tenantId) { ConcurrentHashMap<OutputEventAdaptorConfiguration, LoadBalancingDataPublisher> dataPublishers = dataPublisherMap .get(tenantId); if (dataPublishers == null) { dataPublishers = new ConcurrentHashMap<OutputEventAdaptorConfiguration, LoadBalancingDataPublisher>(); dataPublisherMap.putIfAbsent(tenantId, dataPublishers); dataPublishers = dataPublisherMap.get(tenantId); } LoadBalancingDataPublisher dataPublisher = dataPublishers.get(outputEventAdaptorConfiguration); if (dataPublisher == null) { synchronized (this) { dataPublisher = dataPublishers.get(outputEventAdaptorConfiguration); if (dataPublisher == null) { dataPublisher = createDataPublisher(outputEventAdaptorConfiguration); dataPublishers.putIfAbsent(outputEventAdaptorConfiguration, dataPublisher); } } } try { Event event = (Event) ((Object[]) message)[0]; StreamDefinition streamDefinition = (StreamDefinition) ((Object[]) message)[1]; if (!dataPublisher.isStreamDefinitionAdded(streamDefinition)) { dataPublisher.addStreamDefinition(streamDefinition); //Sending the first Event publishEvent(outputEventAdaptorConfiguration, dataPublisher, event, streamDefinition); } else { //Sending Events publishEvent(outputEventAdaptorConfiguration, dataPublisher, event, streamDefinition); } } catch (Exception ex) { throw new OutputEventAdaptorEventProcessingException( ex.getMessage() + " Error Occurred When Publishing Events", ex); } }