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);
}
}
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);
});
})));
}
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;
}
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);
}
}
}
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;
}
Aggregations