Search in sources :

Example 1 with Name

use of io.micronaut.coherence.annotation.Name in project micronaut-coherence by micronaut-projects.

the class EventObserverSupportTest method testCreateObserverForSessionLifecycleEvent.

@Test
void testCreateObserverForSessionLifecycleEvent() {
    ExecutableMethodEventObserver observer = mock(ExecutableMethodEventObserver.class);
    @Starting
    @Started
    @Stopping
    @Stopped
    @Name("test")
    @SessionName("test")
    final class c {
    }
    Starting starting = c.class.getAnnotation(Starting.class);
    Started started = c.class.getAnnotation(Started.class);
    Stopping stopping = c.class.getAnnotation(Stopping.class);
    Stopped stopped = c.class.getAnnotation(Stopped.class);
    Name name = c.class.getAnnotation(Name.class);
    SessionName sessionName = c.class.getAnnotation(SessionName.class);
    Set<java.lang.annotation.Annotation> value = new java.util.HashSet<>();
    value.add(starting);
    value.add(started);
    value.add(stopping);
    value.add(stopped);
    value.add(name);
    value.add(sessionName);
    when(observer.getObservedQualifiers()).thenReturn(value);
    EventObserverSupport.EventHandler handler = EventObserverSupport.createObserver(SessionLifecycleEvent.class, observer);
    EnumSet<?> actual = handler.eventTypes();
    EnumSet<?> expected = EnumSet.allOf(SessionLifecycleEvent.Type.class);
    assertThat(actual, is(expected));
    assertThat(((EventObserverSupport.SessionLifecycleEventHandler) handler).name, is("test"));
}
Also used : Started(io.micronaut.coherence.annotation.Started) Stopped(io.micronaut.coherence.annotation.Stopped) SessionLifecycleEvent(com.tangosol.net.events.SessionLifecycleEvent) Stopping(io.micronaut.coherence.annotation.Stopping) SessionName(io.micronaut.coherence.annotation.SessionName) SessionName(io.micronaut.coherence.annotation.SessionName) Name(io.micronaut.coherence.annotation.Name) Starting(io.micronaut.coherence.annotation.Starting) Test(org.junit.jupiter.api.Test)

Example 2 with Name

use of io.micronaut.coherence.annotation.Name in project micronaut-coherence by micronaut-projects.

the class NamedCacheFactories method getCacheInternal.

private <K, V> NamedCache<K, V> getCacheInternal(InjectionPoint<?> injectionPoint, boolean isCQC) {
    AnnotationMetadata metadata = injectionPoint.getAnnotationMetadata();
    String sessionName = metadata.getValue(SessionName.class, String.class).orElse(Coherence.DEFAULT_NAME);
    String name = metadata.getValue(Name.class, String.class).orElse(getName(injectionPoint));
    isCQC = isCQC || injectionPoint.isAnnotationPresent(View.class);
    if (StringUtils.isEmpty(name)) {
        throw new IllegalArgumentException("Cannot determine cache/map name. No @Name qualifier and injection point is not named");
    }
    Session session = beanContext.createBean(Session.class, sessionName);
    NamedCache<K, V> cache = session.getCache(name);
    if (isCQC || metadata.hasAnnotation(View.class)) {
        boolean hasValues = metadata.booleanValue(View.class, "cacheValues").orElse(true);
        Filter filter = filterFactory.filter(injectionPoint);
        ValueExtractor extractor = getExtractor(injectionPoint);
        ViewId id = new ViewId(name, sessionName, filter, hasValues, extractor);
        WeakReference<ContinuousQueryCache> refCQC = views.compute(id, (key, ref) -> {
            ContinuousQueryCache cqc = ref == null ? null : ref.get();
            if (cqc == null || !cqc.isActive()) {
                cqc = new ContinuousQueryCache<>(cache, filter, hasValues, null, extractor);
                return new WeakReference<>(cqc);
            } else {
                return ref;
            }
        });
        return refCQC.get();
    } else {
        return cache;
    }
}
Also used : ValueExtractor(com.tangosol.util.ValueExtractor) View(io.micronaut.coherence.annotation.View) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) SessionName(io.micronaut.coherence.annotation.SessionName) Name(io.micronaut.coherence.annotation.Name) SessionName(io.micronaut.coherence.annotation.SessionName) Filter(com.tangosol.util.Filter) WeakReference(java.lang.ref.WeakReference) ContinuousQueryCache(com.tangosol.net.cache.ContinuousQueryCache)

Example 3 with Name

use of io.micronaut.coherence.annotation.Name in project micronaut-coherence by micronaut-projects.

the class EventObserverSupportTest method testCreateObserverForCoherenceLifecycleEvent.

@Test
void testCreateObserverForCoherenceLifecycleEvent() {
    ExecutableMethodEventObserver observer = mock(ExecutableMethodEventObserver.class);
    @Starting
    @Started
    @Stopping
    @Stopped
    @Name("test")
    final class c {
    }
    Starting starting = c.class.getAnnotation(Starting.class);
    Started started = c.class.getAnnotation(Started.class);
    Stopping stopping = c.class.getAnnotation(Stopping.class);
    Stopped stopped = c.class.getAnnotation(Stopped.class);
    Name name = c.class.getAnnotation(Name.class);
    Set<java.lang.annotation.Annotation> value = new java.util.HashSet<>();
    value.add(starting);
    value.add(started);
    value.add(stopping);
    value.add(stopped);
    value.add(name);
    when(observer.getObservedQualifiers()).thenReturn(value);
    EventObserverSupport.EventHandler handler = EventObserverSupport.createObserver(CoherenceLifecycleEvent.class, observer);
    EnumSet<?> actual = handler.eventTypes();
    EnumSet<?> expected = EnumSet.allOf(CoherenceLifecycleEvent.Type.class);
    assertThat(actual, is(expected));
    assertThat(((EventObserverSupport.CoherenceLifecycleEventHandler) handler).name, is("test"));
}
Also used : Started(io.micronaut.coherence.annotation.Started) Stopped(io.micronaut.coherence.annotation.Stopped) CoherenceLifecycleEvent(com.tangosol.net.events.CoherenceLifecycleEvent) Stopping(io.micronaut.coherence.annotation.Stopping) SessionName(io.micronaut.coherence.annotation.SessionName) Name(io.micronaut.coherence.annotation.Name) Starting(io.micronaut.coherence.annotation.Starting) Test(org.junit.jupiter.api.Test)

Aggregations

Name (io.micronaut.coherence.annotation.Name)3 SessionName (io.micronaut.coherence.annotation.SessionName)3 Started (io.micronaut.coherence.annotation.Started)2 Starting (io.micronaut.coherence.annotation.Starting)2 Stopped (io.micronaut.coherence.annotation.Stopped)2 Stopping (io.micronaut.coherence.annotation.Stopping)2 Test (org.junit.jupiter.api.Test)2 ContinuousQueryCache (com.tangosol.net.cache.ContinuousQueryCache)1 CoherenceLifecycleEvent (com.tangosol.net.events.CoherenceLifecycleEvent)1 SessionLifecycleEvent (com.tangosol.net.events.SessionLifecycleEvent)1 Filter (com.tangosol.util.Filter)1 ValueExtractor (com.tangosol.util.ValueExtractor)1 View (io.micronaut.coherence.annotation.View)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 WeakReference (java.lang.ref.WeakReference)1