use of arez.spy.ObserverCreatedEvent in project arez by arez.
the class SpyEventProcessorTest method maintainNesting.
@Test
public void maintainNesting() throws Throwable {
final TestSpyEventProcessor processor = new TestSpyEventProcessor();
final ObserverCreatedEvent event = new ObserverCreatedEvent(new NullObserverInfo());
final AtomicInteger handleCallCount = new AtomicInteger();
final BiConsumer<SpyUtil.NestingDelta, ObserverCreatedEvent> handler = (delta, e) -> {
handleCallCount.incrementAndGet();
assertEquals(delta, SpyUtil.NestingDelta.NONE);
assertEquals(e, event);
};
processor.on(ObserverCreatedEvent.class, handler);
assertEquals(processor.getNestingDelta(event), SpyUtil.NestingDelta.NONE);
assertEquals(handleCallCount.get(), 0);
assertEquals(processor.getNestingLevel(), 0);
assertEquals(processor._handleUnhandledEventCallCount, 0);
processor.onSpyEvent(event);
assertEquals(handleCallCount.get(), 1);
assertEquals(processor.getNestingLevel(), 0);
assertEquals(processor._handleUnhandledEventCallCount, 0);
}
use of arez.spy.ObserverCreatedEvent in project arez by arez.
the class ArezContext method createObserver.
/**
* Create an observer with specified parameters.
*
* @param component the component containing observer if any. Should be null if {@link Arez#areNativeComponentsEnabled()} returns false.
* @param name the name of the observer.
* @param mutation true if the reaction may modify state, false otherwise.
* @param reaction the reaction defining observer.
* @param highPriority true if the observer is a high priority observer.
* @return the new Observer.
*/
@Nonnull
Observer createObserver(@Nullable final Component component, @Nullable final String name, final boolean mutation, @Nonnull final Reaction reaction, final boolean highPriority, final boolean canTrackExplicitly) {
final TransactionMode mode = mutationToTransactionMode(mutation);
final Observer observer = new Observer(Arez.areZonesEnabled() ? this : null, component, generateNodeName("Observer", name), null, mode, reaction, highPriority, canTrackExplicitly);
if (willPropagateSpyEvents()) {
getSpy().reportSpyEvent(new ObserverCreatedEvent(new ObserverInfoImpl(getSpy(), observer)));
}
return observer;
}
Aggregations