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

org.asteriskjava.pbx.agi.AgiChannelActivityBridge 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 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;

public class AgiChannelActivityBridge implements AgiChannelActivityAction
{

    private Channel target;
    private final Log logger = LogFactory.getLog(this.getClass());

    CountDownLatch latch = new CountDownLatch(1);

    public AgiChannelActivityBridge(Channel target)
    {
        this.target = target;
    }

    @Override
    public void execute(AgiChannel channel, Channel ichannel) throws AgiException, InterruptedException
    {
        try
        {
            // TODO: this should probably pass the 'F' option to allow the
            // bridgee
            // to go back to dialplan.
            // I'm not currently prepared to do it as it is called from a number
            // of places, and
            // I can't currently see it causing problems.
            channel.bridge(target.getChannelName(), "");
            channel.hangup();
        }
        catch (AgiHangupException e)
        {
            logger.warn(e);
        }
        finally
        {
            latch.countDown();
        }
    }

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

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

    }
    // Logger logger = LogManager.getLogger();

    public void sleepWhileBridged() throws InterruptedException
    {
        latch.await();

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy