Search in sources :

Example 1 with ContinuousQueryCache

use of com.tangosol.net.cache.ContinuousQueryCache in project coherence-spring by coherence-community.

the class CoherenceNamedCacheConfigurationViewTest method shouldInjectSuperTypeContinuousQueryCache.

@Test
@SuppressWarnings("rawtypes")
void shouldInjectSuperTypeContinuousQueryCache() {
    SuperTypesBean bean = this.ctx.getBean(SuperTypesBean.class);
    ContinuousQueryCache cache = bean.getContinuousQueryCache();
    assertThat(cache, is(notNullValue()));
    assertThat(cache, is(sameInstance(bean.getContinuousQueryCache())));
}
Also used : ContinuousQueryCache(com.tangosol.net.cache.ContinuousQueryCache) Test(org.junit.jupiter.api.Test)

Example 2 with ContinuousQueryCache

use of com.tangosol.net.cache.ContinuousQueryCache in project micronaut-coherence by micronaut-projects.

the class NamedCacheFactoriesViewTest method shouldInjectSuperTypeContinuousQueryCache.

@Test
void shouldInjectSuperTypeContinuousQueryCache() {
    SuperTypesBean bean = ctx.getBean(SuperTypesBean.class);
    ContinuousQueryCache cache = bean.getContinuousQueryCache();
    assertThat(cache, is(notNullValue()));
    assertThat(cache, is(sameInstance(bean.getContinuousQueryCache())));
}
Also used : ContinuousQueryCache(com.tangosol.net.cache.ContinuousQueryCache) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Example 3 with ContinuousQueryCache

use of com.tangosol.net.cache.ContinuousQueryCache 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 4 with ContinuousQueryCache

use of com.tangosol.net.cache.ContinuousQueryCache in project coherence-spring by coherence-community.

the class CoherenceGenericConverterTests method testContinuousQueryCacheConversion.

@Test
public void testContinuousQueryCacheConversion() {
    final Map map = this.conversionService.convert(this.mockedContinuousQueryCache, Map.class);
    assertThat(map).isSameAs(this.mockedContinuousQueryCache);
    final ContinuousQueryCache continuousQueryCache = this.conversionService.convert(this.mockedContinuousQueryCache, ContinuousQueryCache.class);
    assertThat(continuousQueryCache).isSameAs(this.mockedContinuousQueryCache);
    final AbstractKeySetBasedMap abstractKeySetBasedMap = this.conversionService.convert(this.mockedContinuousQueryCache, AbstractKeySetBasedMap.class);
    assertThat(abstractKeySetBasedMap).isSameAs(this.mockedContinuousQueryCache);
    final AbstractKeyBasedMap abstractKeyBasedMap = this.conversionService.convert(this.mockedContinuousQueryCache, AbstractKeyBasedMap.class);
    assertThat(abstractKeyBasedMap).isSameAs(this.mockedContinuousQueryCache);
    final NamedCache namedCache = this.conversionService.convert(this.mockedContinuousQueryCache, NamedCache.class);
    assertThat(namedCache).isSameAs(this.mockedContinuousQueryCache);
    final NamedMap namedMap = this.conversionService.convert(this.mockedContinuousQueryCache, NamedMap.class);
    assertThat(namedMap).isSameAs(this.mockedContinuousQueryCache);
    final CacheMap cacheMap = this.conversionService.convert(this.mockedContinuousQueryCache, CacheMap.class);
    assertThat(cacheMap).isSameAs(this.mockedContinuousQueryCache);
    final NamedCollection namedCollection = this.conversionService.convert(this.mockedContinuousQueryCache, NamedCollection.class);
    assertThat(namedCollection).isSameAs(this.mockedContinuousQueryCache);
    final ObservableMap observableMap = this.conversionService.convert(this.mockedContinuousQueryCache, ObservableMap.class);
    assertThat(observableMap).isSameAs(this.mockedContinuousQueryCache);
    final ConcurrentMap concurrentMap = this.conversionService.convert(this.mockedContinuousQueryCache, ConcurrentMap.class);
    assertThat(concurrentMap).isSameAs(this.mockedContinuousQueryCache);
    final QueryMap queryMap = this.conversionService.convert(this.mockedContinuousQueryCache, QueryMap.class);
    assertThat(queryMap).isSameAs(this.mockedContinuousQueryCache);
    final InvocableMap invocableMap = this.conversionService.convert(this.mockedContinuousQueryCache, InvocableMap.class);
    assertThat(invocableMap).isSameAs(this.mockedContinuousQueryCache);
    final Releasable releasable = this.conversionService.convert(this.mockedContinuousQueryCache, Releasable.class);
    assertThat(releasable).isSameAs(this.mockedContinuousQueryCache);
}
Also used : InvocableMap(com.tangosol.util.InvocableMap) QueryMap(com.tangosol.util.QueryMap) AbstractKeyBasedMap(com.tangosol.util.AbstractKeyBasedMap) ConcurrentMap(com.tangosol.util.ConcurrentMap) NamedCache(com.tangosol.net.NamedCache) AbstractKeySetBasedMap(com.tangosol.util.AbstractKeySetBasedMap) NamedMap(com.tangosol.net.NamedMap) NamedCollection(com.tangosol.net.NamedCollection) ContinuousQueryCache(com.tangosol.net.cache.ContinuousQueryCache) CacheMap(com.tangosol.net.cache.CacheMap) Releasable(com.tangosol.net.Releasable) ObservableMap(com.tangosol.util.ObservableMap) InvocableMap(com.tangosol.util.InvocableMap) CacheMap(com.tangosol.net.cache.CacheMap) AbstractKeySetBasedMap(com.tangosol.util.AbstractKeySetBasedMap) QueryMap(com.tangosol.util.QueryMap) Map(java.util.Map) ObservableMap(com.tangosol.util.ObservableMap) AbstractKeyBasedMap(com.tangosol.util.AbstractKeyBasedMap) ConcurrentMap(com.tangosol.util.ConcurrentMap) NamedMap(com.tangosol.net.NamedMap) Test(org.junit.jupiter.api.Test)

