Search in sources :

Example 1 with Name

use of com.oracle.coherence.spring.annotation.Name in project coherence-spring by coherence-community.

the class CoherenceSpringConfiguration method session.

/**
 * Create a {@link com.tangosol.net.Session} from the qualifiers on the specified
 * injection point. If no {@code Name} annotation is provided, then the default
 * session is returned.
 * @param injectionPoint the injection point that the {@link com.tangosol.net.Session}
 *                       will be injected into
 * @return a {@link com.tangosol.net.Session}
 */
@Bean
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public Session session(InjectionPoint injectionPoint) {
    final Name nameAnnotation = injectionPoint.getAnnotation(Name.class);
    final String sessionName;
    if (nameAnnotation == null) {
        sessionName = Coherence.DEFAULT_NAME;
    } else {
        sessionName = nameAnnotation.value();
    }
    return Coherence.findSession(sessionName).orElseThrow(() -> new IllegalStateException("No Session has been configured with the name " + sessionName));
}
Also used : Name(com.oracle.coherence.spring.annotation.Name) Scope(org.springframework.context.annotation.Scope) MapListenerRegistrationBean(com.oracle.coherence.spring.event.mapevent.MapListenerRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with Name

use of com.oracle.coherence.spring.annotation.Name 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)

Example 3 with Name

use of com.oracle.coherence.spring.annotation.Name in project coherence-spring by coherence-community.

the class NamedTopicConfiguration method getTopicInternal.

private <V> NamedTopic<V> getTopicInternal(InjectionPoint injectionPoint) {
    final MergedAnnotations mergedAnnotations = MergedAnnotations.from(injectionPoint.getAnnotatedElement());
    final MergedAnnotation<SessionName> mergedSessionNameAnnotation = mergedAnnotations.get(SessionName.class);
    final MergedAnnotation<Name> mergedNameAnnotation = mergedAnnotations.get(Name.class);
    final String sessionName;
    final String topicName = this.determineTopicName(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 NamedTopic '%s' for session '%s'.", topicName, sessionName));
    }
    if (topicName == null || topicName.trim().isEmpty()) {
        throw new IllegalArgumentException("Cannot determine topic 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)));
    return session.getTopic(topicName);
}
Also used : MergedAnnotations(org.springframework.core.annotation.MergedAnnotations) SessionName(com.oracle.coherence.spring.annotation.SessionName) Name(com.oracle.coherence.spring.annotation.Name) SessionName(com.oracle.coherence.spring.annotation.SessionName) Session(com.tangosol.net.Session)

Aggregations

Name (com.oracle.coherence.spring.annotation.Name)3 SessionName (com.oracle.coherence.spring.annotation.SessionName)2 Session (com.tangosol.net.Session)2 MergedAnnotations (org.springframework.core.annotation.MergedAnnotations)2 View (com.oracle.coherence.spring.annotation.View)1 MapListenerRegistrationBean (com.oracle.coherence.spring.event.mapevent.MapListenerRegistrationBean)1 ContinuousQueryCache (com.tangosol.net.cache.ContinuousQueryCache)1 Filter (com.tangosol.util.Filter)1 ValueExtractor (com.tangosol.util.ValueExtractor)1 Bean (org.springframework.context.annotation.Bean)1 Scope (org.springframework.context.annotation.Scope)1