List of usage examples for com.google.common.collect Multimap asMap
Map<K, Collection<V>> asMap();
From source file:org.jclouds.openstack.nova.v2_0.compute.NovaComputeService.java
@Override protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) { Multimap<String, String> zoneToZoneAndGroupNames = orphanedGroupsByZoneId.apply(deadNodes); for (Map.Entry<String, Collection<String>> entry : zoneToZoneAndGroupNames.asMap().entrySet()) { cleanOrphanedGroupsInZone(ImmutableSet.copyOf(entry.getValue()), entry.getKey()); }/*from w w w . ja v a 2 s. c om*/ }
From source file:com.gwtplatform.processors.tools.bindings.gin.GinModuleProcessor.java
private void outputModule(Type moduleType) { logger.debug("Generating GIN module `%s`.", moduleType.getQualifiedName()); FileObject fileObject = sourceFiles.get(moduleType); Multimap<Type, GinBinding> setBindings = setBinders.get(moduleType); Set<Entry<Type, Collection<GinBinding>>> setBindingsEntries = setBindings == null ? new HashSet<>() : setBindings.asMap().entrySet(); outputter.configure(TEMPLATE).withParam("bindings", bindings.get(moduleType)) .withParam("setBindings", setBindingsEntries).withParam("subModules", subModules.get(moduleType)) .writeTo(moduleType, fileObject); }
From source file:com.github.cbismuth.fdupes.report.DuplicatesCsvReporter.java
public Path report(final Multimap<PathElement, PathElement> duplicates) throws IOException { final Path output = Paths.get(System.getProperty("user.dir"), "report.csv"); try (CSVWriter writer = new CSVWriter(new FileWriter(output.toFile(), false))) { duplicates.asMap().entrySet().forEach(reportEntry(writer)); }/*from w w w . j a va2s. co m*/ return output; }
From source file:de.anycook.db.mysql.DBRecommend.java
public Map<String, Collection<String>> getRecipesByTags(int userId) throws SQLException { CallableStatement call = connection.prepareCall("{call recipes_from_schmeckttags(?)}"); call.setInt(1, userId);/* w w w .j av a 2 s . co m*/ ResultSet data = call.executeQuery(); Multimap<String, String> recipes = HashMultimap.create(); while (data.next()) { String recipe = data.getString("gerichte_name"); String tag = data.getString("tags_name"); recipes.put(recipe, tag); } return recipes.asMap(); }
From source file:org.sonar.ce.notification.ReportAnalysisFailureNotificationDispatcher.java
@Override public void dispatch(Notification notification, Context context) { String projectKey = notification.getFieldValue("project.key"); Multimap<String, NotificationChannel> subscribedRecipients = manager .findSubscribedRecipientsForDispatcher(this, projectKey, REQUIRED_SUBSCRIBER_PERMISSIONS); for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap() .entrySet()) {//from ww w . ja v a 2s. c om String userLogin = channelsByRecipients.getKey(); for (NotificationChannel channel : channelsByRecipients.getValue()) { context.addUser(userLogin, channel); } } }
From source file:com.facebook.buck.util.FakeListeningProcessExecutor.java
public FakeListeningProcessExecutor(Multimap<ProcessExecutorParams, FakeListeningProcessState> processStates) { this(Functions.forMap(processStates.asMap()), new SettableFakeClock(0, 0)); }
From source file:io.airlift.event.client.EventFieldMetadata.java
private void writeMultimap(JsonGenerator jsonGenerator, Multimap<?, ?> value, Deque<Object> objectStack) throws IOException { jsonGenerator.writeStartObject();// w w w .j a v a 2s .c om for (Map.Entry<?, ? extends Collection<?>> entry : value.asMap().entrySet()) { jsonGenerator.writeFieldName((String) entry.getKey()); writeArray(jsonGenerator, entry.getValue(), objectStack); } jsonGenerator.writeEndObject(); }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CQLKeyValueServices.java
public static void waitForSchemaVersionsToCoalesce(String encapsulatingOperationDescription, CQLKeyValueService kvs) {/*from w w w. java2 s .co m*/ PreparedStatement peerInfoQuery = kvs.getPreparedStatement(CassandraConstants.NO_TABLE, "select peer, schema_version from system.peers;", kvs.session); peerInfoQuery.setConsistencyLevel(ConsistencyLevel.ALL); Multimap<UUID, InetAddress> peerInfo = ArrayListMultimap.create(); long start = System.currentTimeMillis(); long sleepTime = 100; do { peerInfo.clear(); for (Row row : kvs.session.execute(peerInfoQuery.bind()).all()) { peerInfo.put(row.getUUID("schema_version"), row.getInet("peer")); } if (peerInfo.keySet().size() <= 1) { // full schema agreement return; } sleepTime = Math.min(sleepTime * 2, 5000); } while (System.currentTimeMillis() < start + CassandraConstants.SECONDS_WAIT_FOR_VERSIONS * 1000); StringBuilder sb = new StringBuilder(); sb.append(String.format( "Cassandra cluster cannot come to agreement on schema versions, during operation: %s.", encapsulatingOperationDescription)); for (Entry<UUID, Collection<InetAddress>> versionToPeer : peerInfo.asMap().entrySet()) { sb.append(String.format("\nAt schema version %s:", versionToPeer.getKey())); for (InetAddress peer : versionToPeer.getValue()) { sb.append(String.format("\n\tNode: %s", peer)); } } sb.append("\nFind the nodes above that diverge from the majority schema " + "(or have schema 'UNKNOWN', which likely means they are down/unresponsive) " + "and examine their logs to determine the issue. Fixing the underlying issue and restarting Cassandra " + "should resolve the problem. You can quick-check this with 'nodetool describecluster'."); throw new IllegalStateException(sb.toString()); }
From source file:org.wso2.msf4j.internal.router.BasicHttpResponder.java
private void setCustomHeaders(HttpResponse response, @Nullable Multimap<String, String> headers) { // Add headers. They will override all headers set by the framework if (headers != null) { for (Map.Entry<String, Collection<String>> entry : headers.asMap().entrySet()) { response.headers().add(entry.getKey(), entry.getValue()); }/* w ww.j a va 2 s . co m*/ } }
From source file:com.bigdata.dastor.service.StorageProxy.java
/** * Use this method to have these RowMutations applied * across all replicas. This method will take care * of the possibility of a replica being down and hint * the data across to some other replica. * * This is the ZERO consistency level. We do not wait for replies. * * @param mutations the mutations to be applied across the replicas */// w w w . j a v a 2 s. co m public static void mutate(List<RowMutation> mutations) { long startTime = System.nanoTime(); try { StorageService ss = StorageService.instance; for (final RowMutation rm : mutations) { try { String table = rm.getTable(); AbstractReplicationStrategy rs = ss.getReplicationStrategy(table); List<InetAddress> naturalEndpoints = ss.getNaturalEndpoints(table, rm.key()); Multimap<InetAddress, InetAddress> hintedEndpoints = rs.getHintedEndpoints(table, naturalEndpoints); Message unhintedMessage = null; // lazy initialize for non-local, unhinted writes // 3 cases: // 1. local, unhinted write: run directly on write stage // 2. non-local, unhinted write: send row mutation message // 3. hinted write: add hint header, and send message for (Map.Entry<InetAddress, Collection<InetAddress>> entry : hintedEndpoints.asMap() .entrySet()) { InetAddress destination = entry.getKey(); Collection<InetAddress> targets = entry.getValue(); if (targets.size() == 1 && targets.iterator().next().equals(destination)) { // unhinted writes if (destination.equals(FBUtilities.getLocalAddress())) { if (logger.isDebugEnabled()) logger.debug("insert writing local key " + rm.key()); Runnable runnable = new WrappedRunnable() { public void runMayThrow() throws IOException { rm.apply(); } }; StageManager.getStage(StageManager.MUTATION_STAGE).execute(runnable); } else { if (unhintedMessage == null) unhintedMessage = rm.makeRowMutationMessage(); if (logger.isDebugEnabled()) logger.debug("insert writing key " + rm.key() + " to " + unhintedMessage.getMessageId() + "@" + destination); MessagingService.instance.sendOneWay(unhintedMessage, destination); } } else { // hinted Message hintedMessage = rm.makeRowMutationMessage(); for (InetAddress target : targets) { if (!target.equals(destination)) { addHintHeader(hintedMessage, target); if (logger.isDebugEnabled()) logger.debug("insert writing key " + rm.key() + " to " + hintedMessage.getMessageId() + "@" + destination + " for " + target); } } MessagingService.instance.sendOneWay(hintedMessage, destination); } } } catch (IOException e) { throw new RuntimeException("error inserting key " + rm.key(), e); } } } finally { writeStats.addNano(System.nanoTime() - startTime); } }