Search in sources :

Example 26 with Session

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

the class CoherenceConfigurationClient method buildSession.

/**
 * Builds Coherence session.
 *
 * @param coherenceClientConfiguration configuration
 * @return Coherence session
 */
protected Session buildSession(CoherenceClientConfiguration coherenceClientConfiguration) {
    Channel channel = buildChannel(coherenceClientConfiguration);
    GrpcSessionConfiguration.Builder builder = GrpcSessionConfiguration.builder(channel);
    GrpcSessionConfiguration grpcSessionConfiguration = builder.build();
    Optional<Session> optional = Session.create(grpcSessionConfiguration);
    return optional.orElseThrow(() -> new IllegalStateException("Unable to create session"));
}
Also used : GrpcSessionConfiguration(com.oracle.coherence.client.GrpcSessionConfiguration) Channel(io.grpc.Channel) Session(com.tangosol.net.Session)

Example 27 with Session

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

the class CoherenceTopicListenerProcessor method createSubscribers.

@SuppressWarnings({ "unchecked", "rawtypes" })
void createSubscribers(Coherence coherence) {
    for (MethodHolder holder : methods) {
        List<Subscriber.Option> options = new ArrayList<>();
        ExecutableMethod<?, ?> method = holder.getMethod();
        String topicName = Utils.getFirstTopicName(method).orElse(method.getMethodName());
        String sessionName = method.stringValue(SessionName.class).orElse(Coherence.DEFAULT_NAME);
        if (!coherence.hasSession(sessionName)) {
            LOG.info("Skipping @CoherenceTopicListener annotated method subscription {} Session {} does not exist on Coherence instance {}", method, sessionName, coherence.getName());
            return;
        }
        Session session = coherence.getSession(sessionName);
        Publisher[] sendToPublishers;
        String[] sendToTopics = Utils.getSendToTopicNames(method);
        if (sendToTopics.length > 0) {
            if (method.getReturnType().isVoid()) {
                LOG.info("Skipping @SendTo annotations for @CoherenceTopicListener annotated method {} - method return type is void", method);
                sendToPublishers = new Publisher[0];
            } else {
                sendToPublishers = new Publisher[sendToTopics.length];
                for (int i = 0; i < sendToTopics.length; i++) {
                    NamedTopic<?> topic = session.getTopic(sendToTopics[i]);
                    sendToPublishers[i] = topic.createPublisher();
                }
            }
        } else {
            sendToPublishers = new Publisher[0];
        }
        method.stringValue(SubscriberGroup.class).ifPresent(name -> options.add(Subscriber.Name.of(name)));
        List<String> filterBindings = method.getAnnotationNamesByStereotype(FilterBinding.class);
        if (!filterBindings.isEmpty()) {
            Set<Annotation> annotations = filterBindings.stream().map(s -> method.getAnnotationType(s).orElse(null)).filter(Objects::nonNull).map(method::synthesize).collect(Collectors.toSet());
            Filter filter = filterFactories.resolve(annotations);
            if (filter != null) {
                options.add(Subscriber.Filtered.by(filter));
            }
        }
        List<String> extractorBindings = method.getAnnotationNamesByStereotype(ExtractorBinding.class);
        if (!extractorBindings.isEmpty()) {
            Set<Annotation> annotations = extractorBindings.stream().map(s -> method.getAnnotationType(s).orElse(null)).filter(Objects::nonNull).map(method::synthesize).collect(Collectors.toSet());
            ValueExtractor extractor = extractorFactories.resolve(annotations);
            if (extractor != null) {
                options.add(Subscriber.Convert.using(extractor));
            }
        }
        BeanDefinition<?> beanDefinition = holder.getBeanDefinition();
        Class<?> clsBeanType = beanDefinition.getBeanType();
        Object bean = context.getBean(clsBeanType);
        NamedTopic<?> topic = session.getTopic(topicName);
        Subscriber<?> subscriber = topic.createSubscriber(options.toArray(options.toArray(new Subscriber.Option[0])));
        TopicSubscriber<?, ?, ?> topicSubscriber = new TopicSubscriber(topicName, subscriber, sendToPublishers, bean, method, registry, scheduler);
        subscribers.add(topicSubscriber);
        topicSubscriber.nextMessage();
    }
    subscribed = true;
}
Also used : Filter(com.tangosol.util.Filter) Coherence(com.tangosol.net.Coherence) java.util(java.util) Publishers(io.micronaut.core.async.publisher.Publishers) NamedTopic(com.tangosol.net.topic.NamedTopic) Publisher(com.tangosol.net.topic.Publisher) FluxSink(reactor.core.publisher.FluxSink) ArrayUtils(io.micronaut.core.util.ArrayUtils) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) ElementArgumentBinderRegistry(io.micronaut.coherence.messaging.binders.ElementArgumentBinderRegistry) io.micronaut.coherence.annotation(io.micronaut.coherence.annotation) Session(com.tangosol.net.Session) Singleton(javax.inject.Singleton) Scheduler(reactor.core.scheduler.Scheduler) Function(java.util.function.Function) ExecutableMethod(io.micronaut.inject.ExecutableMethod) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) ValueExtractor(com.tangosol.util.ValueExtractor) TaskExecutors(io.micronaut.scheduling.TaskExecutors) ApplicationContext(io.micronaut.context.ApplicationContext) ExecutableBinder(io.micronaut.core.bind.ExecutableBinder) Subscriber(com.tangosol.net.topic.Subscriber) Schedulers(reactor.core.scheduler.Schedulers) Named(javax.inject.Named) Argument(io.micronaut.core.type.Argument) BoundExecutable(io.micronaut.core.bind.BoundExecutable) FilterFactories(io.micronaut.coherence.FilterFactories) ExecutorService(java.util.concurrent.ExecutorService) DefaultExecutableBinder(io.micronaut.core.bind.DefaultExecutableBinder) Blocking(io.micronaut.core.annotation.Blocking) Logger(org.slf4j.Logger) CancellationException(java.util.concurrent.CancellationException) Collectors(java.util.stream.Collectors) ExecutableMethodProcessor(io.micronaut.context.processor.ExecutableMethodProcessor) CoherenceLifecycleEvent(com.tangosol.net.events.CoherenceLifecycleEvent) Flux(reactor.core.publisher.Flux) CompletionStage(java.util.concurrent.CompletionStage) Annotation(java.lang.annotation.Annotation) BeanDefinition(io.micronaut.inject.BeanDefinition) ExtractorFactories(io.micronaut.coherence.ExtractorFactories) CoherenceSubscriberException(io.micronaut.coherence.messaging.exceptions.CoherenceSubscriberException) Subscriber(com.tangosol.net.topic.Subscriber) Publisher(com.tangosol.net.topic.Publisher) ValueExtractor(com.tangosol.util.ValueExtractor) Annotation(java.lang.annotation.Annotation) Filter(com.tangosol.util.Filter) Session(com.tangosol.net.Session)

