Combining Manager and FastAgi

Hi, can you help me how to combine the code of Manager and the FastAgi from Asterisk-Java? Here’s my scenario:

  1. Login manager
  2. SendAction to call
  3. Start DefaultAgiServer
  4. Logoff manager
  5. Shutdown DefaultAgiServer

Heres my code:

connection.login(); agiServerThread.setAgiServer(new DefaultAgiServer()); agiServerThread.startup(); ManagerResponse response = connection.sendAction(originateAction, 50000); connection.logoff(); agiServerThread.shutdown();

what exactly are you trying to do? The idea behind the Fast-AGI asterisk-java integration is generally to leave a JVM running to handle AGI requests, as opposed to shutting down the server after each request.

I assume you are trying to originate a call and then hand off control to an AGI script? If that is the case then you will need to do some dialplan programming as well as java programming.

You will need an extension in your dialplan which will call the AGI:// script. Once you have that then you should originate your call (probably via a Local channel) to the context/extension/priority which calls your AGI.

One the java side, you should do things in about this order:

[on startup]
Manager Connection/Login
Start AGI Server

[on some event this is probably repeated many times]
Issue Originate
Process AGI Script

[on shutdown]
Stop AGI Server
Logoff Manager

Hi, thanks for the information. I did the DefaultAgiServer and is running on JVM. I also have a class that is extending the BaseAgiScript so that it will be called on my extension. My problem is, how can I return the data from the class that extends BaseAgiScript to other class?
Here is my code,

[code]public void service(AgiRequest request, AgiChannel channel) throws AgiException {
exec(“Playback”, “welcome”);
String data = getData(“beep”, 15000, 4);
exec(“Playback”, “goodbye”);

}[/code]This code prints the [b]data[/b] but cannot passed to other class inside the java project because the [b]extension[/b] is the one calling this class.

Now we are really getting into Java programming and not so much Asterisk or even Asterisk-Java :smile:

You have a common problem which is that one thread needs to provide data or notifications to another thread. There are some nice Java classes which can help facilitate this, but you will need to be creative in your solutions.

This, like most ‘problems’ in programming there are multiple paths to the same destination. You need to become familiar with the environment you are working with before you can become truly creative in your problem solving.

Just to give you a kick in the right direction… One thing you could do is delcare a static java.util.concurrent.LinkedBlockingQueue at the Main class level. You could poll this blocking queue from one thread and push data into it from the other. It would facilitate an asynchronous data transfer from thread A to thread B.