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

org.asteriskjava.pbx.internal.activity.HoldActivityImpl Maven / Gradle / Ivy

The newest version!
package org.asteriskjava.pbx.internal.activity;

import org.asteriskjava.pbx.*;
import org.asteriskjava.pbx.activities.HoldActivity;
import org.asteriskjava.pbx.agi.AgiChannelActivityHold;
import org.asteriskjava.pbx.asterisk.wrap.events.ManagerEvent;
import org.asteriskjava.pbx.internal.core.AsteriskPBX;
import org.asteriskjava.util.Log;
import org.asteriskjava.util.LogFactory;

import java.util.HashSet;

public class HoldActivityImpl extends ActivityHelper implements HoldActivity {
    private static final Log logger = LogFactory.getLog(HoldActivityImpl.class);
    private final Channel _channel;

    public HoldActivityImpl(final Channel channel, final ActivityCallback callback) {
        super("HoldCall", callback);

        this._channel = channel;
        this.startActivity(false);
    }

    @Override
    public boolean doActivity() throws PBXException {
        boolean success = false;

        HoldActivityImpl.logger.debug("*******************************************************************************");
        HoldActivityImpl.logger.info("***********                    begin Hold Audio               ****************");
        HoldActivityImpl.logger.info("***********                  " + this._channel + " ****************");
        HoldActivityImpl.logger.debug("*******************************************************************************");
        try {
            AsteriskPBX pbx = (AsteriskPBX) PBXFactory.getActivePBX();

            if (!pbx.moveChannelToAgi(_channel)) {
                throw new PBXException("Channel: " + _channel + " couldn't be moved to agi");
            }

            _channel.setCurrentActivityAction(new AgiChannelActivityHold());
            success = true;

        } catch (IllegalArgumentException | IllegalStateException e) {
            HoldActivityImpl.logger.error(e, e);
            HoldActivityImpl.logger.error(e, e);
            throw new PBXException(e);
        }
        return success;
    }

    public Channel getChannel() {
        return this._channel;
    }

    @Override
    public HashSet> requiredEvents() {
        HashSet> required = new HashSet<>();
        // no events requried.

        return required;
    }

    @Override
    public ListenerPriority getPriority() {
        return ListenerPriority.NORMAL;
    }

    @Override
    public void onManagerEvent(ManagerEvent event) {
        // NOOP

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy