Search in sources :

Example 26 with OptionMap

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

the class AutobahnWebSocketServer method run.

public void run() {
    xnio = Xnio.getInstance();
    try {
        worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_WRITE_THREADS, 4).set(Options.WORKER_READ_THREADS, 4).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
        OptionMap serverOptions = OptionMap.builder().set(Options.WORKER_ACCEPT_THREADS, 4).set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
        openListener = new HttpOpenListener(new DefaultByteBufferPool(false, 8192));
        ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
        server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
        setRootHandler(getRootHandler());
        server.resumeAccepts();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ChannelListener(org.xnio.ChannelListener) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) InetSocketAddress(java.net.InetSocketAddress) OptionMap(org.xnio.OptionMap) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) IOException(java.io.IOException)

Example 27 with OptionMap

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

the class UndertowConnectorTestCase method getType.

@Test
public void getType() {
    OptionMap options = OptionMap.builder().getMap();
    assertSame(Connector.Type.AJP, new UndertowConnector(new AjpListenerService("", "", options, OptionMap.EMPTY)).getType());
    assertSame(Connector.Type.HTTP, new UndertowConnector(new HttpListenerService("", "", options, OptionMap.EMPTY, false, false)).getType());
    assertSame(Connector.Type.HTTPS, new UndertowConnector(new HttpsListenerService("", "", options, null, OptionMap.EMPTY)).getType());
}
Also used : OptionMap(org.xnio.OptionMap) AjpListenerService(org.wildfly.extension.undertow.AjpListenerService) HttpListenerService(org.wildfly.extension.undertow.HttpListenerService) HttpsListenerService(org.wildfly.extension.undertow.HttpsListenerService) Test(org.junit.Test)

Example 28 with OptionMap

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

the class RemotingProfileAdd method installServices.

protected void installServices(final OperationContext context, final PathAddress address, final ModelNode profileNode) throws OperationFailedException {
    try {
        final String profileName = address.getLastElement().getValue();
        final ServiceName profileServiceName = RemotingProfileService.BASE_SERVICE_NAME.append(profileName);
        final ModelNode staticEjbDiscoery = StaticEJBDiscoveryDefinition.INSTANCE.resolveModelAttribute(context, profileNode);
        List<StaticEJBDiscoveryDefinition.StaticEjbDiscovery> discoveryList = StaticEJBDiscoveryDefinition.createStaticEjbList(context, staticEjbDiscoery);
        final List<ServiceURL> urls = new ArrayList<>();
        for (StaticEJBDiscoveryDefinition.StaticEjbDiscovery resource : discoveryList) {
            ServiceURL.Builder builder = new ServiceURL.Builder();
            builder.setAbstractType("ejb").setAbstractTypeAuthority("jboss").setUri(new URI(resource.getUrl()));
            String distinctName = resource.getDistinct() == null ? "" : resource.getDistinct();
            String appName = resource.getApp() == null ? "" : resource.getApp();
            String moduleName = resource.getModule();
            if (distinctName.isEmpty()) {
                if (appName.isEmpty()) {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(moduleName));
                } else {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(appName + "/" + moduleName));
                }
            } else {
                if (appName.isEmpty()) {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(moduleName + "/" + distinctName));
                } else {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(appName + "/" + moduleName + "/" + distinctName));
                }
            }
            urls.add(builder.create());
        }
        final Map<String, RemotingProfileService.ConnectionSpec> map = new HashMap<>();
        final RemotingProfileService profileService = new RemotingProfileService(urls, map);
        // populating the map after the fact is cheating, but it works thanks to the MSC start service "fence"
        final ServiceBuilder<RemotingProfileService> builder = context.getServiceTarget().addService(profileServiceName, profileService);
        if (profileNode.hasDefined(EJB3SubsystemModel.REMOTING_EJB_RECEIVER)) {
            for (final Property receiverProperty : profileNode.get(EJB3SubsystemModel.REMOTING_EJB_RECEIVER).asPropertyList()) {
                final ModelNode receiverNode = receiverProperty.getValue();
                final String connectionRef = RemotingEjbReceiverDefinition.OUTBOUND_CONNECTION_REF.resolveModelAttribute(context, receiverNode).asString();
                final long timeout = RemotingEjbReceiverDefinition.CONNECT_TIMEOUT.resolveModelAttribute(context, receiverNode).asLong();
                final ServiceName connectionDependencyService = AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionRef);
                final InjectedValue<AbstractOutboundConnectionService> connectionInjector = new InjectedValue<AbstractOutboundConnectionService>();
                builder.addDependency(connectionDependencyService, AbstractOutboundConnectionService.class, connectionInjector);
                final ModelNode channelCreationOptionsNode = receiverNode.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
                OptionMap channelCreationOptions = createChannelOptionMap(context, channelCreationOptionsNode);
                map.put(connectionRef, new RemotingProfileService.ConnectionSpec(connectionRef, connectionInjector, channelCreationOptions, timeout));
            }
        }
        final boolean isLocalReceiverExcluded = RemotingProfileResourceDefinition.EXCLUDE_LOCAL_RECEIVER.resolveModelAttribute(context, profileNode).asBoolean();
        // service
        if (!isLocalReceiverExcluded) {
            final ModelNode passByValueNode = RemotingProfileResourceDefinition.LOCAL_RECEIVER_PASS_BY_VALUE.resolveModelAttribute(context, profileNode);
            if (passByValueNode.isDefined()) {
                final ServiceName localTransportProviderServiceName = passByValueNode.asBoolean() == true ? LocalTransportProvider.BY_VALUE_SERVICE_NAME : LocalTransportProvider.BY_REFERENCE_SERVICE_NAME;
                builder.addDependency(localTransportProviderServiceName, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
            } else {
                // setup a dependency on the default local ejb receiver service configured at the subsystem level
                builder.addDependency(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
            }
        }
        builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    } catch (IllegalArgumentException | URISyntaxException e) {
        throw new OperationFailedException(e.getLocalizedMessage());
    }
}
Also used : AbstractOutboundConnectionService(org.jboss.as.remoting.AbstractOutboundConnectionService) InjectedValue(org.jboss.msc.value.InjectedValue) HashMap(java.util.HashMap) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ServiceURL(org.wildfly.discovery.ServiceURL) RemotingProfileService(org.jboss.as.ejb3.remote.RemotingProfileService) Property(org.jboss.dmr.Property) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) OptionMap(org.xnio.OptionMap) ModelNode(org.jboss.dmr.ModelNode)

