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

org.jgroups.protocols.tom.DeliveryThread Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and Jakarta Messaging 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: 35.0.0.Beta1
Show newest version
package org.jgroups.protocols.tom;

import org.jgroups.Message;
import org.jgroups.logging.Log;
import org.jgroups.logging.LogFactory;

import java.util.List;

/**
 * The delivery thread. Is the only thread that delivers the Total Order Anycast message in order
 *
 * @author Pedro Ruivo
 * @since 3.1
 */
public class DeliveryThread extends Thread {
    private DeliveryManager  deliveryManager;
    private volatile boolean running = false;
    private DeliveryProtocol deliveryProtocol;

    private final Log log = LogFactory.getLog(this.getClass());

    public DeliveryThread(DeliveryProtocol protocol) {
        super("TOA-Delivery-Thread");
        if (protocol == null) {
            throw new NullPointerException("TOA Protocol can't be null");
        }
        this.deliveryProtocol= protocol;
    }

    public void start(DeliveryManager deliveryManager) {
        this.deliveryManager = deliveryManager;
        start();
    }

    public void setLocalAddress(String localAddress) {
        setName("TOA-Delivery-Thread-" + localAddress);
    }

    @Override
    public void start() {
        if (deliveryManager == null) {
            throw new NullPointerException("Delivery Manager can't be null");
        }
        running = true;
        super.start();
    }

    @Override
    public void run() {
        while (running) {
            try {
                List messages = deliveryManager.getNextMessagesToDeliver();

                for (Message msg : messages) {
                    try {
                        deliveryProtocol.deliver(msg);
                    } catch(Throwable t) {
                        log.warn("Exception caught while delivering message " + msg + ":" + t.getMessage());
                    }
                }
            } catch (InterruptedException e) {
                //interrupted
            }
        }
    }

    @Override
    public void interrupt() {
        running = false;
        super.interrupt();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy