Search in sources :

Example 1 with ClassLoaderThreadFactory

use of org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory in project wildfly by wildfly.

the class TransportConfigurationBuilder method accept.

@Override
public void accept(T protocol) {
    InetSocketAddress socketAddress = this.getSocketBinding().getSocketAddress();
    protocol.setBindAddress(socketAddress.getAddress());
    protocol.setBindPort(socketAddress.getPort());
    protocol.setThreadFactory(new ClassLoaderThreadFactory(new DefaultThreadFactory("", false), JChannelFactory.class.getClassLoader()));
    protocol.setDefaultThreadPool(this.threadPoolFactories.get(ThreadPoolResourceDefinition.DEFAULT).getValue().get());
    protocol.setInternalThreadPool(this.threadPoolFactories.get(ThreadPoolResourceDefinition.INTERNAL).getValue().get());
    protocol.setOOBThreadPool(this.threadPoolFactories.get(ThreadPoolResourceDefinition.OOB).getValue().get());
    protocol.setTimer(this.timerFactory.getValue().get());
    Optional<InetSocketAddress> diagnosticsSocketAddress = Optional.ofNullable(this.diagnosticsSocketBinding).map(Value::getValue).map(SocketBinding::getSocketAddress);
    protocol.setValue("enable_diagnostics", diagnosticsSocketAddress.isPresent());
    diagnosticsSocketAddress.ifPresent(address -> {
        protocol.setValue("diagnostics_addr", address.getAddress());
        protocol.setValue("diagnostics_port", address.getPort());
    });
}
Also used : DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) SocketBinding(org.jboss.as.network.SocketBinding) InetSocketAddress(java.net.InetSocketAddress) ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory)

Example 2 with ClassLoaderThreadFactory

use of org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory in project wildfly by wildfly.

the class ThreadPoolFactoryBuilder method build.

@Override
public ServiceBuilder<ThreadPoolFactory> build(ServiceTarget target) {
    int queueLength = this.getQueueLength();
    BlockingQueue<Runnable> queue = (queueLength > 0) ? new ArrayBlockingQueue<>(queueLength) : new SynchronousQueue<>();
    ClassLoader loader = JChannelFactory.class.getClassLoader();
    ThreadFactory threadFactory = new ClassLoaderThreadFactory(new DefaultThreadFactory(this.getThreadGroupPrefix(), false, true), loader);
    RejectedExecutionHandler handler = new ShutdownRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
    ThreadPoolFactory factory = () -> new ThreadPoolExecutor(this.getMinThreads(), this.getMaxThreads(), this.getKeepAliveTime(), TimeUnit.MILLISECONDS, queue, threadFactory, handler);
    return target.addService(this.getServiceName(), new ValueService<>(new ImmediateValue<>(factory)));
}
Also used : ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) ThreadFactory(org.jgroups.util.ThreadFactory) ShutdownRejectedExecutionHandler(org.jgroups.util.ShutdownRejectedExecutionHandler) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) ImmediateValue(org.jboss.msc.value.ImmediateValue) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory) ShutdownRejectedExecutionHandler(org.jgroups.util.ShutdownRejectedExecutionHandler) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 3 with ClassLoaderThreadFactory

use of org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory in project wildfly by wildfly.

the class TimerFactoryBuilder method build.

@Override
public ServiceBuilder<TimerFactory> build(ServiceTarget target) {
    ThreadFactory threadFactory = new ClassLoaderThreadFactory(new LazyThreadFactory(this.getThreadGroupPrefix(), true, true), JChannelFactory.class.getClassLoader());
    TimerFactory factory = () -> new TimeScheduler3(threadFactory, this.getMinThreads(), this.getMaxThreads(), this.getKeepAliveTime(), this.getQueueLength(), "abort");
    return target.addService(this.getServiceName(), new ValueService<>(new ImmediateValue<>(factory)));
}
Also used : ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory) ThreadFactory(org.jgroups.util.ThreadFactory) LazyThreadFactory(org.jgroups.util.LazyThreadFactory) LazyThreadFactory(org.jgroups.util.LazyThreadFactory) JChannelFactory(org.jboss.as.clustering.jgroups.JChannelFactory) TimeScheduler3(org.jgroups.util.TimeScheduler3) ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 4 with ClassLoaderThreadFactory

use of org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory in project wildfly by wildfly.

the class TransportConfigurationServiceConfigurator method accept.

@Override
public void accept(T protocol) {
    SocketBinding binding = this.getSocketBinding();
    InetSocketAddress socketAddress = binding.getSocketAddress();
    protocol.setBindAddress(socketAddress.getAddress());
    protocol.setBindPort(socketAddress.getPort());
    List<ClientMapping> clientMappings = binding.getClientMappings();
    if (!clientMappings.isEmpty()) {
        // JGroups cannot select a client mapping based on the source address, so just use the first one
        ClientMapping mapping = clientMappings.get(0);
        try {
            this.setValue(protocol, "external_addr", InetAddress.getByName(mapping.getDestinationAddress()));
            this.setValue(protocol, "external_port", mapping.getDestinationPort());
        } catch (UnknownHostException e) {
            throw new IllegalArgumentException(e);
        }
    }
    protocol.setThreadFactory(new ClassLoaderThreadFactory(new DefaultThreadFactory("jgroups", false, true), JChannelFactory.class.getClassLoader()));
    protocol.setThreadPool(this.threadPoolFactory.get().apply(protocol.getThreadFactory()));
    protocol.setInternalThreadPoolThreadFactory(new ClassLoaderThreadFactory(new DefaultThreadFactory("jgroups-int", false, false), JChannelFactory.class.getClassLoader()));
    // Because we provide the transport with a thread pool, TP.init() won't auto-create the internal thread pool
    // So create one explicitly matching the logic in TP.init() but with our thread factory
    QueuelessThreadPoolFactory factory = new QueuelessThreadPoolFactory().setMaxThreads(Math.max(4, Runtime.getRuntime().availableProcessors())).setKeepAliveTime(30000);
    protocol.setInternalThreadPool(factory.apply(protocol.getInternalThreadPoolThreadFactory()));
    SocketBinding diagnosticsBinging = this.diagnosticsSocketBinding.get();
    this.setValue(protocol, "enable_diagnostics", diagnosticsBinging != null);
    if (diagnosticsBinging != null) {
        InetSocketAddress address = diagnosticsBinging.getSocketAddress();
        this.setValue(protocol, "diagnostics_addr", address.getAddress());
        this.setValue(protocol, "diagnostics_port", address.getPort());
    }
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) ClientMapping(org.jboss.as.network.ClientMapping) ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory)

Aggregations

ClassLoaderThreadFactory (org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory)4 DefaultThreadFactory (org.jgroups.util.DefaultThreadFactory)3 InetSocketAddress (java.net.InetSocketAddress)2 SocketBinding (org.jboss.as.network.SocketBinding)2 ImmediateValue (org.jboss.msc.value.ImmediateValue)2 ThreadFactory (org.jgroups.util.ThreadFactory)2 UnknownHostException (java.net.UnknownHostException)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 JChannelFactory (org.jboss.as.clustering.jgroups.JChannelFactory)1 ClientMapping (org.jboss.as.network.ClientMapping)1 LazyThreadFactory (org.jgroups.util.LazyThreadFactory)1 ShutdownRejectedExecutionHandler (org.jgroups.util.ShutdownRejectedExecutionHandler)1 TimeScheduler3 (org.jgroups.util.TimeScheduler3)1