Example 29 with OptionMap

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

the class EJB3RemoteServiceAdd method getChannelCreationOptions.

private OptionMap getChannelCreationOptions(final OperationContext context) throws OperationFailedException {
    // read the full model of the current resource
    final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
    final ModelNode channelCreationOptions = fullModel.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
    if (channelCreationOptions.isDefined() && channelCreationOptions.asInt() > 0) {
        final ClassLoader loader = this.getClass().getClassLoader();
        final OptionMap.Builder builder = OptionMap.builder();
        for (final Property optionProperty : channelCreationOptions.asPropertyList()) {
            final String name = optionProperty.getName();
            final ModelNode propValueModel = optionProperty.getValue();
            final String type = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_TYPE.resolveModelAttribute(context, propValueModel).asString();
            final String optionClassName = this.getClassNameForChannelOptionType(type);
            final String fullyQualifiedOptionName = optionClassName + "." + name;
            final Option option = Option.fromString(fullyQualifiedOptionName, loader);
            final String value = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_VALUE.resolveModelAttribute(context, propValueModel).asString();
            builder.set(option, option.parseValue(value, loader));
        }
        return builder.getMap();
    }
    return OptionMap.EMPTY;
}
Also used : OptionMap(org.xnio.OptionMap) Option(org.xnio.Option) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 30 with OptionMap

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

the class EJB3RemoteServiceAdd method installRuntimeServices.

