use of io.helidon.common.Builder in project helidon by oracle.
the class JmsConnector method getSubscriberBuilder.
@Override
public SubscriberBuilder<? extends Message<?>, Void> getSubscriberBuilder(Config mpConfig) {
io.helidon.config.Config config = MpConfig.toHelidonConfig(mpConfig);
ConnectionContext ctx = new ConnectionContext(config);
ConnectionFactory factory = getFactory(ctx).orElseThrow(() -> new MessagingException("No ConnectionFactory found."));
try {
SessionMetadata sessionEntry = prepareSession(config, factory);
Session session = sessionEntry.session();
Destination destination = createDestination(session, ctx);
MessageProducer producer = session.createProducer(destination);
AtomicReference<MessageMappers.MessageMapper> mapper = new AtomicReference<>();
return ReactiveStreams.<Message<?>>builder().flatMapCompletionStage(m -> consume(m, session, mapper, producer, config)).onError(t -> LOGGER.log(Level.SEVERE, t, () -> "Error intercepted from channel " + config.get(CHANNEL_NAME_ATTRIBUTE).asString().orElse("unknown"))).ignore();
} catch (JMSException e) {
throw new MessagingException("Error when creating JMS producer.", e);
}
}
use of io.helidon.common.Builder in project helidon by oracle.
the class GrpcClientBuilder method addServiceMethod.
/**
* Add a method to the {@link ClientServiceDescriptor.Builder}.
* <p>
* The method configuration will be determined by the annotations present on the
* method and the method signature.
*
* @param builder the {@link ClientServiceDescriptor.Builder} to add the method to
* @param method the {@link io.helidon.microprofile.grpc.core.AnnotatedMethod} representing the method to add
*/
private void addServiceMethod(ClientServiceDescriptor.Builder builder, AnnotatedMethod method) {
GrpcMethod annotation = method.firstAnnotationOrMetaAnnotation(GrpcMethod.class);
String name = determineMethodName(method, annotation);
MethodHandler handler = handlerSuppliers().stream().filter(supplier -> supplier.supplies(method)).findFirst().map(supplier -> supplier.get(name, method, instanceSupplier())).orElseThrow(() -> new IllegalArgumentException("Cannot locate a method handler supplier for method " + method));
Class<?> requestType = handler.getRequestType();
Class<?> responseType = handler.getResponseType();
AnnotatedMethodConfigurer configurer = new AnnotatedMethodConfigurer(method, requestType, responseType, handler);
switch(annotation.type()) {
case UNARY:
builder.unary(name, configurer);
break;
case CLIENT_STREAMING:
builder.clientStreaming(name, configurer);
break;
case SERVER_STREAMING:
builder.serverStreaming(name, configurer);
break;
case BIDI_STREAMING:
builder.bidirectional(name, configurer);
break;
case UNKNOWN:
default:
LOGGER.log(Level.SEVERE, () -> "Unrecognized method type " + annotation.type());
}
}
use of io.helidon.common.Builder in project helidon by oracle.
the class GrpcServiceBuilder method addServiceMethod.
/**
* Add a method to the {@link ServiceDescriptor.Builder}.
* <p>
* The method configuration will be determined by the annotations present on the
* method and the method signature.
*
* @param builder the {@link ServiceDescriptor.Builder} to add the method to
* @param method the {@link AnnotatedMethod} representing the method to add
* @param beanManager the {@link jakarta.enterprise.inject.spi.BeanManager} to use
* to look-up CDI beans.
*/
@SuppressWarnings("unchecked")
private void addServiceMethod(ServiceDescriptor.Builder builder, AnnotatedMethod method, BeanManager beanManager) {
GrpcMethod annotation = method.firstAnnotationOrMetaAnnotation(GrpcMethod.class);
String name = determineMethodName(method, annotation);
Supplier<?> instanceSupplier = instanceSupplier();
MethodHandler handler = handlerSuppliers().stream().filter(supplier -> supplier.supplies(method)).findFirst().map(supplier -> supplier.get(name, method, instanceSupplier)).orElseThrow(() -> new IllegalArgumentException("Cannot locate a method handler supplier for method " + method));
Class<?> requestType = handler.getRequestType();
Class<?> responseType = handler.getResponseType();
List<ServerInterceptor> interceptors = lookupMethodInterceptors(beanManager, method);
GrpcInterceptors grpcInterceptors = method.getAnnotation(GrpcInterceptors.class);
if (grpcInterceptors != null) {
for (Class<?> interceptorClass : grpcInterceptors.value()) {
ServerInterceptor interceptor = resolveInterceptor(beanManager, interceptorClass);
if (interceptor != null) {
interceptors.add(interceptor);
}
}
}
AnnotatedMethodConfigurer configurer = new AnnotatedMethodConfigurer(method, requestType, responseType, interceptors);
switch(annotation.type()) {
case UNARY:
builder.unary(name, handler, configurer);
break;
case CLIENT_STREAMING:
builder.clientStreaming(name, handler, configurer);
break;
case SERVER_STREAMING:
builder.serverStreaming(name, handler, configurer);
break;
case BIDI_STREAMING:
builder.bidirectional(name, handler, configurer);
break;
case UNKNOWN:
default:
LOGGER.log(Level.SEVERE, () -> "Unrecognized method type " + annotation.type());
}
}
Aggregations