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