sunlabs.brazil.asterisk
Class AsteriskAGIHandler
java.lang.Object
   sunlabs.brazil.template.Template
sunlabs.brazil.template.Template
       sunlabs.brazil.asterisk.AsteriskAGIHandler (view source)
sunlabs.brazil.asterisk.AsteriskAGIHandler (view source)
- All Implemented Interfaces: 
- Runnable, Handler, TemplateInterface
- public class AsteriskAGIHandler 
- extends Template- implements Handler, Runnable
FAGI (fast AGI) handler and template for Asterisk.  
 This handler/template starts a server listening on the * FAGI port.
 Anytime it gets an agi request from * it creates a dummy
 request object (sort of like TestRequest) to simulate an http
 request, reads a file implied by the request agi:... string, and
 processes the file through the template runner.
 The  template can be used to interact with * via
 standard agi commands, and the web via the SetTemplate and namespaces.
 The template output is discarded (if debug is enables, it is printed on
 the server console); everything is done via side effect.
 This allows us to interact with the ordinary template variables and
 namespaces.
 I'm still not sure how to deal with sessions, so we'll use a 
 different one for each uniqueid in the agi request. (This is a bad idea
 unless we delete completed sessions "by hand").
(Implementation notes)
 This class implements 4 different threads:
 - handler/init: to get the config params and start the listening socket
 - The thread that listens and accepts connections from *
 - the threads that handle the incoming agi requests
 - the threads that do the template  stuff
 
| Fields inherited from class sunlabs.brazil.template.Template | 
| debug | 
 
 
| Method Summary | 
|  boolean | done(RewriteContext hr)Close the socket connection.
 | 
|  boolean | init(RewriteContext hr)Open the socket's streams at top of page.
 | 
|  boolean | init(Server server,
     String prefix)Start a Listening socket thread, and wait for AGI connections.
 | 
|  boolean | respond(Request request)We don't handle any "normal" requests.
 | 
|  void | run()Either start a listening socket or handle an AGI request.
 | 
|  void | tag_agi(RewriteContext hr)Provide the 'agi' tag.
 | 
 
 
AsteriskAGIHandler
public AsteriskAGIHandler()
init
public boolean init(Server server,
                    String prefix)
- Start a Listening socket thread, and wait for AGI connections.
 
- 
- Specified by:
- initin interface- Handler
 
- 
- Parameters:
- server- The HTTP server that created this- Handler.
                Typical- Handlers will use- Server.propsto obtain run-time configuration information.
- prefix- The handlers name.
                The string this- Handlermay prepend to all
                of the keys that it uses to extract configuration information
                from- Server.props.  This is set (by the- Serverand- ChainHandler) to help avoid configuration parameter
                namespace collisions.
- Returns:
- trueif this- Handlerinitialized
                successfully,- falseotherwise.  If- falseis returned, this- Handlershould not be used.
 
respond
public boolean respond(Request request)
                throws IOException
- We don't handle any "normal" requests.
 
- 
- Specified by:
- respondin interface- Handler
 
- 
- Parameters:
- request- The- Requestobject that represents the HTTP
                request.
- Returns:
- always false
- Throws:
- IOException- if there was an I/O error while sending the response to
                the client.  Typically, in that case, the- Serverwill (try to) send an error message to the client and then
                close the client's connection.- 
                The - IOExceptionshould not be used to silently
                ignore problems such as being unable to access some
                server-side resource (for example getting a- FileNotFoundExceptiondue to not being able
                to open a file).  In that case, the- Handler's
                duty is to turn that- IOExceptioninto a
                HTTP response indicating, in this case, that a file could
                not be found.
 
 
init
public boolean init(RewriteContext hr)
- Open the socket's streams at top of page.
  This will be used by the <agi> calls.
 
- 
- Specified by:
- initin interface- TemplateInterface
- Overrides:
- initin class- Template
 
- 
 
done
public boolean done(RewriteContext hr)
- Close the socket connection.
 
- 
- Specified by:
- donein interface- TemplateInterface
- Overrides:
- donein class- Template
 
- 
 
tag_agi
public void tag_agi(RewriteContext hr)
- Provide the 'agi' tag.
 <agi command="agi command">
 The result is placed in "agi_result".
 NOTE: the thread running this instance doesn't set 
 any of the instance variables.  We get everything from "hr".
 
- 
 
- 
 
run
public void run()
- Either start a listening socket or handle an AGI request.
 
- 
- Specified by:
- runin interface- Runnable
 
-