List of usage examples for java.util.concurrent ConcurrentHashMap put
public V put(K key, V value)
From source file:org.apache.kylin.job.CubeMetadataUpgrade.java
private void upgradeCubeInstance() { ResourceStore store = getStore();//w w w. jav a 2 s .com List<String> paths = listResourceStore(ResourceStore.CUBE_RESOURCE_ROOT); for (String path : paths) { CubeInstance cubeInstance = null; try { cubeInstance = store.getResource(path, CubeInstance.class, new JsonSerializer<CubeInstance>(CubeInstance.class)); cubeInstance.setConfig(config); org.apache.kylin.cube.CubeInstance newInstance = new org.apache.kylin.cube.CubeInstance(); newInstance.setName(cubeInstance.getName()); newInstance.setDescName(cubeInstance.getDescName()); newInstance.setOwner(cubeInstance.getOwner()); newInstance.setUuid(cubeInstance.getUuid()); newInstance.setVersion(cubeInstance.getVersion()); newInstance.setCreateTimeUTC(RootPersistentEntity.parseTime(cubeInstance.getCreateTime())); newInstance.setLastModified(cubeInstance.getLastModified()); //status if (cubeInstance.getStatus() == CubeStatusEnum.BUILDING) { newInstance.setStatus(RealizationStatusEnum.BUILDING); } else if (cubeInstance.getStatus() == CubeStatusEnum.DESCBROKEN) { newInstance.setStatus(RealizationStatusEnum.DESCBROKEN); } else if (cubeInstance.getStatus() == CubeStatusEnum.DISABLED) { newInstance.setStatus(RealizationStatusEnum.DISABLED); } else if (cubeInstance.getStatus() == CubeStatusEnum.READY) { newInstance.setStatus(RealizationStatusEnum.READY); } List<org.apache.kylin.cube.CubeSegment> newSegments = Lists.newArrayList(); // segment for (CubeSegment segment : cubeInstance.getSegments()) { org.apache.kylin.cube.CubeSegment newSeg = new org.apache.kylin.cube.CubeSegment(); newSegments.add(newSeg); newSeg.setUuid(segment.getUuid()); newSeg.setName(segment.getName()); newSeg.setStorageLocationIdentifier(segment.getStorageLocationIdentifier()); newSeg.setDateRangeStart(segment.getDateRangeStart()); newSeg.setDateRangeEnd(segment.getDateRangeEnd()); if (segment.getStatus() == CubeSegmentStatusEnum.NEW) { newSeg.setStatus(SegmentStatusEnum.NEW); } else if (segment.getStatus() == CubeSegmentStatusEnum.READY) { newSeg.setStatus(SegmentStatusEnum.READY); } else if (segment.getStatus() == CubeSegmentStatusEnum.READY_PENDING) { newSeg.setStatus(SegmentStatusEnum.READY_PENDING); } newSeg.setSizeKB(segment.getSizeKB()); newSeg.setInputRecords(segment.getSourceRecords()); newSeg.setInputRecordsSize(segment.getSourceRecordsSize()); newSeg.setLastBuildTime(segment.getLastBuildTime()); newSeg.setLastBuildJobID(segment.getLastBuildJobID()); newSeg.setCreateTimeUTC(RootPersistentEntity.parseTime(segment.getCreateTime())); newSeg.setBinarySignature(segment.getBinarySignature()); ConcurrentHashMap<String, String> newDictionaries = new ConcurrentHashMap<String, String>(); for (Map.Entry<String, String> e : segment.getDictionaries().entrySet()) { String key = e.getKey(); String[] tableCol = StringUtils.split(key, "/"); key = appendDBName(tableCol[0]) + "/" + tableCol[1]; newDictionaries.put(key, e.getValue()); } newSeg.setDictionaries(newDictionaries); ConcurrentHashMap<String, String> newSnapshots = new ConcurrentHashMap<String, String>(); for (Map.Entry<String, String> e : segment.getSnapshots().entrySet()) { newSnapshots.put(appendDBName(e.getKey()), e.getValue()); } newSeg.setSnapshots(newSnapshots); } newInstance.setSegments(newSegments); store.putResource(newInstance.getResourcePath(), newInstance, CubeManager.CUBE_SERIALIZER); } catch (Exception e) { logger.error("Error during load cube instance " + path, e); } } }
From source file:org.rifidi.edge.core.configuration.services.ConfigurationServiceImpl.java
/** * Load the configuration. Not thread safe. * //from ww w . j ava2 s.c o m * @return */ private ConcurrentHashMap<String, Set<DefaultConfigurationImpl>> loadConfig() { ConcurrentHashMap<String, Set<DefaultConfigurationImpl>> ret = new ConcurrentHashMap<String, Set<DefaultConfigurationImpl>>(); ConfigurationStore store; try { store = (ConfigurationStore) jaxbContext.createUnmarshaller().unmarshal(persistanceResource.getFile()); } catch (IOException e) { logger.error(e); return ret; } catch (JAXBException e) { logger.error(e); return ret; } if (store.getServices() != null) { for (ServiceStore service : store.getServices()) { if (ret.get(service.getFactoryID()) == null) { ret.put(service.getFactoryID(), new CopyOnWriteArraySet<DefaultConfigurationImpl>()); } AttributeList attributes = new AttributeList(); // get all properties for (String key : service.getAttributes().keySet()) { // factoryid is already processed if (Constants.FACTORYID.equals(key)) { continue; } // type is already processed if (Constants.FACTORY_TYPE.equals(key)) { continue; } attributes.add(new Attribute(key, service.getAttributes().get(key))); } if (!checkName(service.getServiceID())) { continue; } ret.get(service.getFactoryID()).add(createAndRegisterConfiguration(service.getServiceID(), service.getFactoryID(), attributes, service.getSessionDTOs())); serviceNames.add(service.getServiceID()); } } return ret; }
From source file:fastcall.FastCallSNP.java
private ConcurrentHashMap<BufferedReader, List<String>> getReaderRemainderMap( HashMap<String, BufferedReader> bamPathPileupReaderMap) { ArrayList<String> empty = new ArrayList(); ConcurrentHashMap<BufferedReader, List<String>> readerRemainderMap = new ConcurrentHashMap(); Set<Map.Entry<String, BufferedReader>> enties = bamPathPileupReaderMap.entrySet(); enties.stream().forEach(e -> {/* w w w . j a va 2 s . co m*/ readerRemainderMap.put(e.getValue(), empty); }); return readerRemainderMap; }
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 w w . j ava2 s . com*/ */ @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:org.apache.marmotta.ucuenca.wk.commons.function.SemanticDistance.java
/** * @param args the command line arguments *//* w w w. j av a2s . c o m*/ public synchronized double semanticKeywordsDistance(List<String> a, List<String> b) throws ClassNotFoundException, SQLException, IOException { Class.forName("org.postgresql.Driver"); conn = DriverManager.getConnection(dburl, user, pass); ConcurrentHashMap<String, List<String>> map = new ConcurrentHashMap<>(); List<String> authors = new ArrayList(); authors.add("a1"); authors.add("a2"); ConcurrentHashMap<String, Double> result = new ConcurrentHashMap<>(); double avg = 0; double har = 0; for (int i = 0; i < authors.size(); i++) { for (int j = i + 1; j < authors.size(); j++) { String a1 = authors.get(i); String a2 = authors.get(j); List<String> ka1 = null; List<String> ka2 = null; if (map.containsKey(a1)) { ka1 = map.get(a1); } else { ka1 = formatList(a);//consultado2R(a1, Endpoints.get(i)); map.put(a1, ka1); } if (map.containsKey(a2)) { ka2 = map.get(a2); } else { ka2 = formatList(b);//consultado2R(a2, Endpoints.get(j)); map.put(a2, ka2); } double sum = 0; double num = 0; for (String t1 : ka1) { for (String t2 : ka2) { num++; String tt1 = t1; String tt2 = t2; double v = ngd(tt1, tt2); sum += v; } } double prom = sum / num; if (num == 0 && sum == 0) { prom = 2; } result.put(i + "," + j, prom); avg = avg(avg, prom); har = har(har, prom); } } conn.close(); return mapEntry(result); }
From source file:com.thoughtworks.go.server.service.PipelineConfigServicePerformanceTest.java
@Test public void performanceTestForUpdatePipeline() throws Exception { setupPipelines(numberOfRequests);/* ww w . ja va 2s .c o m*/ final ConcurrentHashMap<String, Boolean> results = new ConcurrentHashMap<>(); run(new Runnable() { @Override public void run() { PipelineConfig pipelineConfig = goConfigService.getConfigForEditing() .pipelineConfigByName(new CaseInsensitiveString(Thread.currentThread().getName())); pipelineConfig.add(new StageConfig(new CaseInsensitiveString("additional_stage"), new JobConfigs(new JobConfig(new CaseInsensitiveString("addtn_job"))))); PerfTimer updateTimer = PerfTimer.start("Saving pipelineConfig : " + pipelineConfig.name()); pipelineConfigService.updatePipelineConfig(user, pipelineConfig, entityHashingService.md5ForEntity(pipelineConfig), result); updateTimer.stop(); results.put(Thread.currentThread().getName(), result.isSuccessful()); if (!result.isSuccessful()) { LOGGER.error(result.toString()); LOGGER.error("Errors on pipeline" + Thread.currentThread().getName() + " are : " + StringUtils.join(getAllErrors(pipelineConfig), ", ")); } } }, numberOfRequests, results); }
From source file:com.thoughtworks.go.server.service.PipelineConfigServicePerformanceTest.java
@Test public void performanceTestForCreatePipeline() throws Exception { setupPipelines(0);//from w ww .j a v a 2 s .co m final ConcurrentHashMap<String, Boolean> results = new ConcurrentHashMap<>(); run(new Runnable() { @Override public void run() { JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("job")); StageConfig stageConfig = new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(jobConfig)); PipelineConfig pipelineConfig = new PipelineConfig( new CaseInsensitiveString(Thread.currentThread().getName()), new MaterialConfigs(git("FOO")), stageConfig); PerfTimer updateTimer = PerfTimer.start("Saving pipelineConfig : " + pipelineConfig.name()); pipelineConfigService.createPipelineConfig(user, pipelineConfig, result, "jumbo"); updateTimer.stop(); results.put(Thread.currentThread().getName(), result.isSuccessful()); if (!result.isSuccessful()) { LOGGER.error(result.toString()); LOGGER.error("Errors on pipeline" + Thread.currentThread().getName() + " are : " + StringUtils.join(getAllErrors(pipelineConfig), ", ")); } } }, numberOfRequests, results); }
From source file:org.seedstack.mqtt.internal.MqttModuleTest.java
/** * Test method for//from w w w . j a v a 2s . co m * {@link org.seedstack.mqtt.internal.MqttModule#configure()}. * * @throws Exception * if an error occurred */ @Test public void testConfigureWithListener(@Mocked final Binder binder, @Mocked final MqttClientUtils mqttClientUtils, @Mocked final Configuration configuration) throws Exception { ConcurrentHashMap<String, MqttClientDefinition> mqttClientDefinitions = new ConcurrentHashMap<String, MqttClientDefinition>(); ConcurrentHashMap<String, IMqttClient> mqttClients = new ConcurrentHashMap<String, IMqttClient>(); final String uri = "uri"; final String clientId = "id"; final String clientName = "name"; MqttClientDefinition clientDefinition = new MqttClientDefinition(uri, clientId); final MqttListenerDefinition listenerDefinition = new MqttListenerDefinition(Listener1.class, Listener1.class.getCanonicalName(), new String[] { "topic" }, new int[] { 0 }); clientDefinition.setListenerDefinition(listenerDefinition); final MqttPoolDefinition poolDefinition = new MqttPoolDefinition(configuration); final String handlerName = "rejectName"; poolDefinition.setRejectHandler(MqttRejectedExecutionHandler.class, handlerName); clientDefinition.setPoolDefinition(poolDefinition); mqttClientDefinitions.put(clientName, clientDefinition); mqttClients.put(clientName, mqttClient); MqttModule module = new MqttModule(mqttClients, mqttClientDefinitions); module.configure(binder); new Verifications() { { binder.bind(IMqttClient.class).annotatedWith(Names.named(clientName)).toInstance(mqttClient); binder.bind(MqttCallback.class).annotatedWith(Names.named(Listener1.class.getCanonicalName())) .to(Listener1.class); binder.bind(MqttRejectedExecutionHandler.class).annotatedWith(Names.named(handlerName)) .to(MqttRejectedExecutionHandler.class); } }; }
From source file:org.wso2.carbon.event.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// w ww . j a v a2 s. co m .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"); } ConcurrentHashMap<Integer, ConcurrentHashMap<String, String>> tenantSpecifcEventOutputAdapterMap = UIEventAdaptorServiceInternalValueHolder .getTenantSpecificOutputEventStreamAdapterMap(); ConcurrentHashMap<String, String> streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); if (streamSpecifAdapterMap == null) { streamSpecifAdapterMap = new ConcurrentHashMap<String, String>(); 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 = UIEventAdaptorServiceInternalValueHolder .getTenantSpecificStreamEventMap(); ConcurrentHashMap<String, LinkedBlockingDeque<Object>> streamSpecificEventsMap = tenantSpecificStreamMap .get(tenantId); if (streamSpecificEventsMap == null) { streamSpecificEventsMap = new ConcurrentHashMap<String, LinkedBlockingDeque<Object>>(); if (null != tenantSpecificStreamMap.putIfAbsent(tenantId, streamSpecificEventsMap)) { streamSpecificEventsMap = tenantSpecificStreamMap.get(tenantId); } } streamSpecificEvents = streamSpecificEventsMap.get(streamId); if (streamSpecificEvents == null) { streamSpecificEvents = new LinkedBlockingDeque<Object>(); 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:com.alibaba.napoli.gecko.service.impl.BaseRemotingController.java
public void setAttribute(final String url, final String key, final Object value) { ConcurrentHashMap<String, Object> subAttr = this.attributes.get(url); if (subAttr == null) { subAttr = new ConcurrentHashMap<String, Object>(); final ConcurrentHashMap<String, Object> oldSubAttr = this.attributes.putIfAbsent(url, subAttr); if (oldSubAttr != null) { subAttr = oldSubAttr;//from w w w.j a v a 2 s . com } } subAttr.put(key, value); }