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

org.asteriskjava.pbx.agi.AgiChannelActivityTransientHoldSilence Maven / Gradle / Ivy

There is a newer version: 3.41.0
Show newest version
package org.asteriskjava.pbx.agi;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiHangupException;
import org.asteriskjava.pbx.AgiChannelActivityAction;
import org.asteriskjava.pbx.Channel;
import org.asteriskjava.util.Log;
import org.asteriskjava.util.LogFactory;

/**
 * Waits in silence for 10 seconds, then hangs up. This is useful where channels
 * are waiting for some external action to redirect/bridge them.
 * 
 * @author rsutton
 */
public class AgiChannelActivityTransientHoldSilence implements AgiChannelActivityAction
{
    private final Log logger = LogFactory.getLog(this.getClass());

    CountDownLatch latch = new CountDownLatch(1);
    volatile boolean callReachedAgi = false;
    boolean firstPass = true;

    @Override
    public void execute(AgiChannel channel, Channel ichannel) throws AgiException, InterruptedException
    {
        try
        {
            callReachedAgi = true;
            channel.answer();
            if (!firstPass)
            {
                logger.error(ichannel + " is still on hold after first pass, Hanging up");
                channel.hangup();
            }
            else
            {
                if (!latch.await(10, TimeUnit.SECONDS))
                {
                    logger.warn("Exiting with timeout");
                }
            }
        }
        catch (AgiHangupException e)
        {
            logger.warn(e);
        }
        finally
        {
            firstPass = false;
        }

    }

    @Override
    public boolean isDisconnect(ActivityAgi activityAgi)
    {
        return false;
    }

    @Override
    public void cancel()
    {
        latch.countDown();

    }

    public boolean hasCallReachedAgi()
    {
        return callReachedAgi;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy