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