/** * Register an init callback that will be executed upon initialization. * * @param callback valid callback. * @param persistent should the callback persist after the singleton is initialized, will be removed if false. */ public static void registerInitCallback(ErraiInitCallback callback, boolean persistent) { synchronized (monitor) { InitCallbackBlock block = new InitCallbackBlock(callback, persistent); if (isActive()) { callback.onInit(getService()); if(persistent) { callbacks.add(block); } } else { callbacks.add(block); } } }
/** * Register an init callback that will be executed upon initialization. * * @param callback valid callback. */ public static void registerInitCallback(ErraiInitCallback callback) { registerInitCallback(callback, false); }
private static ErraiService initService(final InitConfig config) { synchronized (getServiceLock) { if (ErraiServiceSingleton.isActive()) { return ErraiServiceSingleton.getService(); ErraiConfigAttribs.WEBSOCKET_SERVLET_CONTEXT_PATH.set(configurator, context.getContextPath() + "/" + pathElement); return ErraiServiceSingleton.initSingleton(configurator);
@Override @SuppressWarnings("unchecked") public Object create(final CreationalContext ctx) { final Object instance = ErraiServiceSingleton.getService(); it.inject(instance, ctx); it.postConstruct(instance); return instance; }
/** * Get the {@link ErraiService} singleton, or if not yet active provide a valid proxy. */ public static ErraiService getService() { return isActive() ? service : proxy; }
@Override public void stopService() { bus.stop(); DefaultTaskManager.get().requestStop(); for (Runnable runnable : shutdownHooks) { try { runnable.run(); } catch (Throwable e) { log.error("error executing shutdown hook", e); } } bus = null; config = null; sessionProvider = null; dispatcher = null; shutdownHooks = null; DefaultRemoteCallBuilder.destroyProxyFactory(); ErraiServiceSingleton.resetProxyAndService(); }
private static ErraiService initService(final InitConfig config) { synchronized (getServiceLock) { if (ErraiServiceSingleton.isActive()) { return ErraiServiceSingleton.getService(); ErraiConfigAttribs.WEBSOCKET_SERVLET_CONTEXT_PATH.set(configurator, context.getContextPath() + "/" + pathElement); return ErraiServiceSingleton.initSingleton(configurator);
@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); }
public static ErraiService initSingleton(final ErraiServiceConfigurator configurator) { synchronized (monitor) { if (isActive()) throw new IllegalStateException("service already set into singleton"); service = ErraiServiceFactory.create(configurator); proxy.closeProxy(service); Iterator<InitCallbackBlock> it = callbacks.iterator(); while(it.hasNext()) { InitCallbackBlock block = it.next(); block.callback.onInit(service); if(!block.persistent) { it.remove(); } } return service; } }
@Override public void stopService() { bus.stop(); DefaultTaskManager.get().requestStop(); for (Runnable runnable : shutdownHooks) { try { runnable.run(); } catch (Throwable e) { log.error("error executing shutdown hook", e); } } bus = null; config = null; sessionProvider = null; dispatcher = null; shutdownHooks = null; DefaultRemoteCallBuilder.destroyProxyFactory(); ErraiServiceSingleton.resetProxyAndService(); }
public DefaultErraiWebSocketChannel(Session session, HttpSession httpSession) { this.session = session; this.httpSession = httpSession; if (ErraiServiceSingleton.isActive()) { erraiService = ErraiServiceSingleton.getService(); } else { throw new IllegalStateException( "Errai Bus should be initialized at this time. Default servlet configured?"); } }
/** * Get the {@link ErraiService} singleton, or if not yet active provide a valid proxy. */ public static ErraiService getService() { return isActive() ? service : proxy; }
/** * Register an init callback that will be executed upon initialization. * * @param callback valid callback. */ public static void registerInitCallback(ErraiInitCallback callback) { registerInitCallback(callback, false); }
public DefaultErraiWebSocketChannel(Session session, HttpSession httpSession) { this.session = session; this.httpSession = httpSession; if (ErraiServiceSingleton.isActive()) { erraiService = ErraiServiceSingleton.getService(); } else { throw new IllegalStateException( "Errai Bus should be initialized at this time. Default servlet configured?"); } }
public static ErraiService initSingleton(final ErraiServiceConfigurator configurator) { synchronized (monitor) { if (isActive()) throw new IllegalStateException("service already set into singleton"); service = ErraiServiceFactory.create(configurator); proxy.closeProxy(service); Iterator<InitCallbackBlock> it = callbacks.iterator(); while(it.hasNext()) { InitCallbackBlock block = it.next(); block.callback.onInit(service); if(!block.persistent) { it.remove(); } } return service; } }
/** * Register an init callback that will be executed upon initialization. * * @param callback valid callback. * @param persistent should the callback persist after the singleton is initialized, will be removed if false. */ public static void registerInitCallback(ErraiInitCallback callback, boolean persistent) { synchronized (monitor) { InitCallbackBlock block = new InitCallbackBlock(callback, persistent); if (isActive()) { callback.onInit(getService()); if(persistent) { callbacks.add(block); } } else { callbacks.add(block); } } }