void postEvent(final AbstractLifecycleEvent<Object> event, final Object pojo) { event.setSource(pojo); eventBusService.post(event); } //endregion
@PostConstruct public void postConstruct() { eventBusService.register(this); }
/** * Post an event. */ @Programmatic public void post(Object event) { if(skip(event)) { return; } getEventBusImplementation().post(event); }
/** * Populates {@link #eventBusImplementation} with the {@link #registeredSubscribers currently registered subscribers}. * * <p> * Guava event bus will throw an exception if attempt to unsubscribe any subscribers that were not subscribed. * It is therefore the responsibility of this service to remember which services were registered * at the start of the request, and to unregister precisely this same set of services at the end. * </p> * * <p> * That said, the Guava event bus is only ever instantiated once (it is in essence an application-scoped singleton), * and so once created it is not possible for any subscribers to be registered. For this reason, the * {@link #register(Object)} will throw an exception if any attempt is made to register once the event bus * has been instantiated. * </p> */ protected void setupEventBus() { if(eventBusImplementation != null) { return; } this.eventBusImplementation = newEventBus(); registeredSubscribers = getSubscribers(); for (Object subscriber : this.registeredSubscribers) { eventBusImplementation.register(subscriber); } }
@Programmatic @PreDestroy public void shutdown() { teardownEventBus(); }
/** * Lazily populates the event bus for the current {@link #getSubscribers() subscribers}. */ @Programmatic protected EventBusImplementation getEventBusImplementation() { setupEventBus(); return eventBusImplementation; }
doRegister(domainService);
/** * Whether or not this link type is supported. * * <p> * Allows users of this module to be able to turn off/on contributions. * </p> */ public boolean supportsLink(final PR polymorphicReference) { final E event = instantiateEvent(eventSource, null, polymorphicReference); eventBusService.post(event); final Class<? extends L> subtype = event.getSubtype(); return subtype != null; }
/** * {@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); }
/** * Installs all {{@link #addFixture(Object) added fixtures} fixtures (ie as * returned by {@link #getFixtures()}). * * <p> * The set of fixtures (as per {@link #getFixtures()}) is <i>not</i> cleared * after installation; the intention being to allow the * {@link org.apache.isis.core.runtime.fixtures.FixturesInstallerAbstract} to be * reused across multiple tests (REVIEW: does that make sense?) */ public void installFixtures() { final IsisConfiguration configuration = getConfiguration(); final boolean fireEvents = configuration.getBoolean("isis.fixtures.fireEvents", true); final EventBusService eventBusService = getEventBusService(); try { if(fireEvents) { eventBusService.post(new FixturesInstallingEvent(this)); } installFixtures(Collections.unmodifiableList(fixtures)); } finally { if(fireEvents) { eventBusService.post(new FixturesInstalledEvent(this)); } } }
@Action( restrictTo = RestrictTo.PROTOTYPING ) @MemberOrder(sequence="10") @Override public List<FixtureResult> runFixtureScript( final FixtureScript fixtureScript, @ParameterLayout( named = "Parameters", describedAs = "Script-specific parameters (if any). The format depends on the script implementation (eg key=value, CSV, JSON, XML etc)", multiLine = 10) @Parameter(optionality = Optionality.OPTIONAL) final String parameters) { try { eventBusService.post(new FixturesInstallingEvent(this)); return super.runFixtureScript(fixtureScript, parameters); } finally { eventBusService.post(new FixturesInstalledEvent(this)); } }
eventBusService.post(event);