Search in sources :

Example 1 with ThreadFactory

use of org.jgroups.util.ThreadFactory in project JGroups by belaban.

the class FD_SOCK method startPingerThread.

/**
 * Does *not* need to be synchronized on pinger_mutex because the caller (down()) already has the mutex acquired
 */
protected synchronized boolean startPingerThread() {
    if (!isPingerThreadRunning()) {
        ThreadFactory factory = getThreadFactory();
        pinger_thread = factory.newThread(this, "FD_SOCK pinger");
        pinger_thread.setDaemon(true);
        pinger_thread.start();
        return true;
    }
    return false;
}
Also used : ThreadFactory(org.jgroups.util.ThreadFactory)

Example 2 with ThreadFactory

use of org.jgroups.util.ThreadFactory 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 ThreadFactory

use of org.jgroups.util.ThreadFactory 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 ThreadFactory

use of org.jgroups.util.ThreadFactory in project JGroups by belaban.

the class ViewHandlerTest method configureGMS.

protected static void configureGMS(GMS gms) {
    Address local_addr = Util.createRandomAddress("A");
    ThreadFactory fac = new DefaultThreadFactory("test", true);
    set(gms, "local_addr", local_addr);
    set(gms, "timer", new TimeScheduler3(fac, 1, 3, 5000, 100, "run"));
    gms.setDownProtocol(new Protocol() {

        public ThreadFactory getThreadFactory() {
            return fac;
        }
    });
}
Also used : DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) ThreadFactory(org.jgroups.util.ThreadFactory) Address(org.jgroups.Address) TimeScheduler3(org.jgroups.util.TimeScheduler3) Protocol(org.jgroups.stack.Protocol)

Example 5 with ThreadFactory

use of org.jgroups.util.ThreadFactory in project JGroups by belaban.

the class VERIFY_SUSPECT_Test method testUnsuspect.

public void testUnsuspect() throws TimeoutException {
    VERIFY_SUSPECT ver = new VERIFY_SUSPECT().setTimeout(1000);
    ProtImpl impl = new ProtImpl();
    ver.setUpProtocol(impl);
    ver.setDownProtocol(new Protocol() {

        public Object down(Event evt) {
            return null;
        }

        public Object down(Message msg) {
            return null;
        }

        public ThreadFactory getThreadFactory() {
            return new DefaultThreadFactory("foo", false, true);
        }
    });
    Map<Address, Long> map = impl.getMap();
    start = System.currentTimeMillis();
    ver.up(new Event(Event.SUSPECT, Collections.singletonList(a)));
    ver.up(new Event(Event.SUSPECT, Collections.singletonList(b)));
    Util.waitUntil(10000, 500, () -> map.size() == 2);
    ver.up(new Event(Event.SUSPECT, Collections.singletonList(a)));
    ver.up(new Event(Event.SUSPECT, Collections.singletonList(b)));
    ver.unsuspect(a);
    Util.waitUntilTrue(10000, 500, () -> map.size() == 1);
    assert map.size() == 1 && map.containsKey(b);
}
Also used : DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) ThreadFactory(org.jgroups.util.ThreadFactory) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) Protocol(org.jgroups.stack.Protocol)

Aggregations

ThreadFactory (org.jgroups.util.ThreadFactory)5 DefaultThreadFactory (org.jgroups.util.DefaultThreadFactory)3 ClassLoaderThreadFactory (org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory)2 ImmediateValue (org.jboss.msc.value.ImmediateValue)2 Protocol (org.jgroups.stack.Protocol)2 TimeScheduler3 (org.jgroups.util.TimeScheduler3)2 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 JChannelFactory (org.jboss.as.clustering.jgroups.JChannelFactory)1 Address (org.jgroups.Address)1 LazyThreadFactory (org.jgroups.util.LazyThreadFactory)1 ShutdownRejectedExecutionHandler (org.jgroups.util.ShutdownRejectedExecutionHandler)1