@PostConstruct public void postConstruct() { eventBusService.register(this); }
/** * {@inheritDoc} * * This service overrides the method to perform additional validation that (a) request-scoped services register * their proxies, not themselves, and (b) that singleton services are never registered after the event bus has * been created. * * <p> * Note that we <i>do</i> allow for request-scoped services to register (their proxies) multiple times, ie at * the beginning of each transaction. Because the subscribers are stored in a set, these additional * registrations are in effect ignored. * </p> */ @Override public void register(final Object domainService) { if(domainService instanceof RequestScopedService) { // ok; allow to be registered multiple times (each xactn) since stored in a set. } else { if (Annotations.getAnnotation(domainService.getClass(), RequestScoped.class) != null) { throw new IllegalArgumentException("Request-scoped services must register their proxy, not themselves"); } // a singleton if (!allowLateRegistration && hasPosted()) { // ... coming too late to the party. throw new IllegalStateException("Attempting to register '" + domainService.getClass().getSimpleName() + "' as a subscriber. However events have already been posted and it is too late to register any further (singleton) subscribers. Either use @DomainServiceLayout(menuOrder=...) on subscribing services to ensure that subscribers are initialized before any services that might post events, or alternatively use '" + KEY_ALLOW_LATE_REGISTRATION + "' configuration property to relax this check (meaning that some subscribers will miss some posted events)"); } } super.register(domainService); }