Synchronous Originate

I was wondering if anyone knew of a way to make a synchronous call from another server via Asterisk. I have an application (Java) that needs to initiate calls and block until the call is completed. Specifically, I have 2 servers. The main server contacts the asterisk server via the manager API and intiates a phone call. I would like my “phone call request” thread to block until the call has completed. The problem is that the originate command returns before the call completes.

Any suggestions?

Thanks, David

ugh… only thing i can think of is to write a couple of AGI scripts that synchronize (using a lockfile or something…) the creation of the ‘i am done’ file would have to be hooked into the ‘h’ priority for that call (i think this is possible?) the application doing the originate would run the agi script that would wait for the ‘i am done’ file to show up.

Two questions:

Do you want to block until
a) the originate has completed, i.e. the first party answered and the second is being called
b) the call has been setup, i.e. the second party answered
c) the whole call is completed, i.e. one party hung up

Why do you need to block a thread? Doesn’t an asynchronous model fit much better?


Hi Stefan,

I am looking for C. I want to block until the entire call is complete. The call that is being maded is automated. In a nutshell, the phone call ask the answering party to enter some DTMF digits. On my application server (java), I will have a thread that is tasked with ensuring the call is initiate and completed. I might have 10 threads going on at once, each in the process of being in a call. (Specifically, I am using JMS queues to handle requests to make (automated) calls. My MDB is handing the requests in the queue. I want the MDB to block until the call is completed (or fails)).

I’m not doing a typical PBX application. Asynchronous doesn’t actually fit better. I can have my application server deal with an asynchronous call to initiate and a “call back” when the call is completed, but with my current design on my app sever, it would require more work and moving parts.

Thanks, David


with Asterisk-Java 0.3 I would do something like this:

[code] DefaultAsteriskServer server;
AsteriskChannel channel;

    server = new DefaultAsteriskServer(new DefaultManagerConnection(...));
    channel = server.originateToExtension("SIP/1234", "default", "3456", 1, timeout);

    synchronized (channel)
        channel.addPropertyChangeListener(AsteriskChannel.PROPERTY_STATE, new PropertyChangeListener()
            public void propertyChange(PropertyChangeEvent evt)
                if (evt.getNewValue() == ChannelState.HUNGUP)

        // not yet hung up?
        if (channel.getState() != ChannelState.HUNGUP)
            // wait for the notification


I didn’t test it, but you should get the idea.


P.S. Asterisk-Java is not yet officially released but you can grab it from


Thank you for the pointer. This solution looks like it will work well.

My time line to solve this problem is actually pretty tight. Do you have any idea on when 0.3 will be “officially” released? Can you think of a way to do this using 0.2?

Thank you again for the help.


WIth 0.2 you would have to implement the channel tracking on your own.

0.3 should be released with Asterisk 1.4 - but maybe I do it earlier depending on how long Asterisk takes…