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"));
}
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;
}
}
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"));
}
Aggregations