Example usage for com.google.common.collect ImmutableMultimap copyOf

List of usage examples for com.google.common.collect ImmutableMultimap copyOf

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMultimap copyOf.

Prototype

@Beta
public static <K, V> ImmutableMultimap<K, V> copyOf(
        Iterable<? extends Entry<? extends K, ? extends V>> entries) 

Source Link

Document

Returns an immutable multimap containing the specified entries.

Usage

From source file:fr.ujm.tse.lt2c.satin.triplestore.VerticalPartioningTripleStoreRWLock.java

@Override
public Multimap<Long, Long> getMultiMapForPredicate(final long p) {
    this.rwlock.readLock().lock();
    Multimap<Long, Long> multimap = null;
    try {//from  w  ww  . j  a  va  2 s.c  o  m
        if (this.internalstore.get(p) != null) {
            multimap = ImmutableMultimap.copyOf(this.internalstore.get(p));
        }
    } catch (final Exception e) {
        logger.error("", e);
    } finally {
        this.rwlock.readLock().unlock();
    }
    return multimap;
}

From source file:io.prestosql.execution.scheduler.NodeScheduler.java

public static SplitPlacementResult selectDistributionNodes(NodeMap nodeMap, NodeTaskMap nodeTaskMap,
        int maxSplitsPerNode, int maxPendingSplitsPerTask, Set<Split> splits, List<RemoteTask> existingTasks,
        BucketNodeMap bucketNodeMap) {//w  w w . j a  va2s .  c  o  m
    Multimap<Node, Split> assignments = HashMultimap.create();
    NodeAssignmentStats assignmentStats = new NodeAssignmentStats(nodeTaskMap, nodeMap, existingTasks);

    Set<Node> blockedNodes = new HashSet<>();
    for (Split split : splits) {
        // node placement is forced by the bucket to node map
        Node node = bucketNodeMap.getAssignedNode(split).get();

        // if node is full, don't schedule now, which will push back on the scheduling of splits
        if (assignmentStats.getTotalSplitCount(node) < maxSplitsPerNode
                || assignmentStats.getQueuedSplitCountForStage(node) < maxPendingSplitsPerTask) {
            assignments.put(node, split);
            assignmentStats.addAssignedSplit(node);
        } else {
            blockedNodes.add(node);
        }
    }

    ListenableFuture<?> blocked = toWhenHasSplitQueueSpaceFuture(blockedNodes, existingTasks,
            calculateLowWatermark(maxPendingSplitsPerTask));
    return new SplitPlacementResult(blocked, ImmutableMultimap.copyOf(assignments));
}

From source file:com.facebook.presto.execution.scheduler.NodeScheduler.java

public static SplitPlacementResult selectDistributionNodes(NodeMap nodeMap, NodeTaskMap nodeTaskMap,
        int maxSplitsPerNode, int maxPendingSplitsPerTask, Set<Split> splits, List<RemoteTask> existingTasks,
        NodePartitionMap partitioning) {
    Multimap<Node, Split> assignments = HashMultimap.create();
    NodeAssignmentStats assignmentStats = new NodeAssignmentStats(nodeTaskMap, nodeMap, existingTasks);

    Set<Node> blockedNodes = new HashSet<>();
    for (Split split : splits) {
        // node placement is forced by the partitioning
        Node node = partitioning.getNode(split);

        // if node is full, don't schedule now, which will push back on the scheduling of splits
        if (assignmentStats.getTotalSplitCount(node) < maxSplitsPerNode
                || assignmentStats.getQueuedSplitCountForStage(node) < maxPendingSplitsPerTask) {
            assignments.put(node, split);
            assignmentStats.addAssignedSplit(node);
        } else {// ww w  .j a  v  a 2 s.com
            blockedNodes.add(node);
        }
    }

    ListenableFuture<?> blocked = toWhenHasSplitQueueSpaceFuture(blockedNodes, existingTasks,
            calculateLowWatermark(maxPendingSplitsPerTask));
    return new SplitPlacementResult(blocked, ImmutableMultimap.copyOf(assignments));
}

From source file:org.jclouds.openstack.nova.v2_0.domain.Server.java

@ConstructorProperties({ "id", "name", "links", "uuid", "tenant_id", "user_id", "updated", "created", "hostId",
        "accessIPv4", "accessIPv6", "status", "image", "flavor", "key_name", "config_drive", "addresses",
        "metadata", "extendedStatus", "extendedAttributes", "OS-DCF:diskConfig" })
