List of usage examples for com.google.common.collect ImmutableMap getOrDefault
default V getOrDefault(Object key, V defaultValue)
From source file:com.facebook.buck.remoteexecution.event.listener.RemoteExecutionConsoleLineProvider.java
private static String getStatesString(ImmutableMap<State, Integer> actionsPerState) { List<String> states = Lists.newArrayList(); for (State state : RemoteExecutionActionEvent.State.values()) { String stateName = state.getAbbreviateName(); Integer stateValue = actionsPerState.getOrDefault(state, 0); states.add(String.format("%s=%d", stateName, stateValue)); }/*www.j a v a 2s . c om*/ return Joiner.on(" ").join(states); }
From source file:io.awacs.server.Configurations.java
public static List<String> exportServerAddr(Configuration configuration) { ImmutableMap<String, String> map = configuration.getSubProperties(SERVER_PREFIX + "."); Set<String> serverNames = map.keySet().stream().map(key -> key.substring(0, key.indexOf("."))) .collect(Collectors.toSet()); List<String> addrs = new ArrayList<>(serverNames.size()); addrs.addAll(serverNames.stream()/*from w ww .ja va2 s . c om*/ .map(serverName -> map.getOrDefault(serverName + "." + TCP_BIND_HOST, DEFAULT_TCP_BIND_HOST) + ":" + map.getOrDefault(serverName + "." + TCP_BIND_PORT, DEFAULT_TCP_BIND_PORT)) .collect(Collectors.toList())); return addrs; }
From source file:com.facebook.buck.remoteexecution.event.listener.RemoteExecutionConsoleLineProvider.java
private int getLocallyBuiltRules(int totalBuildRules, ImmutableMap<State, Integer> actionsPerState) { int remotelyExecutedBuildRules = actionsPerState.getOrDefault(State.ACTION_SUCCEEDED, 0) + actionsPerState.getOrDefault(State.ACTION_FAILED, 0); return Math.max(0, totalBuildRules - remotelyExecutedBuildRules); }
From source file:io.awacs.server.MessageReportServer.java
@Override public void init(Configuration configuration) throws InitializationException { String serverName = configuration.getString(Configurations.SERVER_PREFIX); ImmutableMap<String, String> serverConfig = configuration .getSubProperties(Configurations.SERVER_PREFIX + "." + serverName + "."); host = serverConfig.getOrDefault(Configurations.TCP_BIND_HOST, Configurations.DEFAULT_TCP_BIND_HOST); port = Integer.parseInt(/* w w w . j av a2 s.c o m*/ serverConfig.getOrDefault(Configurations.TCP_BIND_PORT, Configurations.DEFAULT_TCP_BIND_PORT)); int bossCore = Integer.parseInt( serverConfig.getOrDefault(Configurations.TCP_BOSS_CORE, Configurations.DEFAULT_TCP_BOSS_CORE)); int workerCore = Integer.parseInt( serverConfig.getOrDefault(Configurations.TCP_WORKER_CORE, Configurations.DEFAULT_TCP_WORKER_CORE)); boss = new NioEventLoopGroup(bossCore); worker = new NioEventLoopGroup(workerCore); }
From source file:io.awacs.server.StaticResourceServer.java
@Override public void init(Configuration configuration) throws InitializationException { String serverName = configuration.getString(Configurations.SERVER_PREFIX); ImmutableMap<String, String> serverConfig = configuration .getSubProperties(Configurations.SERVER_PREFIX + "." + serverName + "."); host = serverConfig.getOrDefault(Configurations.HTTP_BIND_HOST, Configurations.DEFAULT_HTTP_BIND_HOST); port = Integer.parseInt(//ww w . ja v a2 s.com serverConfig.getOrDefault(Configurations.HTTP_BIND_PORT, Configurations.DEFAULT_HTTP_BIND_PORT)); int bossCore = Integer.parseInt( serverConfig.getOrDefault(Configurations.HTTP_BOSS_CORE, Configurations.DEFAULT_HTTP_BOSS_CORE)); int workerCore = Integer.parseInt(serverConfig.getOrDefault(Configurations.HTTP_WORKER_CORE, Configurations.DEFAULT_HTTP_WORKER_CORE)); boss = new NioEventLoopGroup(bossCore); worker = new NioEventLoopGroup(workerCore); }
From source file:com.srotya.flume.kinesis.source.KinesisSource.java
@Override protected void doConfigure(Context ctx) throws FlumeException { ImmutableMap<String, String> props = ctx.getSubProperties(Constants.SETTINGS); if (!props.containsKey(Constants.ACCESS_KEY) || !props.containsKey(Constants.ACCESS_SECRET)) { Throwables.propagate(/* w w w. jav a 2 s . com*/ new InvalidArgumentException("Must provide AWS credentials i.e. accessKey and accessSecret")); } awsCredentials = new BasicAWSCredentials(props.get(Constants.ACCESS_KEY), props.get(Constants.ACCESS_SECRET)); clientConfig = new ClientConfiguration(); if (props.containsKey(Constants.PROXY_HOST)) { clientConfig.setProxyHost(props.get(Constants.PROXY_HOST)); clientConfig.setProxyPort(Integer.parseInt(props.getOrDefault(Constants.PROXY_PORT, "80"))); clientConfig.setProtocol(Protocol.valueOf(props.getOrDefault(Constants.PROTOCOL, "HTTPS"))); } if (!props.containsKey(Constants.STREAM_NAME)) { Throwables.propagate(new InvalidArgumentException("Must provide Kinesis stream name")); } streamName = props.get(Constants.STREAM_NAME); putSize = Integer.parseInt(props.getOrDefault(Constants.PUT_SIZE, "100")); if (putSize > 500) { Throwables.propagate( new InvalidArgumentException("AWS Kinesis doesn't allow more than 500 put requests")); } endpoint = props.getOrDefault(Constants.ENDPOINT, Constants.DEFAULT_ENDPOINT); String serializerClass = props.getOrDefault(Constants.SERIALIZER, GsonSerializer.class.getName()); try { serializer = (KinesisSerializer) Class.forName(serializerClass).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { Throwables.propagate(e); } serializer.configure(props); shardId = Integer.parseInt(props.getOrDefault(SHARD_INDEX, "0")); shardIteratorType = props.getOrDefault(ITERATOR_TYPE, DEFAULT_ITERATOR_TYPE); }
From source file:com.srotya.flume.kinesis.sink.KinesisSink.java
@Override public void configure(Context ctx) { ImmutableMap<String, String> props = ctx.getSubProperties(Constants.SETTINGS); if (!props.containsKey(Constants.ACCESS_KEY) || !props.containsKey(Constants.ACCESS_SECRET)) { Throwables.propagate(/*from ww w . j a v a 2 s . co m*/ new InvalidArgumentException("Must provide AWS credentials i.e. accessKey and accessSecret")); } awsCredentials = new BasicAWSCredentials(props.get(Constants.ACCESS_KEY), props.get(Constants.ACCESS_SECRET)); clientConfig = new ClientConfiguration(); if (props.containsKey(Constants.PROXY_HOST)) { clientConfig.setProxyHost(props.get(Constants.PROXY_HOST)); clientConfig.setProxyPort(Integer.parseInt(props.getOrDefault(Constants.PROXY_PORT, "80"))); clientConfig.setProtocol(Protocol.valueOf(props.getOrDefault(Constants.PROTOCOL, "HTTPS"))); } if (!props.containsKey(Constants.STREAM_NAME)) { Throwables.propagate(new InvalidArgumentException("Must provide Kinesis stream name")); } streamName = props.get(Constants.STREAM_NAME); putSize = Integer.parseInt(props.getOrDefault(Constants.PUT_SIZE, "100")); if (putSize > 500) { Throwables.propagate( new InvalidArgumentException("AWS Kinesis doesn't allow more than 500 put requests")); } endpoint = props.getOrDefault(Constants.ENDPOINT, Constants.DEFAULT_ENDPOINT); String serializerClass = props.getOrDefault(Constants.SERIALIZER, GsonSerializer.class.getName()); try { serializer = (KinesisSerializer) Class.forName(serializerClass).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { Throwables.propagate(e); } serializer.configure(props); }
From source file:com.facebook.buck.command.config.AbstractConfigIgnoredByDaemon.java
@Value.Lazy public ImmutableMap<String, ImmutableMap<String, String>> getRawConfigForParser() { ImmutableMap<String, ImmutableSet<String>> ignoredFields = getIgnoreFieldsForDaemonRestart(); ImmutableMap<String, ImmutableMap<String, String>> rawSections = getDelegate().getConfig() .getSectionToEntries();/* www . j a v a 2 s. co m*/ // If the raw config doesn't have sections which have ignored fields, then just return it as-is. ImmutableSet<String> sectionsWithIgnoredFields = ignoredFields.keySet(); if (Sets.intersection(rawSections.keySet(), sectionsWithIgnoredFields).isEmpty()) { return rawSections; } // Otherwise, iterate through the config to do finer-grain filtering. ImmutableMap.Builder<String, ImmutableMap<String, String>> filtered = ImmutableMap.builder(); for (Map.Entry<String, ImmutableMap<String, String>> sectionEnt : rawSections.entrySet()) { String sectionName = sectionEnt.getKey(); // If this section doesn't have a corresponding ignored section, then just add it as-is. if (!sectionsWithIgnoredFields.contains(sectionName)) { filtered.put(sectionEnt); continue; } // If none of this section's entries are ignored, then add it as-is. ImmutableMap<String, String> fields = sectionEnt.getValue(); ImmutableSet<String> ignoredFieldNames = ignoredFields.getOrDefault(sectionName, ImmutableSet.of()); if (Sets.intersection(fields.keySet(), ignoredFieldNames).isEmpty()) { filtered.put(sectionEnt); continue; } // Otherwise, filter out the ignored fields. ImmutableMap<String, String> remainingKeys = ImmutableMap .copyOf(Maps.filterKeys(fields, Predicates.not(ignoredFieldNames::contains))); filtered.put(sectionName, remainingKeys); } return MoreMaps.filterValues(filtered.build(), Predicates.not(Map::isEmpty)); }
From source file:io.druid.query.materializedview.DataSourceOptimizer.java
public List<DataSourceOptimizerStats> getAndResetStats() { ImmutableMap<String, AtomicLong> derivativesHitCountSnapshot; ImmutableMap<String, AtomicLong> totalCountSnapshot; ImmutableMap<String, AtomicLong> hitCountSnapshot; ImmutableMap<String, AtomicLong> costTimeSnapshot; ImmutableMap<String, ConcurrentHashMap<Set<String>, AtomicLong>> missFieldsSnapshot; lock.writeLock().lock();//from w w w . ja va 2s . com try { derivativesHitCountSnapshot = ImmutableMap.copyOf(derivativesHitCount); totalCountSnapshot = ImmutableMap.copyOf(totalCount); hitCountSnapshot = ImmutableMap.copyOf(hitCount); costTimeSnapshot = ImmutableMap.copyOf(costTime); missFieldsSnapshot = ImmutableMap.copyOf(missFields); derivativesHitCount.clear(); totalCount.clear(); hitCount.clear(); costTime.clear(); missFields.clear(); } finally { lock.writeLock().unlock(); } List<DataSourceOptimizerStats> stats = Lists.newArrayList(); Map<String, Set<DerivativeDataSource>> baseToDerivatives = DerivativeDataSourceManager.getAllDerivatives(); for (Map.Entry<String, Set<DerivativeDataSource>> entry : baseToDerivatives.entrySet()) { Map<String, Long> derivativesStat = Maps.newHashMap(); for (DerivativeDataSource derivative : entry.getValue()) { derivativesStat.put(derivative.getName(), derivativesHitCountSnapshot.getOrDefault(derivative.getName(), new AtomicLong(0)).get()); } stats.add(new DataSourceOptimizerStats(entry.getKey(), hitCountSnapshot.getOrDefault(entry.getKey(), new AtomicLong(0)).get(), totalCountSnapshot.getOrDefault(entry.getKey(), new AtomicLong(0)).get(), costTimeSnapshot.getOrDefault(entry.getKey(), new AtomicLong(0)).get(), missFieldsSnapshot.getOrDefault(entry.getKey(), new ConcurrentHashMap<>()), derivativesStat)); } return stats; }
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
@VisibleForTesting static FluentIterable<TargetNode<?>> swapSharedLibrariesForBundles(FluentIterable<TargetNode<?>> targetDeps, ImmutableMap<BuildTarget, TargetNode<?>> sharedLibrariesToBundles) { return targetDeps.transform(t -> sharedLibrariesToBundles.getOrDefault(t.getBuildTarget(), t)); }