Search in sources :

Example 26 with XnioWorker

use of org.xnio.XnioWorker in project undertow by undertow-io.

the class Http2ClientTestCase method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException {
    int port = DefaultServer.getHostPort("default");
    final PathHandler path = new PathHandler().addExactPath(MESSAGE, new HttpHandler() {

        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            sendMessage(exchange);
        }
    }).addExactPath(POST, new HttpHandler() {

        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            exchange.getRequestReceiver().receiveFullString(new Receiver.FullStringCallback() {

                @Override
                public void handle(HttpServerExchange exchange, String message) {
                    exchange.getResponseSender().send(message);
                }
            });
        }
    });
    server = Undertow.builder().addHttpsListener(port + 1, DefaultServer.getHostAddress("default"), DefaultServer.getServerSslContext()).setServerOption(UndertowOptions.ENABLE_HTTP2, true).setSocketOption(Options.REUSE_ADDRESSES, true).setHandler(new HttpHandler() {

        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            if (!exchange.getProtocol().equals(Protocols.HTTP_2_0)) {
                throw new RuntimeException("Not HTTP/2");
            }
            path.handleRequest(exchange);
        }
    }).build();
    server.start();
    try {
        ADDRESS = new URI("https://" + DefaultServer.getHostAddress() + ":" + (port + 1));
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    // Create xnio worker
    final Xnio xnio = Xnio.getInstance();
    final XnioWorker xnioWorker = xnio.createWorker(null, DEFAULT_OPTIONS);
    worker = xnioWorker;
}
Also used : HttpHandler(io.undertow.server.HttpHandler) XnioWorker(org.xnio.XnioWorker) PathHandler(io.undertow.server.handlers.PathHandler) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) HttpServerExchange(io.undertow.server.HttpServerExchange) Xnio(org.xnio.Xnio) BeforeClass(org.junit.BeforeClass)

Example 27 with XnioWorker

use of org.xnio.XnioWorker in project wildfly by wildfly.

the class ModClusterService method install.

