Search in sources :

Example 1 with ObserverCreatedEvent

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);
}
Also used : TransactionCompletedEvent(arez.spy.TransactionCompletedEvent) TransactionStartedEvent(arez.spy.TransactionStartedEvent) Assert(org.testng.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractArezExtrasTest(arez.extras.AbstractArezExtrasTest) BiConsumer(java.util.function.BiConsumer) ValueUtil(org.realityforge.guiceyloops.shared.ValueUtil) Test(org.testng.annotations.Test) ObserverCreatedEvent(arez.spy.ObserverCreatedEvent) Nonnull(javax.annotation.Nonnull) ObserverCreatedEvent(arez.spy.ObserverCreatedEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractArezExtrasTest(arez.extras.AbstractArezExtrasTest) Test(org.testng.annotations.Test)

Example 2 with ObserverCreatedEvent

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;
}
Also used : ObserverCreatedEvent(arez.spy.ObserverCreatedEvent) Nonnull(javax.annotation.Nonnull)

Aggregations

ObserverCreatedEvent (arez.spy.ObserverCreatedEvent)2 Nonnull (javax.annotation.Nonnull)2 AbstractArezExtrasTest (arez.extras.AbstractArezExtrasTest)1 TransactionCompletedEvent (arez.spy.TransactionCompletedEvent)1 TransactionStartedEvent (arez.spy.TransactionStartedEvent)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiConsumer (java.util.function.BiConsumer)1 ValueUtil (org.realityforge.guiceyloops.shared.ValueUtil)1 Assert (org.testng.Assert)1 Test (org.testng.annotations.Test)1