All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.up.uca.rs.hunt.OneWayAim Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package io.vertx.up.uca.rs.hunt;

import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.EventBus;
import io.vertx.ext.web.RoutingContext;
import io.vertx.up.commune.Envelop;
import io.vertx.up.atom.agent.Event;
import io.vertx.up.uca.rs.Aim;
import io.vertx.up.fn.Fn;

/**
 * OneWayAim: Event Bus: One-Way
 */
public class OneWayAim extends BaseAim implements Aim {

    @Override
    public Handler attack(final Event event) {
        return Fn.getNull(() -> (context) -> this.exec(() -> {
            // 1. Build Arguments
            final Object[] arguments = this.buildArgs(context, event);

            // 2. Method callxx
            final Object returnValue = this.invoke(event, arguments);
            final Envelop request = Flower.continuous(context, returnValue);

            // 3. Build event bus
            final Vertx vertx = context.vertx();
            final EventBus bus = vertx.eventBus();
            // 4. Send message
            final String address = this.address(event);
            bus.send(address, request, handler -> {
                final Envelop response;
                if (handler.succeeded()) {
                    // One Way message
                    response = Envelop.success(Boolean.TRUE);
                } else {
                    response = this.failure(address, handler);
                }
                Answer.reply(context, response, event);
            });
        }, context, event), event);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy