org.asteriskjava.manager.internal.AsyncEventPump Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of asterisk-java Show documentation
Show all versions of asterisk-java Show documentation
The free Java library for Asterisk PBX integration.
package org.asteriskjava.manager.internal;
import com.google.common.util.concurrent.RateLimiter;
import org.asteriskjava.lock.Locker;
import org.asteriskjava.manager.event.ManagerEvent;
import org.asteriskjava.manager.response.ManagerResponse;
import org.asteriskjava.pbx.util.LogTime;
import org.asteriskjava.util.Log;
import org.asteriskjava.util.LogFactory;
import java.lang.ref.WeakReference;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/**
* AsyncEventPump delivers events and responses to a Dispatcher without blocking
* the thread which is producing the events and responses. AsyncEventPump also
* adds logging around timely handling of events
*
* @author rsutton
*/
public class AsyncEventPump implements Dispatcher, Runnable {
private final Log logger = LogFactory.getLog(AsyncEventPump.class);
private static final long MAX_SAFE_EVENT_AGE = 500;
private final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(20000);
private final Dispatcher dispatcher;
private volatile boolean stop = false;
private final WeakReference