List of usage examples for java.util.concurrent ConcurrentHashMap ConcurrentHashMap
public ConcurrentHashMap()
From source file:com.blacklocus.qs.worker.util.log.SamplingQSLogServiceTest.java
@Test public void testSampledLifeCycle() throws InterruptedException { // With these parameters, by far most logger interactions should be filtered out, very few sampled in. final int numThreads = 64, iterations = 200, processingJitterMaxMs = 16, noSoonerThanMs = 100; final Set<String> sampledTaskIds = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); final QSLogService logService = Mockito.mock(QSLogService.class); // track which logging interactions were allowed through (sampled in) Mockito.doAnswer(new Answer() { @Override/*from w w w. j a va 2 s. c o m*/ public Object answer(InvocationOnMock invocation) throws Throwable { sampledTaskIds.add(((QSTaskModel) invocation.getArguments()[0]).taskId); return null; } }).when(logService).startedTask(Matchers.any(QSTaskModel.class)); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { sampledTaskIds.add(((QSLogModel) invocation.getArguments()[0]).taskId); return null; //TODO jason } }).when(logService).log(Matchers.any(QSLogModel.class)); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { sampledTaskIds.add(((QSTaskModel) invocation.getArguments()[0]).taskId); return null; //TODO jason } }).when(logService).completedTask(Matchers.any(QSTaskModel.class)); Predicate<QSTaskModel> taskPredicate = SamplingPredicates.noSoonerThan(noSoonerThanMs, TimeUnit.MILLISECONDS); final QSLogService sampledLogService = new SamplingQSLogService(logService, taskPredicate); long startNs = System.nanoTime(); ExecutorService threads = Executors.newFixedThreadPool(numThreads); for (int i = 0; i < numThreads; i++) { threads.submit(new Callable<Void>() { @Override public Void call() throws Exception { LOG.debug("Thread start {}", Thread.currentThread().getName()); for (int i = 0; i < iterations; i++) { String taskId = UUID.randomUUID().toString(); // simulate task processing, some have logs, some don't, processing time varies between each step QSTaskModel task = new QSTaskModel(); task.taskId = taskId; Thread.sleep(RandomUtils.nextInt(processingJitterMaxMs)); sampledLogService.startedTask(task); Thread.sleep(RandomUtils.nextInt(processingJitterMaxMs)); // random number of associated logs [0, 2] for (int j = RandomUtils.nextInt(2); j > 0; j--) { QSLogModel log = new QSLogModel(); log.taskId = taskId; sampledLogService.log(log); Thread.sleep(RandomUtils.nextInt(processingJitterMaxMs)); } sampledLogService.completedTask(task); } LOG.debug("Thread end {}", Thread.currentThread().getName()); return null; } }); } threads.shutdown(); threads.awaitTermination(1, TimeUnit.MINUTES); long endNs = System.nanoTime(); // Theoretical maximum number of sampled in task logging long durationMs = TimeUnit.NANOSECONDS.toMillis(endNs - startNs); long expectedMax = durationMs / noSoonerThanMs + 1; // +1 for time@0: sampled in LOG.debug("Run duration: {}ms no sooner than: {}ms", durationMs, noSoonerThanMs); LOG.debug("Expected max sampled in: {} Actually sampled: {}", expectedMax, sampledTaskIds.size()); Assert.assertTrue(expectedMax >= sampledTaskIds.size()); }
From source file:com.codemacro.jcm.storage.StatusStorage.java
public StatusStorage(ClusterManager clusterManager) { this.clusterManager = clusterManager; this.statusCache = new ConcurrentHashMap<String, String>(); }
From source file:com.vmware.identity.idm.server.provider.LdapConnectionPool.java
private LdapConnectionPool() { String systemTenant = IdmServerConfig.getInstance().getDirectoryConfigStoreDomain().toLowerCase(); GenericKeyedObjectPool<PooledLdapConnectionIdentity, ILdapConnectionEx> systemTenantPool = new GenericKeyedObjectPool<>( new PooledLdapConnectionFactory(), getGenericKeyedObjectPoolConfig(systemTenant)); this.poolMap = new ConcurrentHashMap<>(); this.poolMap.put(systemTenant, systemTenantPool); }
From source file:com.mirth.connect.plugins.serverlog.ServerLogProvider.java
private void initialize() { // add the new appender Appender arrayAppender = new ArrayAppender(this); Layout patternLayout = new PatternLayout("[%d] %-5p (%c:%L): %m%n"); arrayAppender.setLayout(patternLayout); patternLayout.activateOptions();//from w w w .jav a 2s . c o m Logger.getRootLogger().addAppender(arrayAppender); lastDisplayedServerLogIdBySessionId = new ConcurrentHashMap<String, Long>(); }
From source file:com.github.jknack.handlebars.cache.ConcurrentMapTemplateCache.java
/** * Creates a new ConcurrentMapTemplateCache. *//*from ww w .j a v a 2 s . c o m*/ public ConcurrentMapTemplateCache() { this(new ConcurrentHashMap<TemplateSource, Pair<TemplateSource, Template>>()); }
From source file:com.flipkart.flux.guice.module.AkkaModule.java
/** * Returns map of all the available routers and actors per router, * currently a router is created per Task of deployment unit //todo: handle dynamic deployments *///from w w w . j a va2 s. c o m @Provides @Singleton @Named("routerConfigMap") public Map<String, Integer> getRouterConfigs( @Named("deploymentUnits") Map<String, DeploymentUnit> deploymentUnitsMap, @Named("routers.default.instancesPerNode") int defaultNoOfActors) { Map<String, Integer> routerConfigMap = new ConcurrentHashMap<>(); //add all deployment units' routers for (Map.Entry<String, DeploymentUnit> deploymentUnitEntry : deploymentUnitsMap.entrySet()) { DeploymentUnit deploymentUnit = deploymentUnitEntry.getValue(); Set<Method> taskMethods = deploymentUnit.getTaskMethods(); Configuration taskConfiguration = deploymentUnit.getTaskConfiguration(); for (Method taskMethod : taskMethods) { String routerName = new MethodId(taskMethod).getPrefix(); Integer taskExecConcurrency = Optional .ofNullable((Integer) taskConfiguration.getProperty(routerName + ".executionConcurrency")) .orElse(defaultNoOfActors); routerConfigMap.put(routerName, taskExecConcurrency); } } return routerConfigMap; }
From source file:cn.com.dfc.pl.afinal.http.PreferencesCookieStore.java
/** * Construct a persistent cookie store./*from w w w . j a v a 2s. c o m*/ */ public PreferencesCookieStore(Context context) { cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, 0); cookies = new ConcurrentHashMap<String, Cookie>(); // Load any previously stored cookies into the store String storedCookieNames = cookiePrefs.getString(COOKIE_NAME_STORE, null); if (storedCookieNames != null) { String[] cookieNames = TextUtils.split(storedCookieNames, ","); for (String name : cookieNames) { String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null); if (encodedCookie != null) { Cookie decodedCookie = decodeCookie(encodedCookie); if (decodedCookie != null) { cookies.put(name, decodedCookie); } } } // Clear out expired cookies clearExpired(new Date()); } }
From source file:com.clustercontrol.monitor.util.EventSearchRunUtil.java
public Map<String, ViewListInfo> searchInfo(List<String> managerList, String facilityId, EventFilterInfo filter, int messages) { Map<String, ViewListInfo> dispDataMap = new ConcurrentHashMap<>(); Map<String, String> errMsgs = new ConcurrentHashMap<>(); long start = System.currentTimeMillis(); try {// w w w . java2s . c o m String threadName = Thread.currentThread().getName() + "-EventSearch"; List<EventSearchTask> searchList = new ArrayList<EventSearchTask>(); for (String managerName : managerList) { EventSearchTask task = null; task = new EventSearchTask(threadName, managerName, facilityId, filter, messages, ContextProvider.getContext()); searchList.add(task); } List<Future<Map<String, List<?>>>> list = getExecutorService().invokeAll(searchList); for (Future<Map<String, List<?>>> future : list) { if (future == null || future.get() == null) { continue; } Map<String, List<?>> map = future.get(); for (Map.Entry<String, List<?>> entry : map.entrySet()) { //?1?? String managerName = entry.getKey(); List<?> ret = entry.getValue(); if (ret.get(POS_INFO) != null && ret.get(POS_INFO) instanceof ViewListInfo) { ViewListInfo infoList = (ViewListInfo) ret.get(POS_INFO); dispDataMap.put(managerName, infoList); } if (ret.get(POS_ERROR) != null && ret.get(POS_ERROR) instanceof String) { String err = (String) ret.get(POS_ERROR); errMsgs.put(managerName, (String) err); } } } } catch (InterruptedException e) { m_log.error(e.getMessage() + e.getClass().getName()); } catch (ExecutionException e) { m_log.error(e.getMessage() + e.getClass().getName()); } // if (0 < errMsgs.size()) { UIManager.showMessageBox(errMsgs, true); } long end = System.currentTimeMillis(); m_log.debug("time=" + (end - start)); return dispDataMap; }
From source file:com.drive.student.xutils.util.CookieUtils.java
/** * Construct a persistent cookie store.//ww w.java2 s.c o m */ public CookieUtils(Context context) { cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, Context.MODE_PRIVATE); cookies = new ConcurrentHashMap<String, Cookie>(); // Load any previously stored cookies into the store String storedCookieNames = cookiePrefs.getString(COOKIE_NAME_STORE, null); if (storedCookieNames != null) { String[] cookieNames = TextUtils.split(storedCookieNames, ","); for (String name : cookieNames) { String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null); if (encodedCookie != null) { Cookie decodedCookie = decodeCookie(encodedCookie); if (decodedCookie != null) { cookies.put(name, decodedCookie); } } } // Clear out expired cookies // clearExpired(new Date()); } }
From source file:com.frank.search.solr.core.schema.SolrPersistentEntitySchemaCreator.java
public SolrPersistentEntitySchemaCreator(SolrClientFactory factory, SolrSchemaWriter schemaWriter) { super();//from w ww . j a v a 2s . c o m this.factory = factory; this.schemaWriter = schemaWriter != null ? schemaWriter : new SolrSchemaWriter(this.factory); this.schemaResolver = new SolrSchemaResolver(); this.processed = new ConcurrentHashMap<Class<?>, Class<?>>(); }