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

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

Introduction

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

Prototype

public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1) 

Source Link

Document

Returns an immutable multimap containing a single entry.

Usage

From source file:org.wso2.msf4j.internal.router.RequestRouter.java

/**
 * Sends the error to responder./*from  ww w  . j  a va2 s . c o  m*/
 */
private void sendError(HttpResponseStatus status, Throwable ex) {
    String msg;

    if (ex instanceof InvocationTargetException) {
        msg = String.format("Exception Encountered while processing request : %s",
                Objects.firstNonNull(ex.getCause(), ex).getMessage());
    } else {
        msg = String.format("Exception Encountered while processing request: %s", ex.getMessage());
    }

    // Send the status and message, followed by closing of the connection.
    httpMethodInfoBuilder.getResponder().sendString(status, msg,
            ImmutableMultimap.of(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE));
}

From source file:org.wso2.carbon.mss.internal.router.HttpMethodInfo.java

/**
 * Sends the error to responder.//from ww w  . j a  va  2  s. c om
 */
void sendError(HttpResponseStatus status, Throwable ex) {
    String msg;

    if (ex instanceof InvocationTargetException) {
        msg = String.format("Exception Encountered while processing request : %s",
                Objects.firstNonNull(ex.getCause(), ex).getMessage());
    } else {
        msg = String.format("Exception Encountered while processing request: %s", ex.getMessage());
    }

    // Send the status and message, followed by closing of the connection.
    responder.sendString(status, msg,
            ImmutableMultimap.of(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE));
}

From source file:org.jboss.errai.todomvc.client.local.MainPage.java

@EventHandler("allTodos")
void allTodos(ClickEvent event) {
    navigation.goTo(MainPage.class, ImmutableMultimap.of("filter", ALL.name().toLowerCase()));
}

From source file:org.jboss.errai.todomvc.client.local.MainPage.java

@EventHandler("activeTodos")
void activeTodos(ClickEvent event) {
    navigation.goTo(MainPage.class, ImmutableMultimap.of("filter", ACTIVE.name().toLowerCase()));
}

From source file:com.sun.tools.hat.internal.server.HistogramQuery.java

@Override
public void run() {
    ClassResolver resolver = new ClassResolver(snapshot, false);
    JavaClass referee = resolver.apply(Iterables.getOnlyElement(params.get("referee"), null));
    Collection<JavaClass> referrers = Collections2.transform(params.get("referrer"), resolver);
    MetricsProvider metrics;/*  ww  w  .  j  a va 2s .c o  m*/
    if (referee == null) {
        metrics = new GlobalMetricsProvider(snapshot);
    } else {
        metrics = RefereeMetricsProvider.make(referee, referrers);
    }

    startHtml("Heap Histogram");

    printBreadcrumbs(query, referee, referrers);
    out.println("<p align='center'>");
    out.println("<b><a href='/'>All Classes (excluding platform)</a></b>");
    out.println("</p>");

    out.println("<table align=center border=1>");
    out.println("<tr>");
    printHeader("class", "Class", referee, referrers);
    if (metrics.hasRefCount()) {
        printHeader("refCount", "Reference Count", referee, referrers);
    }
    printHeader("count", "Instance Count", referee, referrers);
    printHeader("size", "Total Size", referee, referrers);
    out.println("</tr>");

    Comparator<JavaClass> comparator;
    if (query.equals("count")) {
        comparator = Ordering.natural().reverse().onResultOf(metrics::getCount);
    } else if (query.equals("class")) {
        comparator = Ordering.natural().onResultOf(JavaClass::getName);
    } else if (query.equals("size") || !metrics.hasRefCount()) {
        comparator = Ordering.natural().reverse().onResultOf(metrics::getSize);
    } else {
        comparator = Ordering.natural().reverse().onResultOf(metrics::getRefCount);
    }

    metrics.getClasses().stream().sorted(comparator).forEach(clazz -> {
        out.print("<tr><td>");
        printClass(clazz);
        if (referee == null) {
            out.printf(" (%s)", formatLink(query, "refs", clazz, null, null));
        } else {
            out.printf(" (%s, %s)", formatLink(query, "top", clazz, null, null),
                    formatLink(query, "chain", referee, referrers, clazz));
        }
        out.println("</td>");

        if (metrics.hasRefCount()) {
            String refCount = String.valueOf(metrics.getRefCount(clazz));
            ImmutableMultimap<String, String> params = ImmutableMultimap.of("referee", "true");
            if (referee == null) {
                out.printf("<td>%s</td>%n",
                        formatLink("instances", null, refCount, null, clazz, null, null, params));
            } else {
                out.printf("<td>%s</td>%n",
                        formatLink("instances", null, refCount, null, referee, referrers, clazz, params));
            }
        }

        String count = String.valueOf(metrics.getCount(clazz));
        if (referee == null) {
            out.printf("<td>%s</td>%n", formatLink("instances", null, count, null, clazz, null, null, null));
        } else {
            out.printf("<td>%s</td>%n",
                    formatLink("instances", null, count, null, referee, referrers, clazz, null));
        }
        out.printf("<td>%s</td></tr>%n", metrics.getSize(clazz));
    });
    out.println("</table>");

    endHtml();
}