Example 28 with Session

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

the class ClientCoherenceFactoryTest method shouldGetSessionByName.

@Test
public void shouldGetSessionByName() {
    Session session = context.createBean(Session.class, "extend");
    assertThat(session, is(notNullValue()));
}
Also used : Session(com.tangosol.net.Session) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Aggregations

Session (com.tangosol.net.Session)28 Test (org.junit.jupiter.api.Test)14 GrpcSessionConfiguration (com.oracle.coherence.client.GrpcSessionConfiguration)5 Coherence (com.tangosol.net.Coherence)5 Filter (com.tangosol.util.Filter)5 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)4 Platform (com.oracle.bedrock.runtime.Platform)4 GetClusterSize (com.oracle.bedrock.runtime.coherence.callables.GetClusterSize)4 GetLocalMemberId (com.oracle.bedrock.runtime.coherence.callables.GetLocalMemberId)4 AbstractTest (com.oracle.bedrock.testsupport.junit.AbstractTest)4 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)4 SessionName (com.oracle.coherence.spring.annotation.SessionName)3 NamedCache (com.tangosol.net.NamedCache)3 ValueExtractor (com.tangosol.util.ValueExtractor)3 Channel (io.grpc.Channel)3 Name (com.oracle.coherence.spring.annotation.Name)2 NamedMap (com.tangosol.net.NamedMap)2 Publisher (com.tangosol.net.topic.Publisher)2 MapEventTransformer (com.tangosol.util.MapEventTransformer)2 MapEventFilter (com.tangosol.util.filter.MapEventFilter)2