protected Server(String id, @Nullable String name, java.util.Set<Link> links, @Nullable String uuid,
        String tenantId, String userId, @Nullable Date updated, Date created, @Nullable String hostId,
        @Nullable String accessIPv4, @Nullable String accessIPv6, Server.Status status, Resource image,
        Resource flavor, @Nullable String keyName, @Nullable String configDrive,
        Multimap<String, Address> addresses, Map<String, String> metadata,
        @Nullable ServerExtendedStatus extendedStatus, @Nullable ServerExtendedAttributes extendedAttributes,
        @Nullable String diskConfig) {
    super(id, name, links);
    this.uuid = uuid;
    this.tenantId = checkNotNull(tenantId, "tenantId");
    this.userId = checkNotNull(userId, "userId");
    this.updated = updated;
    this.created = checkNotNull(created, "created");
    this.hostId = Strings.emptyToNull(hostId);
    this.accessIPv4 = Strings.emptyToNull(accessIPv4);
    this.accessIPv6 = Strings.emptyToNull(accessIPv6);
    this.status = checkNotNull(status, "status");
    this.image = checkNotNull(image, "image");
    this.flavor = checkNotNull(flavor, "flavor");
    this.keyName = Strings.emptyToNull(keyName);
    this.configDrive = Strings.emptyToNull(configDrive);
    this.addresses = ImmutableMultimap.copyOf(checkNotNull(addresses, "addresses"));
    this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
    this.extendedStatus = Optional.fromNullable(extendedStatus);
    this.extendedAttributes = Optional.fromNullable(extendedAttributes);
    this.diskConfig = Optional.fromNullable(diskConfig);
}

From source file:org.basepom.mojo.duplicatefinder.classpath.ClasspathDescriptor.java

public ImmutableMap<String, Collection<File>> getClasspathElementLocations(final ConflictType type) {
    checkNotNull(type, "type is null");
    switch (type) {
    case CLASS://  w  w w .j a v  a2  s .c  om
        return ImmutableMultimap.copyOf(classesWithElements).asMap();
    case RESOURCE:
        return ImmutableMultimap.copyOf(resourcesWithElements).asMap();
    default:
        throw new IllegalStateException("Type '" + type + "' unknown!");
    }
}

From source file:org.jclouds.openstack.nova.v1_1.domain.Server.java

protected Server(String id, String name, Set<Link> links, @Nullable String uuid, String tenantId, String userId,
        Date updated, Date created, @Nullable String hostId, @Nullable String accessIPv4,
        @Nullable String accessIPv6, Status status, @Nullable String configDrive, Resource image,
        Resource flavor, String adminPass, @Nullable String keyName, Multimap<String, Address> addresses,
        Map<String, String> metadata) {
    super(id, name, links);
    this.uuid = uuid; // TODO: see what version this came up in
    this.tenantId = checkNotNull(tenantId, "tenantId");
    this.userId = checkNotNull(userId, "userId");
    this.updated = checkNotNull(updated, "updated");
    this.created = checkNotNull(created, "created");
    this.hostId = hostId;
    this.accessIPv4 = accessIPv4;
    this.accessIPv6 = accessIPv6;
    this.status = checkNotNull(status, "status");
    this.configDrive = configDrive;
    this.image = checkNotNull(image, "image");
    this.flavor = checkNotNull(flavor, "flavor");
    this.metadata = Maps.newHashMap(metadata);
    this.addresses = Multimaps2.toOldSchool(ImmutableMultimap.copyOf(checkNotNull(addresses, "addresses")));
    this.adminPass = adminPass;
    this.keyName = keyName;
}

From source file:com.google.template.soy.sharedpasses.FindIndirectParamsVisitor.java

@Override
public IndirectParamsInfo exec(SoyNode node) {

    Preconditions.checkArgument(node instanceof TemplateNode);

    isStartOfPass = true;/*from w  ww. j  av  a 2 s.c  o m*/
    visitedCallSituations = Sets.newHashSet();
    currTemplate = null;
    callerStack = new ArrayDeque<>();
    callerStack.add(new CallerFrame(null, ImmutableSet.<TemplateNode>of(), ImmutableSet.<String>of()));
    indirectParams = Maps.newHashMap();
    paramKeyToCalleesMultimap = HashMultimap.create();
    indirectParamTypes = HashMultimap.create();
    mayHaveIndirectParamsInExternalCalls = false;
    mayHaveIndirectParamsInExternalDelCalls = false;

    visit(node);

    return new IndirectParamsInfo(ImmutableSortedMap.copyOf(indirectParams), paramKeyToCalleesMultimap,
            ImmutableMultimap.copyOf(indirectParamTypes), mayHaveIndirectParamsInExternalCalls,
            mayHaveIndirectParamsInExternalDelCalls);
}

From source file:com.treasuredata.client.AbstractTDClientBuilder.java

public BuilderImpl setHeaders(Multimap<String, String> headers) {
    this.headers = ImmutableMultimap.copyOf(headers);
    return self();
}

From source file:org.jclouds.http.HttpUtils.java

public static Multimap<String, String> filterOutContentHeaders(Multimap<String, String> headers) {
    // http message usually comes in as a null key header, let's filter it out.
    return ImmutableMultimap.copyOf(filterKeys(headers, and(notNull(), not(in(ContentMetadata.HTTP_HEADERS)))));
}

From source file:com.facebook.presto.accumulo.tools.RewriteIndex.java

private void deleteIndexEntries(Connector connector, AccumuloTable table, long start) {
    LOG.info(format("Scanning index table %s to delete index entries", table.getIndexTableName()));
    BatchScanner scanner = null;/*ww  w .  j ava 2 s  .  c  om*/
    BatchWriter indexWriter = null;
    try {
        // Create index writer and metrics writer, but we are never going to flush the metrics writer
        indexWriter = connector.createBatchWriter(table.getIndexTableName(), bwc);
        scanner = connector.createBatchScanner(table.getIndexTableName(), auths, 10);
        LOG.info(format("Created batch scanner against %s with auths %s", table.getIndexTableName(), auths));

        IteratorSetting timestampFilter = new IteratorSetting(21, "timestamp", TimestampFilter.class);
        TimestampFilter.setRange(timestampFilter, 0L, start);
        scanner.addScanIterator(timestampFilter);

        scanner.setRanges(connector.tableOperations().splitRangeByTablets(table.getIndexTableName(),
                new Range(), Integer.MAX_VALUE));

        // Scan the index table, gathering row IDs into batches
        long numTotalMutations = 0L;

        Map<ByteBuffer, RowStatus> rowIdStatuses = new HashMap<>();
        Multimap<ByteBuffer, Mutation> queryIndexEntries = MultimapBuilder.hashKeys().hashSetValues().build();
        Text text = new Text();
        for (Entry<Key, Value> entry : scanner) {
            ++numTotalMutations;

            ByteBuffer rowID = ByteBuffer.wrap(entry.getKey().getColumnQualifier(text).copyBytes());
            Mutation mutation = new Mutation(entry.getKey().getRow(text).copyBytes());
            mutation.putDelete(entry.getKey().getColumnFamily(text).copyBytes(),
                    entry.getKey().getColumnQualifier(text).copyBytes(),
                    entry.getKey().getColumnVisibilityParsed(), start);

            // Get status of this row ID
            switch (rowIdStatuses.getOrDefault(rowID, RowStatus.UNKNOWN)) {
            case ABSENT:
            case UNKNOWN:
                // Absent or unknown? Add it to the collection to check the status and/or delete
                queryIndexEntries.put(rowID, mutation);
                break;
            case PRESENT: // Present? No op
                break;
            }

            if (queryIndexEntries.size() == 100000) {
                flushDeleteEntries(connector, table, start, indexWriter,
                        ImmutableMultimap.copyOf(queryIndexEntries), rowIdStatuses);
                queryIndexEntries.clear();
            }
        }

        flushDeleteEntries(connector, table, start, indexWriter, ImmutableMultimap.copyOf(queryIndexEntries),
                rowIdStatuses);
        queryIndexEntries.clear();

        LOG.info(format(
                "Finished scanning index entries. There are %s distinct row IDs containing %s entries. %s rows present in the data table and %s absent",
                rowIdStatuses.size(), numTotalMutations,
                rowIdStatuses.entrySet().stream().filter(entry -> entry.getValue().equals(RowStatus.PRESENT))
                        .count(),
                rowIdStatuses.entrySet().stream().filter(entry -> entry.getValue().equals(RowStatus.ABSENT))
                        .count()));

        if (dryRun) {
            LOG.info(format("Would have deleted %s index entries", numDeletedIndexEntries));
        } else {
            LOG.info(format("Deleted %s index entries", numDeletedIndexEntries));
        }
    } catch (AccumuloException | AccumuloSecurityException e) {
        LOG.error("Accumulo exception", e);
    } catch (TableNotFoundException e) {
        LOG.error("Table not found, must have been deleted during process", e);
    } finally {
        if (indexWriter != null) {
            try {
                indexWriter.close();
            } catch (MutationsRejectedException e) {
                LOG.error("Server rejected mutations", e);
            }
        }

        if (scanner != null) {
            scanner.close();
        }
    }
}