All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgroups.protocols.AsyncNoBundler Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 34.0.0.Final
Show newest version
package org.jgroups.protocols;

import org.jgroups.Message;
import org.jgroups.annotations.Experimental;
import org.jgroups.annotations.Property;
import org.jgroups.util.ByteArrayDataOutputStream;
import org.jgroups.util.DefaultThreadFactory;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Simple and stupid async version of NoBundler. The main purpose is for a send() to return immediately, so
 * delivery of a message which itself sends a message is fast.
 * @author Bela Ban
 * @since  4.0.4
 */
@Experimental
public class AsyncNoBundler extends NoBundler {
    @Property(description="Max number of threads in thread pool")
    protected int max_threads=200;

    protected final ThreadPoolExecutor thread_pool;

    public AsyncNoBundler() {
        thread_pool=new ThreadPoolExecutor(0, max_threads,
                                           30, TimeUnit.SECONDS,
                                           new SynchronousQueue<>(),
                                           new DefaultThreadFactory("async-bundler", true, true),
                                           new ThreadPoolExecutor.CallerRunsPolicy());
        thread_pool.allowCoreThreadTimeOut(true);
    }

    @Override
    public void send(final Message msg) throws Exception {
        Runnable async_send=() -> {
            ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(msg.size() + 10);
            try {
                sendSingleMessage(msg, out);
            }
            catch(Exception e) {
                log.error("failed sending message", e);
            }
        };
        thread_pool.execute(async_send);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy