Example usage for io.vertx.core Handler Handler

List of usage examples for io.vertx.core Handler Handler

Introduction

In this page you can find the example usage for io.vertx.core Handler Handler.

Prototype

Handler

Source Link

Usage

From source file:SubVerticle2.java

License:Apache License

@Override
public void start() {
    vertx.eventBus().consumer("foo-bar", new Handler<Message<JsonObject>>() {
        @Override//from   www.  j av  a2  s .co  m
        public void handle(Message<JsonObject> msg) {
            System.out.println("Subscriber verticle received msg : " + msg.body().encodePrettily());

        }
    });
}

From source file:SubVerticle1.java

License:Apache License

@Override
public void start() {
    vertx.eventBus().consumer("foo-all", new Handler<Message<JsonObject>>() {
        @Override//from   w  ww .jav  a 2 s. c o  m
        public void handle(Message<JsonObject> msg) {
            System.out.println("Subscriber verticle received msg : " + msg.body().encodePrettily());

        }
    });
}

From source file:com.acme.rxjava.example.IrcClient.java

License:Apache License

public IrcClient messageHandler(Handler<IrcMessage> handler) {
    this.delegate.messageHandler(new Handler<com.acme.example.IrcMessage>() {
        public void handle(com.acme.example.IrcMessage event) {
            handler.handle(new IrcMessage(event));
        }//ww w  .j  av a2 s .c  om
    });
    return this;
}

From source file:com.acme.rxjava.example.IrcClient.java

License:Apache License

public void connect(Handler<AsyncResult<IrcClient>> connectHandler) {
    this.delegate.connect(new Handler<AsyncResult<com.acme.example.IrcClient>>() {
        public void handle(AsyncResult<com.acme.example.IrcClient> event) {
            AsyncResult<IrcClient> f;
            if (event.succeeded()) {
                f = InternalHelper.<IrcClient>result(new IrcClient(event.result()));
            } else {
                f = InternalHelper.<IrcClient>failure(event.cause());
            }//from  w ww .j a v a2 s . com
            connectHandler.handle(f);
        }
    });
}

From source file:com.consol.citrus.vertx.endpoint.VertxSyncProducer.java

License:Apache License

@Override
public void send(Message message, final TestContext context) {
    if (log.isDebugEnabled()) {
        log.debug("Sending message to Vert.x event bus address: '" + endpointConfiguration.getAddress() + "'");
    }/*www. j a va 2s .c o m*/

    String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName());
    final String correlationKey = endpointConfiguration.getCorrelator().getCorrelationKey(message);
    correlationManager.saveCorrelationKey(correlationKeyName, correlationKey, context);
    context.onOutboundMessage(message);

    log.info("Message was sent to Vert.x event bus address: '" + endpointConfiguration.getAddress() + "'");

    vertx.eventBus().send(endpointConfiguration.getAddress(), message.getPayload(),
            new Handler<AsyncResult<io.vertx.core.eventbus.Message<Object>>>() {
                @Override
                public void handle(AsyncResult<io.vertx.core.eventbus.Message<Object>> event) {
                    log.info("Received synchronous response on Vert.x event bus reply address");

                    Message responseMessage = endpointConfiguration.getMessageConverter()
                            .convertInbound(event.result(), endpointConfiguration, context);

                    context.onInboundMessage(responseMessage);
                    correlationManager.store(correlationKey, responseMessage);
                }
            });
}

From source file:com.consol.citrus.vertx.factory.AbstractVertxInstanceFactory.java

License:Apache License

/**
 * Creates new Vert.x instance with default factory. Subclasses may overwrite this
 * method in order to provide special Vert.x instance.
 * @return/*from  ww w  .j  a  v  a 2  s . c  om*/
 */
protected Vertx createVertx(VertxEndpointConfiguration endpointConfiguration) {
    final Vertx[] vertx = new Vertx[1];
    final Future loading = new FutureFactoryImpl().future();

    Handler<AsyncResult<Vertx>> asyncLoadingHandler = new Handler<AsyncResult<Vertx>>() {
        @Override
        public void handle(AsyncResult<Vertx> event) {
            vertx[0] = event.result();
            loading.complete();
            log.info("Vert.x instance started");
        }
    };

    if (endpointConfiguration.getPort() > 0) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Creating new Vert.x instance '%s:%s' ...", endpointConfiguration.getHost(),
                    endpointConfiguration.getPort()));
        }
        VertxOptions vertxOptions = new VertxOptions();
        vertxOptions.setClusterPort(endpointConfiguration.getPort());
        vertxOptions.setClusterHost(endpointConfiguration.getHost());
        vertxFactory.clusteredVertx(vertxOptions, asyncLoadingHandler);
    } else {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Creating new Vert.x instance '%s:%s' ...", endpointConfiguration.getHost(),
                    0L));
        }
        VertxOptions vertxOptions = new VertxOptions();
        vertxOptions.setClusterPort(0);
        vertxOptions.setClusterHost(endpointConfiguration.getHost());
        vertxFactory.clusteredVertx(vertxOptions, asyncLoadingHandler);
    }

    // Wait for full loading
    while (!loading.isComplete()) {
        try {
            log.debug("Waiting for Vert.x instance to startup");
            Thread.sleep(250L);
        } catch (InterruptedException e) {
            log.warn("Interrupted while waiting for Vert.x instance startup", e);
        }
    }

    return vertx[0];
}

