List of usage examples for com.google.common.collect Maps newConcurrentMap
public static <K, V> ConcurrentMap<K, V> newConcurrentMap()
From source file:org.lanternpowered.server.inject.impl.SimpleModule.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public SimpleModule(List<Binding<?>> bindings, Map<Class<?>, Supplier<?>> suppliers, List<MethodSpec<?>> methodBindings) { Map<Class<?>, List<Binding<?>>> map = Maps.newConcurrentMap(); for (Binding<?> binding : bindings) { map.computeIfAbsent(binding.getParameterSpec().getType(), type -> Lists.newCopyOnWriteArrayList()) .add(binding);/*from ww w.j a v a2 s . c o m*/ } this.methodBindings = ImmutableList.copyOf(methodBindings); this.bindings = (Map) ImmutableMap.copyOf(Maps.transformValues(map, ImmutableList::copyOf)); this.suppliers = ImmutableMap.copyOf(suppliers); }
From source file:org.onosproject.mapping.impl.SimpleMappingStore.java
/** * Obtains the mapping store for specified device and store type. * * @param type mapping store type//from w w w .j a va 2s . c o m * @param deviceId device identifier * @return Map representing Mapping Store of given device and store type */ private ConcurrentMap<MappingId, List<StoredMappingEntry>> getMappingStoreByDeviceId(Type type, DeviceId deviceId) { switch (type) { case MAP_DATABASE: return mapDbStore.computeIfAbsent(deviceId, k -> Maps.newConcurrentMap()); case MAP_CACHE: return mapCacheStore.computeIfAbsent(deviceId, k -> Maps.newConcurrentMap()); default: log.error(UNRECOGNIZED_STORE_MSG, type); return null; } }
From source file:com.arpnetworking.tsdcore.tailer.FilePositionStore.java
private FilePositionStore(final Builder builder) { _file = builder._file;/* w w w . ja va 2 s . com*/ _flushInterval = builder._flushInterval; _flushThreshold = builder._flushThreshold.longValue(); _retention = builder._retention; ConcurrentMap<String, Descriptor> state = Maps.newConcurrentMap(); try { state = OBJECT_MAPPER.readValue(_file, STATE_MAP_TYPE_REFERENCE); } catch (final IOException e) { LOGGER.warn(String.format("Unable to load state; file=%s", _file), e); } _state = state; }
From source file:org.apache.giraph.comm.messages.DiskBackedOnlineComputeMessageStoreByPartition.java
/** * @param service//from ww w . j a va 2s.c o m * Service worker * @param maxSizeOfMessagesInMemory * Number of messages to keep in memory * @param fileStoreFactory * Factory for creating file stores when flushing */ public DiskBackedOnlineComputeMessageStoreByPartition(CentralizedServiceWorker<I, V, E, M> service, int maxSizeOfMessagesInMemory, MessageStoreFactory<I, M, FlushableMessageStore<I, M>> fileStoreFactory) { this.service = service; this.maxSizeOfMessagesInMemory = maxSizeOfMessagesInMemory; this.fileStoreFactory = fileStoreFactory; partitionMessageStores = Maps.newConcurrentMap(); conf = ((BspServiceWorker) service).getConfiguration(); useOnlineCompute = conf.useHotPartition(); }
From source file:kr.ac.postech.lispconfig.LispConfigManager.java
@Activate protected void activate(ComponentContext context) { this.context = context; mapResolverMap = Maps.newConcurrentMap(); eidDbMap = Maps.newConcurrentMap();//w ww. ja v a2 s . co m log.info("Started"); }
From source file:com.android.ide.common.blame.MergingLogPersistUtil.java
@NonNull static Map<SourceFile, Map<SourcePosition, SourceFilePosition>> loadFromMultiFile(@NonNull File folder, @NonNull String shard) {//from w w w .j a va2s.co m Map<SourceFile, Map<SourcePosition, SourceFilePosition>> map = Maps.newConcurrentMap(); JsonReader reader; File file = getMultiFile(folder, shard); if (!file.exists()) { return map; } try { reader = new JsonReader(Files.newReader(file, Charsets.UTF_8)); } catch (FileNotFoundException e) { // Shouldn't happen unless it disappears under us. return map; } try { reader.beginArray(); while (reader.peek() != JsonToken.END_ARRAY) { reader.beginObject(); SourceFile toFile = SourceFile.UNKNOWN; Map<SourcePosition, SourceFilePosition> innerMap = Maps.newLinkedHashMap(); while (reader.peek() != JsonToken.END_OBJECT) { final String name = reader.nextName(); if (name.equals(KEY_OUTPUT_FILE)) { toFile = mSourceFileJsonTypeAdapter.read(reader); } else if (name.equals(KEY_MAP)) { reader.beginArray(); while (reader.peek() != JsonToken.END_ARRAY) { reader.beginObject(); SourceFilePosition from = null; SourcePosition to = null; while (reader.peek() != JsonToken.END_OBJECT) { final String innerName = reader.nextName(); if (innerName.equals(KEY_FROM)) { from = mSourceFilePositionJsonTypeAdapter.read(reader); } else if (innerName.equals(KEY_TO)) { to = mSourcePositionJsonTypeAdapter.read(reader); } else { throw new IOException(String.format("Unexpected property: %s", innerName)); } } if (from == null || to == null) { throw new IOException("Each record must contain both from and to."); } innerMap.put(to, from); reader.endObject(); } reader.endArray(); } else { throw new IOException(String.format("Unexpected property: %s", name)); } } map.put(toFile, innerMap); reader.endObject(); } reader.endArray(); return map; } catch (IOException e) { // TODO: trigger a non-incremental merge if this happens. throw new RuntimeException(e); } finally { try { reader.close(); } catch (Throwable e2) { // well, we tried. } } }
From source file:org.zanata.security.oauth.SecurityTokens.java
String getAuthorizationCode(String username, String clientId) throws OAuthSystemException { Map<String, String> clientIdToAuthCode = authorizationCodesByUsername.getIfPresent(username); if (clientIdToAuthCode != null && clientIdToAuthCode.containsKey(clientId)) { return clientIdToAuthCode.get(clientId); }// w w w . jav a2 s. c o m String authorizationCode = oAuthIssuer.authorizationCode(); try { authorizationCodesByUsername.get(username, () -> { ConcurrentMap<String, String> map = Maps.newConcurrentMap(); map.put(clientId, authorizationCode); return map; }); } catch (ExecutionException e) { throw new RuntimeException(e); } return authorizationCode; }
From source file:org.onosproject.incubator.net.virtual.impl.provider.DefaultVirtualPacketProvider.java
@Activate public void activate() { appId = coreService.registerApplication("org.onosproject.virtual.virtual-packet"); providerRegistryService.registerProvider(this); contextMap = Maps.newConcurrentMap(); log.info("Started"); }
From source file:gobblin.service.modules.flow.IdentityFlowToJobSpecCompiler.java
public IdentityFlowToJobSpecCompiler(Config config, Optional<Logger> log, boolean instrumentationEnabled) { this.log = log.isPresent() ? log.get() : LoggerFactory.getLogger(getClass()); if (instrumentationEnabled) { this.metricContext = Instrumented.getMetricContext(ConfigUtils.configToState(config), IdentityFlowToJobSpecCompiler.class); this.flowCompilationSuccessFulMeter = Optional .of(this.metricContext.meter(ServiceMetricNames.FLOW_COMPILATION_SUCCESSFUL_METER)); this.flowCompilationFailedMeter = Optional .of(this.metricContext.meter(ServiceMetricNames.FLOW_COMPILATION_FAILED_METER)); this.flowCompilationTimer = Optional .<Timer>of(this.metricContext.timer(ServiceMetricNames.FLOW_COMPILATION_TIMER)); } else {/*from w w w . j a v a 2 s .co m*/ this.metricContext = null; this.flowCompilationSuccessFulMeter = Optional.absent(); this.flowCompilationFailedMeter = Optional.absent(); this.flowCompilationTimer = Optional.absent(); } this.topologySpecMap = Maps.newConcurrentMap(); this.config = config; /*** * For multi-tenancy, the following needs to be added: * 1. Change singular templateCatalog to Map<URI, JobCatalogWithTemplates> to support multiple templateCatalogs * 2. Pick templateCatalog from JobCatalogWithTemplates based on URI, and try to resolve JobSpec using that */ try { if (this.config.hasPath(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY) && StringUtils.isNotBlank( this.config.getString(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY))) { Config templateCatalogCfg = config.withValue(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, this.config.getValue(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY)); this.templateCatalog = Optional.of(new FSJobCatalog(templateCatalogCfg)); } else { this.templateCatalog = Optional.absent(); } } catch (IOException e) { throw new RuntimeException("Could not initialize IdentityFlowToJobSpecCompiler because of " + "TemplateCatalog initialization failure", e); } }
From source file:com.pinterest.terrapin.client.FileSetViewManager.java
FileSetViewManager(String clusterName) { this.clusterName = clusterName; this.fileSetInfoBackupMap = Maps.newConcurrentMap(); this.zkBackedFileSetInfoMap = Maps.newHashMap(); this.zkBackedViewInfoMap = Maps.newHashMap(); }