List of usage examples for com.google.common.collect Maps newConcurrentMap
public static <K, V> ConcurrentMap<K, V> newConcurrentMap()
From source file:com.google.sampling.experiential.server.PacoServiceImpl.java
public ExperimentQueryResult getUsersJoinedExperiments(Integer limit, String cursor) { List<com.google.sampling.experiential.server.Query> queries = new QueryParser() .parse("who=" + getWhoFromLogin().getEmail().toLowerCase()); List<Event> events = EventRetriever.getInstance().getEvents(queries, getWho(), TimeUtil.getTimeZoneForClient(getThreadLocalRequest()), 0, 20000); Map<Long, String> experimentIdTitleMap = Maps.newConcurrentMap(); Set<Long> experimentIds = Sets.newHashSet(); for (Event event : events) { if (event.getExperimentId() == null) { continue; // legacy check }/*from w w w . j a v a 2s .com*/ long experimentId = Long.parseLong(event.getExperimentId()); experimentIds.add(experimentId); String experimentTitle = event.getExperimentName(); if (Strings.isNullOrEmpty(experimentTitle)) { experimentTitle = ""; } experimentIdTitleMap.put(experimentId, experimentTitle); } List<ExperimentDAO> experimentDAOs = Lists.newArrayList(); if (experimentIds.size() == 0) { return new ExperimentQueryResult(cursor, experimentDAOs); } ArrayList<Long> idList = Lists.newArrayList(experimentIds); System.out.println("Found " + experimentIds.size() + " unique experiments where joined."); System.out.println(Joiner.on(",").join(idList)); PersistenceManager pm = null; try { pm = PMF.get().getPersistenceManager(); Query q = pm.newQuery(Experiment.class, ":p.contains(id)"); List<Experiment> experiments = (List<Experiment>) q.execute(idList); System.out.println("Got back " + experiments.size() + " experiments"); if (experiments != null) { for (Experiment experiment : experiments) { experimentDAOs.add(DAOConverter.createDAO(experiment)); idList.remove(experiment.getId().longValue()); } } for (Long id : idList) { String titleFromEvent = experimentIdTitleMap.get(id); if (titleFromEvent != null) { titleFromEvent = titleFromEvent + " (Deleted)"; } else { titleFromEvent = " (Deleted)"; } experimentDAOs.add(new ExperimentDAO(id, titleFromEvent, "", "", "", null, null, null, null, null, null, null, null, null, null, null, null, null, null, false, (String) null, FeedbackDAO.FEEDBACK_TYPE_CUSTOM, false, (String) null, false, false, null)); } } finally { if (pm != null) { pm.close(); } } return new ExperimentQueryResult(cursor, experimentDAOs); }
From source file:org.onosproject.vtnweb.resources.SubnetWebResource.java
/** * Changes hostRoutes JsonNode to a collection of the hostRoutes. * * @param hostRoutes the hostRoutes json node * @return a collection of hostRoutes/* w w w . j a va2s. c om*/ */ public Iterable<HostRoute> jsonNodeToHostRoutes(JsonNode hostRoutes) { checkNotNull(hostRoutes, JSON_NOT_NULL); ConcurrentMap<Integer, HostRoute> hostRouteMaps = Maps.newConcurrentMap(); Integer i = 0; for (JsonNode node : hostRoutes) { IpAddress nexthop = IpAddress.valueOf(node.get("nexthop").asText()); IpPrefix destination = IpPrefix.valueOf(node.get("destination").asText()); HostRoute hostRoute = new DefaultHostRoute(nexthop, destination); hostRouteMaps.putIfAbsent(i, hostRoute); i++; } return Collections.unmodifiableCollection(hostRouteMaps.values()); }
From source file:org.glowroot.agent.embedded.init.EmbeddedAgentModule.java
void initEmbeddedServer() throws Exception { if (simpleRepoModule == null) { // repo module failed to start return;/*from w w w .j av a2 s . c om*/ } if (agentModule != null) { uiModule = new CreateUiModuleBuilder().central(false).servlet(false).offlineViewer(false) .webPortReadOnly(WEB_PORT_OVERRIDE != null).confDirs(confDirs).logDir(logDir) .logFileNamePattern(Pattern.compile("glowroot.*\\.log")).ticker(ticker).clock(clock) .liveJvmService(agentModule.getLiveJvmService()) .agentDisplayRepository(new AgentDisplayRepositoryImpl()) .configRepository(simpleRepoModule.getConfigRepository()) .alertingDisabledRepository(simpleRepoModule.getAlertingDisabledDao()) .activeAgentRepository(new ActiveAgentRepositoryImpl()) .environmentRepository(simpleRepoModule.getEnvironmentDao()) .transactionTypeRepository(simpleRepoModule.getTransactionTypeRepository()) .traceAttributeNameRepository(simpleRepoModule.getTraceAttributeNameRepository()) .aggregateRepository(simpleRepoModule.getAggregateDao()) .traceRepository(simpleRepoModule.getTraceDao()) .gaugeValueRepository(simpleRepoModule.getGaugeValueDao()).syntheticResultRepository(null) .incidentRepository(simpleRepoModule.getIncidentDao()) .repoAdmin(simpleRepoModule.getRepoAdmin()) .rollupLevelService(simpleRepoModule.getRollupLevelService()) .liveTraceRepository(agentModule.getLiveTraceRepository()) .liveAggregateRepository(agentModule.getLiveAggregateRepository()) .liveWeavingService(agentModule.getLiveWeavingService()) .sessionMapFactory(new SessionMapFactory() { @Override public <V extends /*@NonNull*/ Serializable> ConcurrentMap<String, V> create() { return Maps.newConcurrentMap(); } }).httpClient(simpleRepoModule.getHttpClient()).numWorkerThreads(2).version(version).build(); } else { checkNotNull(offlineViewerAgentModule); uiModule = new CreateUiModuleBuilder().central(false).servlet(false).offlineViewer(true) .webPortReadOnly(WEB_PORT_OVERRIDE != null).confDirs(confDirs).logDir(logDir) .logFileNamePattern(Pattern.compile("glowroot.*\\.log")).ticker(ticker).clock(clock) .liveJvmService(null).agentDisplayRepository(new AgentDisplayRepositoryImpl()) .configRepository(simpleRepoModule.getConfigRepository()) .alertingDisabledRepository(simpleRepoModule.getAlertingDisabledDao()) .activeAgentRepository(new ActiveAgentRepositoryImpl()) .environmentRepository(simpleRepoModule.getEnvironmentDao()) .transactionTypeRepository(simpleRepoModule.getTransactionTypeRepository()) .traceAttributeNameRepository(simpleRepoModule.getTraceAttributeNameRepository()) .aggregateRepository(simpleRepoModule.getAggregateDao()) .traceRepository(simpleRepoModule.getTraceDao()) .gaugeValueRepository(simpleRepoModule.getGaugeValueDao()).syntheticResultRepository(null) .incidentRepository(simpleRepoModule.getIncidentDao()) .repoAdmin(simpleRepoModule.getRepoAdmin()) .rollupLevelService(simpleRepoModule.getRollupLevelService()) .liveTraceRepository(new LiveTraceRepositoryNop()) .liveAggregateRepository(new LiveAggregateRepositoryNop()).liveWeavingService(null) .sessionMapFactory(new SessionMapFactory() { @Override public <V extends /*@NonNull*/ Serializable> ConcurrentMap<String, V> create() { return Maps.newConcurrentMap(); } }).httpClient(simpleRepoModule.getHttpClient()).numWorkerThreads(10).version(version).build(); } }
From source file:org.apache.giraph.comm.ServerData.java
/** * Prepare resolving mutation. */ public void prepareResolveMutations() { oldPartitionMutations = partitionMutations; partitionMutations = Maps.newConcurrentMap(); }
From source file:org.onosproject.vtnweb.resources.VirtualPortWebResource.java
/** * Returns a Object of the currently known infrastructure virtualPort. * * @param allowedAddressPairs the allowedAddressPairs json node * @return a collection of allowedAddressPair *///from www.j ava2 s.co m public Collection<AllowedAddressPair> jsonNodeToAllowedAddressPair(JsonNode allowedAddressPairs) { checkNotNull(allowedAddressPairs, JSON_NOT_NULL); ConcurrentMap<Integer, AllowedAddressPair> allowMaps = Maps.newConcurrentMap(); int i = 0; for (JsonNode node : allowedAddressPairs) { IpAddress ip = IpAddress.valueOf(node.get("ip_address").asText()); MacAddress mac = MacAddress.valueOf(node.get("mac_address").asText()); AllowedAddressPair allows = AllowedAddressPair.allowedAddressPair(ip, mac); allowMaps.put(i, allows); i++; } log.debug("The jsonNode of allowedAddressPairallow is {}" + allowedAddressPairs.toString()); return Collections.unmodifiableCollection(allowMaps.values()); }
From source file:com.dtstack.jlogstash.distributed.ZkDistributed.java
public boolean downReblance() throws Exception { boolean result = false; try {/*w w w . j a v a2 s . com*/ this.updateNodelock.acquire(30, TimeUnit.SECONDS); BrokerNode brokerNode = BrokerNode.initBrokerNode(); Map<String, BrokerNode> nodes = Maps.newConcurrentMap(); List<String> failNodes = Lists.newArrayList(); List<String> childrens = this.getBrokersChildren(); for (String child : childrens) { BrokerNode bb = this.getBrokerNodeData(child); if (!bb.isAlive() && bb.getMetas().size() > 0) { brokerNode.getMetas().addAll(bb.getMetas()); failNodes.add(child); } else if (bb.isAlive()) { nodes.put(child, bb); } } if (brokerNode.getMetas().size() > 0 && nodes.size() > 0) { int total = brokerNode.getMetas().size(); List<Map.Entry<String, BrokerNode>> entries = new LinkedList<Map.Entry<String, BrokerNode>>( nodes.entrySet()); Collections.sort(entries, new Comparator<Map.Entry<String, BrokerNode>>() { @Override public int compare(Map.Entry<String, BrokerNode> o1, Map.Entry<String, BrokerNode> o2) { return o1.getValue().getMetas().size() - o2.getValue().getMetas().size(); } }); for (Map.Entry<String, BrokerNode> entry : entries) { total = total + entry.getValue().getMetas().size(); } int avg = total / nodes.size(); int start = 0; int end = 0; int resultTotal = 0; for (Map.Entry<String, BrokerNode> entry : entries) { List<String> metas = entry.getValue().getMetas(); int msize = metas.size(); if (msize < avg) { end = end + (avg - msize); metas.addAll(brokerNode.getMetas().subList(start, end)); start = end; resultTotal = resultTotal + metas.size(); continue; } resultTotal = resultTotal + metas.size(); } if (total > resultTotal) { int c = total - resultTotal; int index = 0; for (Map.Entry<String, BrokerNode> entry : entries) { if (index < c) { end = end + 1; entry.getValue().getMetas().addAll(brokerNode.getMetas().subList(start, end)); start = end; index++; } } } for (Map.Entry<String, BrokerNode> entry : entries) { BrokerNode nodeSign = BrokerNode.initNullBrokerNode(); nodeSign.setMetas(entry.getValue().getMetas()); this.updateBrokerNodeNoLock(entry.getKey(), nodeSign); } for (String failNode : failNodes) { BrokerNode nodeSign = BrokerNode.initNullBrokerNode(); nodeSign.setMetas(new ArrayList<String>()); this.updateBrokerNodeNoLock(failNode, nodeSign); } result = true; } } catch (Exception e) { logger.error(ExceptionUtil.getErrorMessage(e)); } finally { if (this.updateNodelock.isAcquiredInThisProcess()) this.updateNodelock.release(); } return result; }
From source file:org.onosproject.vtnweb.resources.VirtualPortWebResource.java
/** * Returns a collection of virtualPorts. * * @param securityGroups the virtualPort jsonnode * @return a collection of securityGroups *///from ww w .ja va 2s. c om public Collection<SecurityGroup> jsonNodeToSecurityGroup(JsonNode securityGroups) { checkNotNull(securityGroups, JSON_NOT_NULL); ConcurrentMap<Integer, SecurityGroup> securMaps = Maps.newConcurrentMap(); int i = 0; for (JsonNode node : securityGroups) { SecurityGroup securityGroup = SecurityGroup.securityGroup(node.asText()); securMaps.put(i, securityGroup); i++; } return Collections.unmodifiableCollection(securMaps.values()); }
From source file:org.apache.drill.exec.expr.fn.registry.FunctionRegistryHolder.java
/** * Adds all function names and signatures to passed jar, * adds all function names, their signatures and holders to {@link #functions}. * * @param jar jar where function to be added * @param newFunctions collection of function holders, each contains function name, signature and holder. *///from w ww .jav a 2 s. c om private void addFunctions(Map<String, Queue<String>> jar, List<FunctionHolder> newFunctions) { for (FunctionHolder function : newFunctions) { final String functionName = function.getName(); Queue<String> jarFunctions = jar.get(functionName); if (jarFunctions == null) { jarFunctions = Queues.newConcurrentLinkedQueue(); ; jar.put(functionName, jarFunctions); } final String functionSignature = function.getSignature(); jarFunctions.add(functionSignature); Map<String, DrillFuncHolder> signatures = functions.get(functionName); if (signatures == null) { signatures = Maps.newConcurrentMap(); functions.put(functionName, signatures); } signatures.put(functionSignature, function.getHolder()); } }
From source file:org.apache.spark.network.shuffle.ExternalShuffleBlockResolver.java
@VisibleForTesting static ConcurrentMap<AppExecId, ExecutorShuffleInfo> reloadRegisteredExecutors(DB db) throws IOException { ConcurrentMap<AppExecId, ExecutorShuffleInfo> registeredExecutors = Maps.newConcurrentMap(); if (db != null) { DBIterator itr = db.iterator();/* w w w .jav a 2s . c o m*/ itr.seek(APP_KEY_PREFIX.getBytes(Charsets.UTF_8)); while (itr.hasNext()) { Map.Entry<byte[], byte[]> e = itr.next(); String key = new String(e.getKey(), Charsets.UTF_8); if (!key.startsWith(APP_KEY_PREFIX)) { break; } AppExecId id = parseDbAppExecKey(key); ExecutorShuffleInfo shuffleInfo = mapper.readValue(e.getValue(), ExecutorShuffleInfo.class); registeredExecutors.put(id, shuffleInfo); } } return registeredExecutors; }
From source file:org.onosproject.cpman.impl.ControlPlaneMonitor.java
/** * Converts metric map into a new map which contains string formatted metric type as key. * * @param metricMap metric map in which ControlMetricType is key * @return a new map in which string formatted metric type is key *//*from www .j ava2 s . c om*/ private Map<String, Double> convertMap(Map<ControlMetricType, Double> metricMap) { if (metricMap == null) { return ImmutableMap.of(); } Map newMap = Maps.newConcurrentMap(); metricMap.forEach((k, v) -> newMap.putIfAbsent(k.toString(), v)); return newMap; }