From source file:com.ddp.SimpleREST.java

License:Open Source License

private void postUserFunctionHierarchy(RoutingContext ctx) {
    HttpServerResponse response = ctx.response();
    Consumer<String> errorHandler = i -> response.putHeader("content-type", "application/json")
            .setStatusCode(500).setStatusMessage(i).end();
    Consumer<String> responseHandler = s -> response.putHeader("content-type", "application/json").end(s);
    ctx.request().bodyHandler(new Handler<Buffer>() {
        @Override//w  ww .j  av a2 s  .  com
        public void handle(Buffer buffer) {
            LOGGER.info("buffer=" + buffer.toString());
            BaseRequest request = gson.fromJson(buffer.toString(), BaseRequest.class);
            UserScriptParameter userScriptParameter = (UserScriptParameter) request.parameter();

            if (userScriptParameter.action().equalsIgnoreCase("add")) { //to add
                userScriptManager.loadUserScript(responseHandler, errorHandler, userScriptParameter.level(),
                        userScriptParameter.name(), userScriptParameter.content(), userScriptParameter.id(),
                        userScriptParameter.parentId());
            } else if (userScriptParameter.action().equalsIgnoreCase("remove")
                    && userScriptParameter.id() > 0) {
                userScriptManager.removeUserScript(responseHandler, errorHandler, userScriptParameter.level(),
                        userScriptParameter.id());
            } else {
                errorHandler.accept("Invalid parameters");
            }

        }
    });

}

From source file:com.ddp.SimpleREST.java

License:Open Source License

private void postHierarchy(RoutingContext routingContext) {
    HttpServerResponse response = routingContext.response();
    Consumer<String> errorHandler = i -> response.putHeader("content-type", "application/json")
            .setStatusCode(500).setStatusMessage(i).end();
    Consumer<String> responseHandler = s -> response.putHeader("content-type", "application/json").end(s);

    routingContext.request().bodyHandler(new Handler<Buffer>() {
        @Override//w w w  . ja  v  a2s  . c o m
        public void handle(Buffer buffer) {
            LOGGER.info("buffer=" + buffer.toString());
            BaseRequest request = gson.fromJson(buffer.toString(), BaseRequest.class);
            NewDataSourceParameter newDataSourceParameter = (NewDataSourceParameter) request.parameter();

            dataBrowse.handleUpdateHierarchy(errorHandler, responseHandler, newDataSourceParameter);
        }
    });
}

From source file:com.ddp.SimpleREST.java

License:Open Source License

private void postSparkRunner(RoutingContext routingContext) {
    // Custom message

    HttpServerResponse response = routingContext.response();
    Consumer<String> errorHandler = i -> response.putHeader("content-type", "application/json")
            .setStatusCode(500).setStatusMessage(i).end();
    Consumer<String> responseHandler = s -> response.putHeader("content-type", "application/json").end(s);

    routingContext.request().bodyHandler(new Handler<Buffer>() {
        @Override/*from  www  .  j a v a2  s  . c om*/
        public void handle(Buffer buffer) {
            LOGGER.info("buffer=" + buffer.toString());
            BaseRequest request = gson.fromJson(buffer.toString(), BaseRequest.class);

            if (request.needPadding()) {
                String className = request.parameter().className();
                if (className.equals(CsvIngestionParameter.class.getCanonicalName())
                        || className.equals(xmlIngestionParameter.class.getCanonicalName())) {
                    IngestionParameter parameter = (IngestionParameter) request.parameter();
                    Consumer curried = currier.apply(BaseConsumer.apply(request, responseHandler));
                    dataBrowse.getEntityDetail(parameter.templateTableName(), curried);
                }
            } else {
                sendToSpark(BaseConsumer.apply(request, responseHandler));
            }
        }
    });
}

From source file:com.diabolicallabs.process.manager.rxjava.service.KnowledgeService.java

License:Apache License

public KnowledgeService getProcessService(Handler<AsyncResult<ProcessService>> handler) {
    delegate.getProcessService(/* www. j a v a2 s  .c  o m*/
            new Handler<AsyncResult<com.diabolicallabs.process.manager.service.ProcessService>>() {
                public void handle(AsyncResult<com.diabolicallabs.process.manager.service.ProcessService> ar) {
                    if (ar.succeeded()) {
                        handler.handle(
                                io.vertx.core.Future.succeededFuture(ProcessService.newInstance(ar.result())));
                    } else {
                        handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
                    }
                }
            });
    return this;
}