Search in sources :

Example 16 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project ethereum-ingest by codingchili.

the class BlockService method importTx.

private Future<Void> importTx(StorableBlock block, JsonObject transactions) {
    Future<Void> future = Future.future();
    DeliveryOptions delivery = new DeliveryOptions().setSendTimeout(ONE_MINUTE);
    if (config.isTxImport()) {
        context.bus().send(TX_ADDR, transactions, delivery, done -> {
            listener.onImported(block.getHash(), block.getNumber());
            if (done.succeeded()) {
                Throwable result = (Throwable) done.result().body();
                if (result == null) {
                    future.complete();
                } else {
                    future.fail(result);
                }
            } else {
                future.fail(done.cause());
            }
        });
    } else {
        future.complete();
    }
    return future;
}
Also used : DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Example 17 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project Eidolons by IDemiurge.

the class GuiEventManagerVertx method trigger_.

public static void trigger_(final GuiEventType type, Object obj) {
    if (CoreEngine.isGraphicsOff())
        return;
    DeliveryOptions options = new DeliveryOptions();
    options.setSendTimeout(50000);
    options.setCodecName("default-codec");
    EventCallbackParam callbackParam;
    if (!(obj instanceof EventCallbackParam)) {
        callbackParam = new EventCallbackParam(obj);
    } else {
        callbackParam = (EventCallbackParam) obj;
    }
    getInstance().publish(type.name(), callbackParam, options);
}
Also used : DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Example 18 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project transmittable-thread-local by alibaba.

the class VertxTransformletTest method testTransmitThreadLocal_InEventbus.

@Test
public void testTransmitThreadLocal_InEventbus() throws Exception {
    final TransmittableThreadLocal<String> transmittableThreadLocal = new TransmittableThreadLocal<>();
    final InheritableThreadLocal<String> inheritableThreadLocal = new InheritableThreadLocal<>();
    final String transmittedData = "transmitted_data";
    final String inheritedData = "inherited_data_ttl";
    final String message = "message_42";
    final Vertx vertx = Vertx.vertx();
    final String address = "consumer";
    vertx.eventBus().consumer(address, msg -> {
        // be executed in netty event loop thread
        System.out.println("========================================");
        assertEquals(message, msg.body());
        if (TtlAgent.isTtlAgentLoaded()) {
            System.out.println("Test **WITH** TTL Agent");
            assertEquals(transmittedData, transmittableThreadLocal.get());
        } else {
            System.out.println("Test WITHOUT TTL Agent");
            assertNull(transmittableThreadLocal.get());
        }
        // InheritableThreadLocal is always null
        assertNull(inheritableThreadLocal.get());
        System.out.println("========================================");
        // reply message can be get by {messageFuture.toCompletionStage().toCompletableFuture().get().body()} or {listener}
        msg.reply(message);
    });
    transmittableThreadLocal.set(transmittedData);
    inheritableThreadLocal.set(inheritedData);
    // delivery message
    final DeliveryOptions deliveryOptions = new DeliveryOptions();
    deliveryOptions.setSendTimeout(1000);
    final Future<Message<Object>> messageFuture = vertx.eventBus().request(address, message, deliveryOptions);
    messageFuture.toCompletionStage().toCompletableFuture().get();
    assertEquals(message, messageFuture.toCompletionStage().toCompletableFuture().get().body());
}
Also used : TransmittableThreadLocal(com.alibaba.ttl.TransmittableThreadLocal) Message(io.vertx.core.eventbus.Message) Vertx(io.vertx.core.Vertx) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions) Test(org.junit.Test)

Example 19 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project vertx-web by vert-x3.

the class RouteToEBServiceHandler method handle.

