List of usage examples for com.google.common.collect Maps newConcurrentMap
public static <K, V> ConcurrentMap<K, V> newConcurrentMap()
From source file:com.quancheng.saluki.core.registry.internal.FailbackRegistry.java
@Override protected void notify(GrpcURL url, NotifyListener.NotifyServiceListener listener, List<GrpcURL> urls) { if (url == null) { throw new IllegalArgumentException("notify url == null"); }// www . ja va 2 s .c o m if (listener == null) { throw new IllegalArgumentException("notify listener == null"); } try { doNotify(url, listener, urls); } catch (Exception t) { // ? Map<NotifyListener.NotifyServiceListener, List<GrpcURL>> listeners = failedNotified.get(url); if (listeners == null) { failedNotified.putIfAbsent(url, Maps.newConcurrentMap()); listeners = failedNotified.get(url); } listeners.put(listener, urls); logger.error("Failed to notify for subscribe " + url + ", waiting for retry, cause: " + t.getMessage(), t); } }
From source file:com.google.gcloud.spi.DefaultStorageRpc.java
private BatchResponse batchChunk(BatchRequest request) { com.google.api.client.googleapis.batch.BatchRequest batch = storage.batch(); final Map<StorageObject, Tuple<Boolean, StorageException>> deletes = Maps.newConcurrentMap(); final Map<StorageObject, Tuple<StorageObject, StorageException>> updates = Maps.newConcurrentMap(); final Map<StorageObject, Tuple<StorageObject, StorageException>> gets = Maps.newConcurrentMap(); try {//from w ww . ja va 2 s. c om for (final Tuple<StorageObject, Map<Option, ?>> tuple : request.toDelete) { deleteRequest(tuple.x(), tuple.y()).queue(batch, new JsonBatchCallback<Void>() { @Override public void onSuccess(Void ignore, HttpHeaders responseHeaders) { deletes.put(tuple.x(), Tuple.<Boolean, StorageException>of(Boolean.TRUE, null)); } @Override public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) { if (e.getCode() == HTTP_NOT_FOUND) { deletes.put(tuple.x(), Tuple.<Boolean, StorageException>of(Boolean.FALSE, null)); } else { deletes.put(tuple.x(), Tuple.<Boolean, StorageException>of(null, translate(e))); } } }); } for (final Tuple<StorageObject, Map<Option, ?>> tuple : request.toUpdate) { patchRequest(tuple.x(), tuple.y()).queue(batch, new JsonBatchCallback<StorageObject>() { @Override public void onSuccess(StorageObject storageObject, HttpHeaders responseHeaders) { updates.put(tuple.x(), Tuple.<StorageObject, StorageException>of(storageObject, null)); } @Override public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) { updates.put(tuple.x(), Tuple.<StorageObject, StorageException>of(null, translate(e))); } }); } for (final Tuple<StorageObject, Map<Option, ?>> tuple : request.toGet) { getRequest(tuple.x(), tuple.y()).queue(batch, new JsonBatchCallback<StorageObject>() { @Override public void onSuccess(StorageObject storageObject, HttpHeaders responseHeaders) { gets.put(tuple.x(), Tuple.<StorageObject, StorageException>of(storageObject, null)); } @Override public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) { if (e.getCode() == HTTP_NOT_FOUND) { gets.put(tuple.x(), Tuple.<StorageObject, StorageException>of(null, null)); } else { gets.put(tuple.x(), Tuple.<StorageObject, StorageException>of(null, translate(e))); } } }); } batch.execute(); } catch (IOException ex) { throw translate(ex); } return new BatchResponse(deletes, updates, gets); }
From source file:org.onosproject.store.trivial.impl.SimpleDeviceStore.java
@Override public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> portStats) { ConcurrentMap<PortNumber, PortStatistics> statsMap = devicePortStats.get(deviceId); if (statsMap == null) { statsMap = Maps.newConcurrentMap(); devicePortStats.put(deviceId, statsMap); }/*from w w w . j a v a 2 s . co m*/ for (PortStatistics stat : portStats) { PortNumber portNumber = PortNumber.portNumber(stat.port()); statsMap.put(portNumber, stat); } return new DeviceEvent(PORT_STATS_UPDATED, devices.get(deviceId), null); }
From source file:org.onosproject.store.trivial.SimpleDeviceStore.java
@Override public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> newStatsCollection) { ConcurrentMap<PortNumber, PortStatistics> prvStatsMap = devicePortStats.get(deviceId); ConcurrentMap<PortNumber, PortStatistics> newStatsMap = Maps.newConcurrentMap(); ConcurrentMap<PortNumber, PortStatistics> deltaStatsMap = Maps.newConcurrentMap(); if (prvStatsMap != null) { for (PortStatistics newStats : newStatsCollection) { PortNumber port = PortNumber.portNumber(newStats.port()); PortStatistics prvStats = prvStatsMap.get(port); DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder(); PortStatistics deltaStats = builder.build(); if (prvStats != null) { deltaStats = calcDeltaStats(deviceId, prvStats, newStats); }/* www .j a v a 2 s .c o m*/ deltaStatsMap.put(port, deltaStats); newStatsMap.put(port, newStats); } } else { for (PortStatistics newStats : newStatsCollection) { PortNumber port = PortNumber.portNumber(newStats.port()); newStatsMap.put(port, newStats); } } devicePortDeltaStats.put(deviceId, deltaStatsMap); devicePortStats.put(deviceId, newStatsMap); return new DeviceEvent(PORT_STATS_UPDATED, devices.get(deviceId), null); }
From source file:org.opendaylight.nic.common.transaction.utils.CommonUtils.java
public Map<Ipv4Address, BgpDataflow> createBGPDataFlow(final IntentIspPrefix intent) throws IntentInvalidException { final EthernetService ethernetService = retrieveEthernetServiceBy(intent.getIspName()); final Map<Ipv4Address, BgpDataflow> bgpDataflowByPeerIp = Maps.newConcurrentMap(); retrieveRouterInfosByRouterGroup(ethernetService.getRouterGroupId().getValue()).forEach(routerInfo -> { BgpDataflowBuilder dataflowBuilder = new BgpDataflowBuilder(); dataflowBuilder.setId(intent.getId()); dataflowBuilder.setOriginatorIp(Ipv4Address.getDefaultInstance(routerInfo.getServicePeerIp())); dataflowBuilder.setPrefix(intent.getPrefix()); dataflowBuilder.setGlobalIp(Ipv4Address.getDefaultInstance(routerInfo.getServicePeerIp())); dataflowBuilder.setPathId(routerInfo.getPeerPathId()); final List<AsNumbers> asNumbers = Lists.newArrayList(); final AsNumbersBuilder asNumbersBuilder = new AsNumbersBuilder(); asNumbersBuilder.setAsNumber(AsNumber.getDefaultInstance(routerInfo.getAsn().toString())); asNumbers.add(asNumbersBuilder.build()); dataflowBuilder.setAsNumbers(asNumbers); bgpDataflowByPeerIp.put(Ipv4Address.getDefaultInstance(routerInfo.getServicePeerIp()), dataflowBuilder.build()); });// w ww. jav a 2 s . c o m return bgpDataflowByPeerIp; }
From source file:gobblin.compaction.mapreduce.MRCompactor.java
public MRCompactor(Properties props, List<? extends Tag<?>> tags, Optional<CompactorListener> compactorListener) throws IOException { this.state = new State(); this.state.addAll(props); this.initilizeTime = getCurrentTime(); this.tags = tags; this.conf = HadoopUtils.getConfFromState(this.state); this.tmpOutputDir = getTmpOutputDir(); this.fs = getFileSystem(); this.datasets = getDatasetsFinder().findDistinctDatasets(); this.jobExecutor = createJobExecutor(); this.jobRunnables = Maps.newConcurrentMap(); this.closer = Closer.create(); this.stopwatch = Stopwatch.createStarted(); this.gobblinMetrics = initializeMetrics(); this.eventSubmitter = new EventSubmitter.Builder( GobblinMetrics.get(this.state.getProp(ConfigurationKeys.JOB_NAME_KEY)).getMetricContext(), MRCompactor.COMPACTION_TRACKING_EVENTS_NAMESPACE).build(); this.compactorListener = compactorListener; this.dataVerifTimeoutMinutes = getDataVerifTimeoutMinutes(); this.compactionTimeoutMinutes = getCompactionTimeoutMinutes(); this.shouldVerifDataCompl = shouldVerifyDataCompleteness(); this.compactionCompleteListener = getCompactionCompleteListener(); this.verifier = this.shouldVerifDataCompl ? Optional.of(this.closer.register(new DataCompletenessVerifier(this.state))) : Optional.<DataCompletenessVerifier>absent(); this.shouldPublishDataIfCannotVerifyCompl = shouldPublishDataIfCannotVerifyCompl(); }
From source file:com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.java
void prepareForExecution(Reporter reporter, Executor executor, boolean keepGoing, boolean explain, ActionCacheChecker actionCacheChecker, OutputService outputService) { this.reporter = Preconditions.checkNotNull(reporter); this.executorEngine = Preconditions.checkNotNull(executor); // Start with a new map each build so there's no issue with internal resizing. this.buildActionMap = Maps.newConcurrentMap(); this.keepGoing = keepGoing; this.hadExecutionError = false; this.actionCacheChecker = Preconditions.checkNotNull(actionCacheChecker); // Don't cache possibly stale data from the last build. this.explain = explain; this.outputService = outputService; }
From source file:org.onosproject.store.device.impl.ECDeviceStore.java
private List<DeviceEvent> refreshDevicePortCache(ProviderId providerId, DeviceId deviceId, Optional<PortNumber> portNumber) { Device device = devices.get(deviceId); checkArgument(device != null, DEVICE_NOT_FOUND, deviceId); List<DeviceEvent> events = Lists.newArrayList(); Map<PortNumber, Port> ports = devicePorts.computeIfAbsent(deviceId, key -> Maps.newConcurrentMap()); List<PortDescription> descriptions = Lists.newArrayList(); portDescriptions.entrySet().forEach(e -> { PortKey key = e.getKey();/*from www . j ava2 s .com*/ PortDescription value = e.getValue(); if (key.deviceId().equals(deviceId) && key.providerId().equals(providerId)) { if (portNumber.isPresent()) { if (portNumber.get().equals(key.portNumber())) { descriptions.add(value); } } else { descriptions.add(value); } } }); for (PortDescription description : descriptions) { final PortNumber number = description.portNumber(); ports.compute(number, (k, existingPort) -> { Port newPort = composePort(device, number); if (existingPort == null) { events.add(new DeviceEvent(PORT_ADDED, device, newPort)); } else { if (existingPort.isEnabled() != newPort.isEnabled() || existingPort.type() != newPort.type() || existingPort.portSpeed() != newPort.portSpeed() || !AnnotationsUtil.isEqual(existingPort.annotations(), newPort.annotations())) { events.add(new DeviceEvent(PORT_UPDATED, device, newPort)); } } return newPort; }); } return events; }
From source file:com.dtstack.jlogstash.distributed.ZkDistributed.java
public boolean upReblance() throws Exception { boolean result = false; List<String> childrens = this.getBrokersChildren(); for (String child : childrens) { BrokerNode brokerNode = this.getBrokerNodeData(child); if (brokerNode.isAlive() && brokerNode.getMetas().size() == 0) { result = true;/*from w w w . jav a 2 s . c o m*/ break; } } if (result) { try { this.updateNodelock.acquire(30, TimeUnit.SECONDS); List<String> noneNode = Lists.newArrayList(); List<String> allNode = Lists.newArrayList(); List<String> nodes = Lists.newArrayList(); Map<String, BrokerNode> mnodes = Maps.newConcurrentMap(); for (String child : childrens) { BrokerNode brokerNode = this.getBrokerNodeData(child); if (brokerNode.isAlive()) { if (brokerNode.getMetas().size() > 0) { nodes.addAll(brokerNode.getMetas()); } else { noneNode.add(child); } allNode.add(child); } } int avg = nodes.size() / allNode.size(); int yu = nodes.size() % allNode.size(); int start = 0; int end = 0; if (noneNode.size() > 0) { for (int i = 0; i < allNode.size(); i++) { if (i == allNode.size() - 1) { end = end + yu; } else { end = end + avg; } BrokerNode brokerNode = BrokerNode.initNullBrokerNode(); brokerNode.setMetas(nodes.subList(start, end)); mnodes.put(allNode.get(i), brokerNode); start = end; } for (Map.Entry<String, BrokerNode> entry : mnodes.entrySet()) { this.updateBrokerNodeNoLock(entry.getKey(), entry.getValue()); } 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.RouterWebResource.java
/** * Changes JsonNode fixedIp to a collection of the fixedIp. * * @param fixedIp the allocationPools JsonNode * @return a collection of fixedIp/*from ww w. j av a 2 s.c om*/ */ private Iterable<FixedIp> jsonNodeToFixedIp(JsonNode fixedIp) { checkNotNull(fixedIp, JSON_NOT_NULL); ConcurrentMap<Integer, FixedIp> fixedIpMaps = Maps.newConcurrentMap(); Integer i = 0; for (JsonNode node : fixedIp) { if (!node.hasNonNull("subnet_id")) { throw new IllegalArgumentException("subnet_id should not be null"); } else if (node.get("subnet_id").asText().isEmpty()) { throw new IllegalArgumentException("subnet_id should not be empty"); } SubnetId subnetId = SubnetId.subnetId(node.get("subnet_id").asText()); if (!node.hasNonNull("ip_address")) { throw new IllegalArgumentException("ip_address should not be null"); } else if (node.get("ip_address").asText().isEmpty()) { throw new IllegalArgumentException("ip_address should not be empty"); } IpAddress ipAddress = IpAddress.valueOf(node.get("ip_address").asText()); FixedIp fixedIpObj = FixedIp.fixedIp(subnetId, ipAddress); fixedIpMaps.putIfAbsent(i, fixedIpObj); i++; } return Collections.unmodifiableCollection(fixedIpMaps.values()); }