void installRuntimeServices(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final String clientMappingsClusterName = EJB3RemoteResourceDefinition.CLIENT_MAPPINGS_CLUSTER_NAME.resolveModelAttribute(context, model).asString();
    final String connectorName = EJB3RemoteResourceDefinition.CONNECTOR_REF.resolveModelAttribute(context, model).asString();
    final ServiceName remotingServerInfoServiceName = RemotingConnectorBindingInfoService.serviceName(connectorName);
    final String threadPoolName = EJB3RemoteResourceDefinition.THREAD_POOL_NAME.resolveModelAttribute(context, model).asString();
    final boolean executeInWorker = EJB3RemoteResourceDefinition.EXECUTE_IN_WORKER.resolveModelAttribute(context, model).asBoolean();
    final ServiceTarget target = context.getServiceTarget();
    // Install the client-mapping service for the remoting connector
    new EJBRemotingConnectorClientMappingsEntryProviderService(clientMappingsClusterName, remotingServerInfoServiceName).configure(context).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
    new RegistryInstallerService(clientMappingsClusterName).configure(context).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
    // Handle case where no infinispan subsystem exists or does not define an ejb cache-container
    Resource rootResource = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
    PathElement infinispanPath = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "infinispan");
    if (!rootResource.hasChild(infinispanPath) || !rootResource.getChild(infinispanPath).hasChild(PathElement.pathElement("cache-container", clientMappingsClusterName))) {
        // Install services that would normally be installed by this container/cache
        CapabilityServiceSupport support = context.getCapabilityServiceSupport();
        for (GroupBuilderProvider provider : ServiceLoader.load(LocalGroupBuilderProvider.class, LocalGroupBuilderProvider.class.getClassLoader())) {
            for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> requirement.getServiceName(support, clientMappingsClusterName), clientMappingsClusterName)) {
                builder.configure(support).build(target).install();
            }
        }
        for (CacheBuilderProvider provider : ServiceLoader.load(LocalCacheBuilderProvider.class, LocalCacheBuilderProvider.class.getClassLoader())) {
            for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> requirement.getServiceName(support, clientMappingsClusterName, null), clientMappingsClusterName, null)) {
                builder.configure(support).build(target).install();
            }
        }
    }
    final OptionMap channelCreationOptions = this.getChannelCreationOptions(context);
    // Install the EJB remoting connector service which will listen for client connections on the remoting channel
    // TODO: Externalize (expose via management API if needed) the version and the marshalling strategy
    final EJBRemoteConnectorService ejbRemoteConnectorService = new EJBRemoteConnectorService(channelCreationOptions);
    ServiceBuilder<EJBRemoteConnectorService> builder = target.addService(EJBRemoteConnectorService.SERVICE_NAME, ejbRemoteConnectorService);
    builder.addDependency(RemotingServices.SUBSYSTEM_ENDPOINT, Endpoint.class, ejbRemoteConnectorService.getEndpointInjector()).addDependency(remotingServerInfoServiceName, RemotingConnectorBindingInfoService.RemotingConnectorInfo.class, ejbRemoteConnectorService.getRemotingConnectorInfoInjectedValue()).addDependency(AssociationService.SERVICE_NAME, AssociationService.class, ejbRemoteConnectorService.getAssociationServiceInjector()).addDependency(TxnServices.JBOSS_TXN_REMOTE_TRANSACTION_SERVICE, RemotingTransactionService.class, ejbRemoteConnectorService.getRemotingTransactionServiceInjector()).addDependency(ControlledProcessStateService.SERVICE_NAME, ControlledProcessStateService.class, ejbRemoteConnectorService.getControlledProcessStateServiceInjector()).setInitialMode(ServiceController.Mode.ACTIVE);
    if (!executeInWorker) {
        builder.addDependency(EJB3SubsystemModel.BASE_THREAD_POOL_SERVICE_NAME.append(threadPoolName), ExecutorService.class, ejbRemoteConnectorService.getExecutorService());
    }
    builder.install();
}
Also used : LocalCacheBuilderProvider(org.wildfly.clustering.spi.LocalCacheBuilderProvider) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) ControlledProcessStateService(org.jboss.as.controller.ControlledProcessStateService) EJBRemotingConnectorClientMappingsEntryProviderService(org.jboss.as.ejb3.remote.EJBRemotingConnectorClientMappingsEntryProviderService) ServiceTarget(org.jboss.msc.service.ServiceTarget) RegistryInstallerService(org.jboss.as.ejb3.remote.RegistryInstallerService) RemotingConnectorBindingInfoService(org.jboss.as.remoting.RemotingConnectorBindingInfoService) Resource(org.jboss.as.controller.registry.Resource) AssociationService(org.jboss.as.ejb3.remote.AssociationService) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) PathElement(org.jboss.as.controller.PathElement) Endpoint(org.jboss.remoting3.Endpoint) ServiceName(org.jboss.msc.service.ServiceName) EJBRemoteConnectorService(org.jboss.as.ejb3.remote.EJBRemoteConnectorService) GroupBuilderProvider(org.wildfly.clustering.spi.GroupBuilderProvider) LocalGroupBuilderProvider(org.wildfly.clustering.spi.LocalGroupBuilderProvider) OptionMap(org.xnio.OptionMap) LocalCacheBuilderProvider(org.wildfly.clustering.spi.LocalCacheBuilderProvider) LocalGroupBuilderProvider(org.wildfly.clustering.spi.LocalGroupBuilderProvider)

Aggregations

OptionMap (org.xnio.OptionMap)34 InetSocketAddress (java.net.InetSocketAddress)10 Test (org.junit.Test)10 TestHttpClient (io.undertow.testutils.TestHttpClient)9 HttpResponse (org.apache.http.HttpResponse)8 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)7 ChannelListener (org.xnio.ChannelListener)7 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)6 IOException (java.io.IOException)6 ModelNode (org.jboss.dmr.ModelNode)5 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)4 HttpHandler (io.undertow.server.HttpHandler)4 HttpGet (org.apache.http.client.methods.HttpGet)4 StreamConnection (org.xnio.StreamConnection)4 XnioSsl (org.xnio.ssl.XnioSsl)4 AjpIgnore (io.undertow.testutils.AjpIgnore)3 HttpPost (org.apache.http.client.methods.HttpPost)3 StringEntity (org.apache.http.entity.StringEntity)3 ServiceName (org.jboss.msc.service.ServiceName)3 XnioWorker (org.xnio.XnioWorker)3