From source file:org.jboss.errai.todomvc.client.local.MainPage.java

@EventHandler("completedTodos")
void completedTodos(ClickEvent event) {
    navigation.goTo(MainPage.class, ImmutableMultimap.of("filter", COMPLETED.name().toLowerCase()));
}

From source file:co.cask.cdap.gateway.handlers.WorkflowHttpHandler.java

@GET
@Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/current")
public void getWorkflowStatus(HttpRequest request, final HttpResponder responder,
        @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId,
        @PathParam("workflow-name") String workflowName, @PathParam("run-id") String runId) {
    try {//ww  w.  ja  v  a  2  s  .  c  o m
        workflowClient.getWorkflowStatus(namespaceId, appId, workflowName, runId,
                new WorkflowClient.Callback() {
                    @Override
                    public void handle(WorkflowClient.Status status) {
                        if (status.getCode() == WorkflowClient.Status.Code.NOT_FOUND) {
                            responder.sendStatus(HttpResponseStatus.NOT_FOUND);
                        } else if (status.getCode() == WorkflowClient.Status.Code.OK) {
                            // This uses responder.sendByteArray because status.getResult returns a
                            // json string, and responder.sendJson would need deserialization and
                            // serialization.
                            responder.sendByteArray(HttpResponseStatus.OK, Bytes.toBytes(status.getResult()),
                                    ImmutableMultimap.of(HttpHeaders.Names.CONTENT_TYPE,
                                            "application/json; charset=utf-8"));

                        } else {
                            responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, status.getResult());
                        }
                    }
                });
    } catch (SecurityException e) {
        responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    } catch (Throwable e) {
        LOG.error("Caught exception", e);
        responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:co.cask.cdap.data2.datafabric.dataset.DatasetServiceClient.java

public void addModule(String moduleName, String className, Location jarLocation)
        throws DatasetManagementException {

    HttpResponse response = doRequest(HttpMethod.PUT, "modules/" + moduleName,
            ImmutableMultimap.of("X-Class-Name", className), Locations.newInputSupplier(jarLocation));

    if (HttpResponseStatus.CONFLICT.getCode() == response.getResponseCode()) {
        throw new ModuleConflictException(
                String.format("Failed to add module %s due to conflict, details: %s", moduleName, response));
    }//from  ww w.  j ava 2 s .c o  m
    if (HttpResponseStatus.OK.getCode() != response.getResponseCode()) {
        throw new DatasetManagementException(
                String.format("Failed to add module %s, details: %s", moduleName, response));
    }
}

From source file:org.jclouds.openstack.swift.v1.blobstore.RegionScopedSwiftBlobStore.java

@Override
public void setContainerAccess(String name, ContainerAccess access) {
    UpdateContainerOptions options = new UpdateContainerOptions();
    if (access == ContainerAccess.PUBLIC_READ) {
        options.anybodyRead();/*  w w w . jav a  2s  .c  o  m*/
    } else {
        options.headers(ImmutableMultimap.of(SwiftHeaders.CONTAINER_READ, SwiftHeaders.CONTAINER_ACL_PRIVATE));
    }
    api.getContainerApi(regionId).update(name, options);
}

From source file:org.artificer.ui.client.local.pages.ArtifactsPage.java

private void addRelationshipRedirect() {
    // navigate back to the artifact details page
    Multimap<String, String> multimap = ImmutableMultimap.of("uuid",
            stateService.getNewRelationshipSourceUuid());
    navigation.goTo(ArtifactDetailsPage.class, multimap);
}