use of io.vertx.up.atom.worker.Receipt in project vertx-zero by silentbalanceyh.
the class ReceiptExtractor method extract.
private Receipt extract(final Method method) {
// 1. Scan whole Endpoints
final Class<?> clazz = method.getDeclaringClass();
final Annotation annotation = method.getDeclaredAnnotation(Address.class);
final String address = Instance.invoke(annotation, "value");
// 2. Ensure address incoming.
Fn.flingUp(!ADDRESS.contains(address), LOGGER, AddressWrongException.class, this.getClass(), address, clazz, method);
final Receipt receipt = new Receipt();
receipt.setMethod(method);
receipt.setAddress(address);
// Fix: Instance class for proxy
final Object proxy = Instance.singleton(clazz);
receipt.setProxy(proxy);
return receipt;
}
use of io.vertx.up.atom.worker.Receipt in project vertx-zero by silentbalanceyh.
the class ZeroHttpWorker method start.
@Override
public void start() {
// 1. Get event bus
final EventBus bus = this.vertx.eventBus();
// 2. Consume address
for (final Receipt receipt : RECEIPTS) {
// 3. Deploy for each type
final String address = receipt.getAddress();
// 4. Get target reference and method
final Object reference = receipt.getProxy();
final Method method = receipt.getMethod();
this.verifyArgs(method, this.getClass());
// length = 1
final Class<?>[] params = method.getParameterTypes();
final Class<?> returnType = method.getReturnType();
final Class<?> paramCls = params[Values.IDX];
// 6. Invoker select
final Invoker invoker = JetSelector.select(returnType, paramCls);
invoker.ensure(returnType, paramCls);
// 7. Record for different invokers
INVOKER_MAP.put(receipt.hashCode(), invoker);
Fn.safeJvm(() -> Fn.safeNull(() -> bus.<Envelop>consumer(address, message -> {
if (method.isAnnotationPresent(Ipc.class)) {
// Rpc continue replying
invoker.next(reference, method, message, this.vertx);
} else {
// Direct replying
invoker.invoke(reference, method, message);
}
}), address, reference, method), LOGGER);
}
// Record all the information;
if (!LOGGED.getAndSet(Boolean.TRUE)) {
INVOKER_MAP.forEach((key, value) -> LOGGER.info(Info.MSG_INVOKER, value.getClass(), String.valueOf(key), String.valueOf(value.hashCode())));
}
}
use of io.vertx.up.atom.worker.Receipt in project vertx-zero by silentbalanceyh.
the class ReceiptInquirer method scan.
@Override
public Set<Receipt> scan(final Set<Class<?>> queues) {
final List<QueueThread> threadReference = new ArrayList<>();
/**
* 3.1. Build Metadata *
*/
for (final Class<?> queue : queues) {
final QueueThread thread = new QueueThread(queue);
threadReference.add(thread);
thread.start();
}
/**
* 3.2. Join *
*/
Fn.safeJvm(() -> {
for (final QueueThread item : threadReference) {
item.join();
}
}, LOGGER);
/**
* 3.3. Return *
*/
final Set<Receipt> receipts = new HashSet<>();
Fn.safeJvm(() -> {
for (final QueueThread item : threadReference) {
receipts.addAll(item.getReceipts());
}
}, LOGGER);
return receipts;
}
use of io.vertx.up.atom.worker.Receipt in project vertx-zero by silentbalanceyh.
the class EventDiffer method findReplier.
private Method findReplier(final Event event) {
final Annotation annotation = event.getAction().getDeclaredAnnotation(Address.class);
final String address = Instance.invoke(annotation, "value");
// Here address mustn't be null or empty
final Receipt found = RECEIPTS.stream().filter(item -> address.equals(item.getAddress())).findFirst().orElse(null);
final Method method;
// Get null found throw exception.
Fn.flingUp(null == found, LOGGER, WorkerMissingException.class, getClass(), address);
method = found.getMethod();
Fn.flingUp(null == method, LOGGER, WorkerMissingException.class, getClass(), address);
return method;
}
Aggregations