@Override
public void handle(RoutingContext routingContext) {
    eventBus.request(address, buildPayload(routingContext), deliveryOptions, (AsyncResult<Message<JsonObject>> res) -> {
        if (res.succeeded()) {
            OperationResponse op = new OperationResponse(res.result().body());
            HttpServerResponse response = routingContext.response().setStatusCode(op.getStatusCode());
            if (op.getStatusMessage() != null)
                response.setStatusMessage(op.getStatusMessage());
            if (op.getHeaders() != null)
                op.getHeaders().forEach(h -> response.putHeader(h.getKey(), h.getValue()));
            if (op.getPayload() != null)
                response.end(op.getPayload());
            else
                response.end();
        } else {
            routingContext.fail(res.cause());
        }
    });
}
Also used : DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions) EventBus(io.vertx.core.eventbus.EventBus) OperationRequest(io.vertx.ext.web.api.OperationRequest) HttpServerResponse(io.vertx.core.http.HttpServerResponse) RequestParameters(io.vertx.ext.web.api.RequestParameters) Message(io.vertx.core.eventbus.Message) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) RoutingContext(io.vertx.ext.web.RoutingContext) OperationResponse(io.vertx.ext.web.api.OperationResponse) Handler(io.vertx.core.Handler) Function(java.util.function.Function) HttpServerResponse(io.vertx.core.http.HttpServerResponse) JsonObject(io.vertx.core.json.JsonObject) OperationResponse(io.vertx.ext.web.api.OperationResponse) AsyncResult(io.vertx.core.AsyncResult)

Example 20 with DeliveryOptions

use of io.vertx.core.eventbus.DeliveryOptions in project vertx-web by vert-x3.

the class OpenAPI3RouterBuilderImpl method mountServicesFromExtensions.

@Override
public RouterBuilder mountServicesFromExtensions() {
    for (Map.Entry<String, OperationImpl> opEntry : operations.entrySet()) {
        OperationImpl operation = opEntry.getValue();
        Object extensionVal = OpenAPI3Utils.getAndMergeServiceExtension(OPENAPI_EXTENSION, OPENAPI_EXTENSION_ADDRESS, OPENAPI_EXTENSION_METHOD_NAME, operation.getPathModel(), operation.getOperationModel());
        if (extensionVal != null) {
            if (extensionVal instanceof String) {
                operation.mountRouteToService((String) extensionVal, opEntry.getKey());
            } else if (extensionVal instanceof JsonObject) {
                JsonObject extensionMap = (JsonObject) extensionVal;
                String address = extensionMap.getString(OPENAPI_EXTENSION_ADDRESS);
                String methodName = extensionMap.getString(OPENAPI_EXTENSION_METHOD_NAME);
                JsonObject sanitizedMap = OpenAPI3Utils.sanitizeDeliveryOptionsExtension(extensionMap);
                if (address == null)
                    // TODO specify where
                    throw RouterBuilderException.createWrongExtension("Extension " + OPENAPI_EXTENSION + " must define " + OPENAPI_EXTENSION_ADDRESS);
                if (methodName == null)
                    operation.mountRouteToService(address, opEntry.getKey(), new DeliveryOptions(sanitizedMap));
                else
                    operation.mountRouteToService(address, methodName, new DeliveryOptions(sanitizedMap));
            } else {
                throw RouterBuilderException.createWrongExtension("Extension " + OPENAPI_EXTENSION + " must be or string or" + // TODO specify where
                " a JsonObject");
            }
        }
    }
    return this;
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions)

Aggregations

DeliveryOptions (io.vertx.core.eventbus.DeliveryOptions)96 JsonObject (io.vertx.core.json.JsonObject)39 Message (io.vertx.core.eventbus.Message)23 EventBus (io.vertx.core.eventbus.EventBus)21 Test (org.junit.Test)20 JsonArray (io.vertx.core.json.JsonArray)17 CountDownLatch (java.util.concurrent.CountDownLatch)16 Handler (io.vertx.core.Handler)15 AsyncResult (io.vertx.core.AsyncResult)14 Utils.handlerToAsyncHandler (fr.wseduc.webutils.Utils.handlerToAsyncHandler)10 Vertx (io.vertx.core.Vertx)10 Either (fr.wseduc.webutils.Either)9 Context (io.vertx.core.Context)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Buffer (io.vertx.core.buffer.Buffer)8 MultiMap (io.vertx.core.MultiMap)7 Span (io.vertx.test.faketracer.Span)6 java.util (java.util)6 io.vertx.core (io.vertx.core)5 Future (io.vertx.core.Future)5