}
@SuppressWarnings("rawtypes")
public void afterBeanDiscovery(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
final ErraiService service = ErraiServiceSingleton.getService();
final MessageBus bus = service.getBus();
final EventRoutingTable eventRoutingTable = new EventRoutingTable();
if (bus.isSubscribed(CDI.SERVER_DISPATCHER_SUBJECT)) {
return;
}
final byte[] randBytes = new byte[32];
final Random random = new Random(System.currentTimeMillis());
random.nextBytes(randBytes);
abd.addBean(new ErraiServiceBean(bm, SecureHashUtil.hashToHexString(randBytes)));
for (final MessageSender ms : messageSenders) {
abd.addBean(new SenderBean(ms.getSenderType(), ms.getQualifiers(), bus));
}
// Errai bus injection
abd.addBean(new MessageBusBean(bus));
// Support to inject the request dispatcher.
abd.addBean(new RequestDispatcherMetaData(bm, service.getDispatcher()));
// Register observers
abd.addObserverMethod(new ShutdownEventObserver(managedTypes, bus));
// subscribe service and rpc endpoints
subscribeServices(bm, bus);
// initialize the CDI event bridge to the client
final EventDispatcher eventDispatcher =
new EventDispatcher(bm, eventRoutingTable, bus, observableEvents, eventQualifiers);
AnyEventObserver.init(eventDispatcher);
// subscribe event dispatcher
bus.subscribe(CDI.SERVER_DISPATCHER_SUBJECT, eventDispatcher);
}