Search in sources :

Example 1 with Event

use of io.vertx.up.atom.agent.Event in project vertx-zero by silentbalanceyh.

the class EndPointTc method testEndPoint.

@Test
public void testEndPoint(final TestContext context) {
    final Set<Event> all = new ConcurrentHashSet<>();
    all.addAll(extractor().extract(ED1.class));
    all.addAll(extractor().extract(ED.class));
    for (final Event event : all) {
        getLogger().info("[TEST] Extract event: {0}.", event);
    }
}
Also used : ED1(io.vertx.quiz.example.ED1) ConcurrentHashSet(io.vertx.core.impl.ConcurrentHashSet) Event(io.vertx.up.atom.agent.Event) ED(io.vertx.quiz.example.ED) Test(org.junit.Test)

Example 2 with Event

use of io.vertx.up.atom.agent.Event in project vertx-zero by silentbalanceyh.

the class FilterAxis method mount.

@Override
public void mount(final Router router) {
    // Extract Event foreach
    FILTERS.forEach((path, events) -> events.forEach(event -> Fn.safeSemi(null == event, LOGGER, () -> LOGGER.warn(Info.NULL_EVENT, this.getClass().getName()), () -> {
        // Path for filter
        final Route route = router.route();
        Hub<Route> hub = Fn.poolThread(Pool.URIHUBS, () -> Instance.instance(UriHub.class));
        hub.mount(route, event);
        // Consumes/Produces
        hub = Fn.poolThread(Pool.MEDIAHUBS, () -> Instance.instance(MediaHub.class));
        hub.mount(route, event);
        // Filter Handler execution
        route.handler(context -> {
            // Execute method
            final Method method = event.getAction();
            final Object proxy = event.getProxy();
            // Call
            this.execute(context, proxy, method);
        });
    })));
}
Also used : Route(io.vertx.ext.web.Route) Event(io.vertx.up.atom.agent.Event) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Fn(io.vertx.up.func.Fn) Router(io.vertx.ext.web.Router) Set(java.util.Set) RoutingContext(io.vertx.ext.web.RoutingContext) Instance(io.vertx.up.tool.mirror.Instance) ConcurrentMap(java.util.concurrent.ConcurrentMap) Axis(io.vertx.up.rs.Axis) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Annal(io.vertx.up.log.Annal) ZeroAnno(io.vertx.up.web.ZeroAnno) Method(java.lang.reflect.Method) Method(java.lang.reflect.Method) Route(io.vertx.ext.web.Route)

Example 3 with Event

use of io.vertx.up.atom.agent.Event in project vertx-zero by silentbalanceyh.

the class EventExtractor method extract.

/**
 * Scan for single
 *
 * @param method
 * @param root
 * @return
 */
private Event extract(final Method method, final String root) {
    // 1.Method path
    final Event event = new Event();
    // 2.Method resolve
    final HttpMethod httpMethod = MethodResolver.resolve(method);
    if (null == httpMethod) {
        // Ignored the method could not be annotated.
        return null;
    } else {
        event.setMethod(httpMethod);
    }
    {
        // 3.1. Get path from method
        final Path path = ZeroHelper.getPath(method);
        if (null == path) {
            // 3.2. Check root double check
            if (!Ut.isNil(root)) {
                // Use root directly.
                event.setPath(root);
            }
        } else {
            final String result = PathResolver.resolve(path, root);
            event.setPath(result);
        }
    }
    // 4.Action
    event.setAction(method);
    // 6.Mime resolve
    event.setConsumes(MediaResolver.consumes(method));
    event.setProduces(MediaResolver.produces(method));
    // 7. Instance clazz for proxy
    final Class<?> clazz = method.getDeclaringClass();
    final Object proxy;
    if (clazz.isInterface()) {
        final Class<?> implClass = Instance.uniqueChild(clazz);
        if (null != implClass) {
            proxy = Instance.singleton(implClass);
        } else {
            /**
             * SPEC5: Interface only, direct api, in this situation,
             * The proxy is null and the agent do nothing. The request will
             * send to event bus direct. It's not needed to set
             * implementation class.
             */
            proxy = Virtual.create();
        }
    } else {
        proxy = Instance.singleton(method.getDeclaringClass());
    }
    event.setProxy(proxy);
    return event;
}
Also used : Path(javax.ws.rs.Path) Event(io.vertx.up.atom.agent.Event) HttpMethod(io.vertx.core.http.HttpMethod)

Example 4 with Event

use of io.vertx.up.atom.agent.Event in project vertx-zero by silentbalanceyh.

the class FilterInquirer method extract.

private void extract(final ConcurrentMap<String, Set<Event>> map, final Class<?> clazz) {
    final Annotation annotation = clazz.getAnnotation(WebFilter.class);
    final String[] pathes = Instance.invoke(annotation, "value");
    // Multi pathes supported
    for (final String path : pathes) {
        final Event event = this.extract(path, clazz);
        if (null != event) {
            // Set<Event> initialized.
            Set<Event> events = map.get(path);
            if (null == events) {
                events = new HashSet<>();
            }
            // Add new event to set
            events.add(event);
            map.put(path, events);
        }
    }
}
Also used : Event(io.vertx.up.atom.agent.Event) Annotation(java.lang.annotation.Annotation)

Example 5 with Event

use of io.vertx.up.atom.agent.Event in project vertx-zero by silentbalanceyh.

the class EventInquirer method scan.

@Override
public Set<Event> scan(final Set<Class<?>> endpoints) {
    final List<EndPointThread> threadReference = new ArrayList<>();
    /**
     * 2.1.Build Api metadata *
     */
    for (final Class<?> endpoint : endpoints) {
        final EndPointThread thread = new EndPointThread(endpoint);
        threadReference.add(thread);
        thread.start();
    }
    /**
     * 3.2. Join *
     */
    Fn.safeJvm(() -> {
        for (final EndPointThread item : threadReference) {
            item.join();
        }
    }, LOGGER);
    /**
     * 3.3. Finally *
     */
    final Set<Event> events = new HashSet<>();
    Fn.safeJvm(() -> {
        for (final EndPointThread item : threadReference) {
            events.addAll(item.getEvents());
        }
    }, LOGGER);
    return events;
}
Also used : ArrayList(java.util.ArrayList) Event(io.vertx.up.atom.agent.Event) EndPointThread(io.vertx.up.web.thread.EndPointThread) HashSet(java.util.HashSet)

Aggregations

Event (io.vertx.up.atom.agent.Event)8 Method (java.lang.reflect.Method)3 ConcurrentHashSet (io.vertx.core.impl.ConcurrentHashSet)2 Annotation (java.lang.annotation.Annotation)2 Path (javax.ws.rs.Path)2 HttpMethod (io.vertx.core.http.HttpMethod)1 HttpServerRequest (io.vertx.core.http.HttpServerRequest)1 HttpServerResponse (io.vertx.core.http.HttpServerResponse)1 Route (io.vertx.ext.web.Route)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 ED (io.vertx.quiz.example.ED)1 ED1 (io.vertx.quiz.example.ED1)1 WebException (io.vertx.up.exception.WebException)1 Fn (io.vertx.up.func.Fn)1 Annal (io.vertx.up.log.Annal)1 Axis (io.vertx.up.rs.Axis)1 Instance (io.vertx.up.tool.mirror.Instance)1 ZeroAnno (io.vertx.up.web.ZeroAnno)1 EndPointThread (io.vertx.up.web.thread.EndPointThread)1