static void install(String name, CapabilityServiceTarget serviceTarget, ModelNode model, OperationContext operationContext) throws OperationFailedException {
    String securityKey = null;
    ModelNode securityKeyNode = ModClusterDefinition.SECURITY_KEY.resolveModelAttribute(operationContext, model);
    if (securityKeyNode.isDefined()) {
        securityKey = securityKeyNode.asString();
    }
    String managementAccessPredicateString = null;
    ModelNode managementAccessPredicateNode = ModClusterDefinition.MANAGEMENT_ACCESS_PREDICATE.resolveModelAttribute(operationContext, model);
    if (managementAccessPredicateNode.isDefined()) {
        managementAccessPredicateString = managementAccessPredicateNode.asString();
    }
    Predicate managementAccessPredicate = null;
    if (managementAccessPredicateString != null) {
        managementAccessPredicate = PredicateParser.parse(managementAccessPredicateString, ModClusterService.class.getClassLoader());
    }
    final ModelNode sslContext = ModClusterDefinition.SSL_CONTEXT.resolveModelAttribute(operationContext, model);
    final ModelNode securityRealm = ModClusterDefinition.SECURITY_REALM.resolveModelAttribute(operationContext, model);
    final ModelNode packetSizeNode = ModClusterDefinition.MAX_AJP_PACKET_SIZE.resolveModelAttribute(operationContext, model);
    OptionMap.Builder builder = OptionMap.builder();
    if (packetSizeNode.isDefined()) {
        builder.set(UndertowOptions.MAX_AJP_PACKET_SIZE, packetSizeNode.asInt());
    }
    builder.set(UndertowOptions.ENABLE_HTTP2, ModClusterDefinition.ENABLE_HTTP2.resolveModelAttribute(operationContext, model).asBoolean());
    ModClusterDefinition.HTTP2_ENABLE_PUSH.resolveOption(operationContext, model, builder);
    ModClusterDefinition.HTTP2_HEADER_TABLE_SIZE.resolveOption(operationContext, model, builder);
    ModClusterDefinition.HTTP2_INITIAL_WINDOW_SIZE.resolveOption(operationContext, model, builder);
    ModClusterDefinition.HTTP2_MAX_CONCURRENT_STREAMS.resolveOption(operationContext, model, builder);
    ModClusterDefinition.HTTP2_MAX_FRAME_SIZE.resolveOption(operationContext, model, builder);
    ModClusterDefinition.HTTP2_MAX_HEADER_LIST_SIZE.resolveOption(operationContext, model, builder);
    // Resolve affinity
    ModelNode affinityNode = model.get(Constants.AFFINITY);
    RouteParsingStrategy routeParsingStrategy = RouteParsingStrategy.SINGLE;
    String routeDelimiter = null;
    if (affinityNode.hasDefined(Constants.NONE)) {
        routeParsingStrategy = RouteParsingStrategy.NONE;
    } else if (affinityNode.hasDefined(Constants.RANKED)) {
        ModelNode rankedModelNode = affinityNode.get(Constants.RANKED);
        routeParsingStrategy = RouteParsingStrategy.RANKED;
        routeDelimiter = RankedAffinityResourceDefinition.Attribute.DELIMITER.resolveModelAttribute(operationContext, rankedModelNode).asString();
    }
    final String mgmtSocketBindingRef = ModClusterDefinition.MANAGEMENT_SOCKET_BINDING.resolveModelAttribute(operationContext, model).asString();
    final ModelNode advertiseSocketBindingRef = ModClusterDefinition.ADVERTISE_SOCKET_BINDING.resolveModelAttribute(operationContext, model);
    final String workerRef = ModClusterDefinition.WORKER.resolveModelAttribute(operationContext, model).asString();
    final RuntimeCapability<?> capabilityName = ModClusterDefinition.Capability.MOD_CLUSTER_FILTER_CAPABILITY.getDefinition();
    final CapabilityServiceBuilder<?> sb = serviceTarget.addCapability(capabilityName);
    final Consumer<FilterService> serviceConsumer = sb.provides(capabilityName, UndertowService.FILTER.append(name));
    final Supplier<XnioWorker> xwSupplier = sb.requiresCapability(IOServices.IO_WORKER_CAPABILITY_NAME, XnioWorker.class, workerRef);
    final Supplier<SocketBinding> msbSupplier = sb.requiresCapability(Capabilities.REF_SOCKET_BINDING, SocketBinding.class, mgmtSocketBindingRef);
    final Supplier<SocketBinding> asbSupplier = advertiseSocketBindingRef.isDefined() ? sb.requiresCapability(Capabilities.REF_SOCKET_BINDING, SocketBinding.class, advertiseSocketBindingRef.asString()) : null;
    final Supplier<SSLContext> scSupplier = sslContext.isDefined() ? sb.requiresCapability(REF_SSL_CONTEXT, SSLContext.class, sslContext.asString()) : null;
    ModClusterService service = new ModClusterService(serviceConsumer, xwSupplier, msbSupplier, asbSupplier, scSupplier, model, ModClusterDefinition.HEALTH_CHECK_INTERVAL.resolveModelAttribute(operationContext, model).asInt(), ModClusterDefinition.MAX_REQUEST_TIME.resolveModelAttribute(operationContext, model).asInt(), ModClusterDefinition.BROKEN_NODE_TIMEOUT.resolveModelAttribute(operationContext, model).asInt(), ModClusterDefinition.ADVERTISE_FREQUENCY.resolveModelAttribute(operationContext, model).asInt(), ModClusterDefinition.ADVERTISE_PATH.resolveModelAttribute(operationContext, model).asString(), ModClusterDefinition.ADVERTISE_PROTOCOL.resolveModelAttribute(operationContext, model).asString(), securityKey, managementAccessPredicate, ModClusterDefinition.CONNECTIONS_PER_THREAD.resolveModelAttribute(operationContext, model).asInt(), ModClusterDefinition.CACHED_CONNECTIONS_PER_THREAD.resolveModelAttribute(operationContext, model).asInt(), ModClusterDefinition.CONNECTION_IDLE_TIMEOUT.resolveModelAttribute(operationContext, model).asInt(), ModClusterDefinition.REQUEST_QUEUE_SIZE.resolveModelAttribute(operationContext, model).asInt(), ModClusterDefinition.USE_ALIAS.resolveModelAttribute(operationContext, model).asBoolean(), ModClusterDefinition.MAX_RETRIES.resolveModelAttribute(operationContext, model).asInt(), Enum.valueOf(FailoverStrategy.class, ModClusterDefinition.FAILOVER_STRATEGY.resolveModelAttribute(operationContext, model).asString()), routeParsingStrategy, routeDelimiter, builder.getMap());
    sb.setInstance(service);
    sb.install();
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) XnioWorker(org.xnio.XnioWorker) SSLContext(javax.net.ssl.SSLContext) RouteParsingStrategy(io.undertow.server.handlers.proxy.RouteParsingStrategy) Predicate(io.undertow.predicate.Predicate) OptionMap(org.xnio.OptionMap) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

XnioWorker (org.xnio.XnioWorker)27 IOException (java.io.IOException)15 Xnio (org.xnio.Xnio)13 HttpHandler (io.undertow.server.HttpHandler)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 HttpServerExchange (io.undertow.server.HttpServerExchange)5 PathHandler (io.undertow.server.handlers.PathHandler)5 BeforeClass (org.junit.BeforeClass)5 OptionMap (org.xnio.OptionMap)5 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)4 InetSocketAddress (java.net.InetSocketAddress)4 URI (java.net.URI)4 Undertow (io.undertow.Undertow)3 ByteBufferPool (io.undertow.connector.ByteBufferPool)3 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)3 ServletContainer (io.undertow.servlet.api.ServletContainer)3 Test (org.junit.Test)3 ChannelListener (org.xnio.ChannelListener)3 Predicate (io.undertow.predicate.Predicate)2 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)2