Example 5 with ContinuousQueryCache

use of com.tangosol.net.cache.ContinuousQueryCache in project coherence-spring by coherence-community.

the class NamedCacheConfiguration method getCacheInternal.

/**
 * Create a {@link NamedCache} instance.
 * <p>
 * If the injection point has a type of {@link ContinuousQueryCache} or is qualified with the {@link View}
 * annotation then a {@link ContinuousQueryCache} instance will be returned otherwise a {@link NamedCache} will be
 * returned.
 * @param injectionPoint the {@link InjectionPoint} that the {@link NamedCache} will be retrieved from
 * @param isCQC a flag specifying whether to return a {@link ContinuousQueryCache}
 * @param <K> the type of the cache keys
 * @param <V> the type of the cache values
 * @return a {@link NamedCache} instance to inject into the injection point
 */
private <K, V> NamedCache<K, V> getCacheInternal(InjectionPoint injectionPoint, boolean isCQC) {
    final MergedAnnotations mergedAnnotations;
    if (injectionPoint.getMethodParameter() != null) {
        mergedAnnotations = MergedAnnotations.from(injectionPoint.getMethodParameter().getParameterAnnotations());
    } else {
        mergedAnnotations = MergedAnnotations.from(injectionPoint.getAnnotatedElement());
    }
    final MergedAnnotation<Name> mergedNameAnnotation = mergedAnnotations.get(Name.class);
    final MergedAnnotation<SessionName> mergedSessionNameAnnotation = mergedAnnotations.get(SessionName.class);
    final MergedAnnotation<View> mergedViewAnnotation = mergedAnnotations.get(View.class);
    final String sessionName;
    final String cacheName = this.determineCacheName(injectionPoint, mergedNameAnnotation);
    if (!mergedSessionNameAnnotation.isPresent() || mergedSessionNameAnnotation.synthesize().value().trim().isEmpty()) {
        sessionName = Coherence.DEFAULT_NAME;
    } else {
        sessionName = mergedSessionNameAnnotation.synthesize().value();
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Going to retrieve NamedCache '%s' for session '%s'.", cacheName, sessionName));
    }
    if (cacheName == null || cacheName.trim().isEmpty()) {
        throw new IllegalArgumentException("Cannot determine cache/map name. No @Name qualifier and injection point is not named");
    }
    final Session session = Coherence.findSession(sessionName).orElseThrow(() -> new IllegalStateException(String.format("No Session is configured with name '%s'.", sessionName)));
    final NamedCache<K, V> cache = session.getCache(cacheName);
    if (isCQC || mergedViewAnnotation.isPresent()) {
        boolean hasValues = (!mergedViewAnnotation.isPresent()) || mergedViewAnnotation.synthesize().cacheValues();
        final Filter filter = this.filterService.getFilter(injectionPoint);
        final ValueExtractor extractor = this.extractorService.getExtractor(injectionPoint, true);
        return new ContinuousQueryCache<>(cache, filter, hasValues, null, extractor);
    }
    return cache;
}
Also used : ValueExtractor(com.tangosol.util.ValueExtractor) View(com.oracle.coherence.spring.annotation.View) SessionName(com.oracle.coherence.spring.annotation.SessionName) Name(com.oracle.coherence.spring.annotation.Name) SessionName(com.oracle.coherence.spring.annotation.SessionName) Filter(com.tangosol.util.Filter) ContinuousQueryCache(com.tangosol.net.cache.ContinuousQueryCache) MergedAnnotations(org.springframework.core.annotation.MergedAnnotations) Session(com.tangosol.net.Session)

Aggregations

ContinuousQueryCache (com.tangosol.net.cache.ContinuousQueryCache)5 Test (org.junit.jupiter.api.Test)3 Filter (com.tangosol.util.Filter)2 ValueExtractor (com.tangosol.util.ValueExtractor)2 Name (com.oracle.coherence.spring.annotation.Name)1 SessionName (com.oracle.coherence.spring.annotation.SessionName)1 View (com.oracle.coherence.spring.annotation.View)1 NamedCache (com.tangosol.net.NamedCache)1 NamedCollection (com.tangosol.net.NamedCollection)1 NamedMap (com.tangosol.net.NamedMap)1 Releasable (com.tangosol.net.Releasable)1 Session (com.tangosol.net.Session)1 CacheMap (com.tangosol.net.cache.CacheMap)1 AbstractKeyBasedMap (com.tangosol.util.AbstractKeyBasedMap)1 AbstractKeySetBasedMap (com.tangosol.util.AbstractKeySetBasedMap)1 ConcurrentMap (com.tangosol.util.ConcurrentMap)1 InvocableMap (com.tangosol.util.InvocableMap)1 ObservableMap (com.tangosol.util.ObservableMap)1 QueryMap (com.tangosol.util.QueryMap)1 Name (io.micronaut.coherence.annotation.Name)1