com.orderlysoftware.orderlycalls.asterisk.agi
Class AGIServer

java.lang.Object
  extended by com.orderlysoftware.orderlycalls.base.Service
      extended by com.orderlysoftware.orderlycalls.asterisk.agi.AGIServer
All Implemented Interfaces:
java.lang.Runnable

public class AGIServer
extends Service
implements java.lang.Runnable

AGIServer responds to calls coming from the FastAGI source by opening a socket, and attaching it to a new AGICall object with its own thread.

The AGIConnection object reads the context information sent by the FastAGI source.

The server also instantiates a new instance of a class implementing the AGIProcessor interface (passed in the command line when running stand-alone).

To develop your own applications, simply create a class that implements the AGIProcessor interface (see documentation for that interface).

Author:
Matt King, M.A. Oxon.

Field Summary
 
Fields inherited from class com.orderlysoftware.orderlycalls.base.Service
log
 
Constructor Summary
AGIServer(AGISettings settings)
           
 
Method Summary
 void clean()
          Closes all listening sockets for this AGIServer.
 void freeAGIProcessor(AGIReusableProcessor processor)
          Returns an AGIProcessor to the ObjectPool.
 AGIProcessor getAGIProcessor(java.lang.Class processorClass)
          Gets an AGIProcessor instance.
static AGIServer getInstance(AGISettings settings)
          Calls getInstance(settings, true).
static AGIServer getInstance(AGISettings settings, boolean reuse)
          Calls the Service superclass.
static AGIServer getInstance(java.lang.String name)
          Gets a named AGIServer
 void init()
          Start serving requests.
 boolean isRunning()
          Determines whether this service is active.
static void main(java.lang.String[] args)
          Main method for running stand-alone AGIServers.
 void run()
          Listens for incoming connections, creates a new AGICall object and runs it with the given AGIProcessor in a new thread.
 void shutdown()
          Graceful exit.
 
Methods inherited from class com.orderlysoftware.orderlycalls.base.Service
getExecutorService, getInstance, getInstance, getInstance, getInstanceByName, getLogName, getName, getSettings, setExecutorService, shutdownAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AGIServer

public AGIServer(AGISettings settings)
Method Detail

getInstance

public static AGIServer getInstance(AGISettings settings)
Calls getInstance(settings, true).

Parameters:
settings - The AGISettings object used to initialise the new server.
Returns:
An initialized, running server.

getInstance

public static AGIServer getInstance(AGISettings settings,
                                    boolean reuse)
Calls the Service superclass.

Parameters:
settings - The AGISettings object used to initialise the new server.
reuse - Whether or not to reuse an existing AGIServer, if one can be found.
Returns:
An initialized, running server.

isRunning

public boolean isRunning()
Description copied from class: Service
Determines whether this service is active.

Specified by:
isRunning in class Service
Returns:
true if running, false otherwise.

getInstance

public static AGIServer getInstance(java.lang.String name)
Gets a named AGIServer

Parameters:
name - the name of the AGIServer to get.
Returns:
the AGIServer, or null if none can be found.

shutdown

public void shutdown()
Graceful exit.

All listening sockets are closed.

Specified by:
shutdown in class Service

freeAGIProcessor

public void freeAGIProcessor(AGIReusableProcessor processor)
Returns an AGIProcessor to the ObjectPool.

The processor must implement AGIReusableProcessor.

Parameters:
processor - The processor to free.

getAGIProcessor

public AGIProcessor getAGIProcessor(java.lang.Class processorClass)
Gets an AGIProcessor instance.

Recycles processors from the ObjectPool when possible. AGIProcessors must have a zero-argument constructor.

Parameters:
processorClass - The class of processor to use.
Returns:
an AGIProcessor ready to handle calls.

init

public void init()
Start serving requests.

Specified by:
init in class Service

clean

public void clean()
Closes all listening sockets for this AGIServer.


run

public void run()
Listens for incoming connections, creates a new AGICall object and runs it with the given AGIProcessor in a new thread.

Call shutdown() to stop serving. Sockets are closed on exit automatically.

Specified by:
run in interface java.lang.Runnable

main

public static void main(java.lang.String[] args)
                 throws java.lang.ClassNotFoundException
Main method for running stand-alone AGIServers.
If you want to combine AGI and Manager functionality in a standalone server, have your AGIProcessor object call ManagerClient.getInstance(ManagerSettings settings)

Parameters:
args - processorClassName port
Both optional.
Throws:
java.lang.ClassNotFoundException