|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsunlabs.brazil.template.Template
sunlabs.brazil.asterisk.AsteriskHandler (view source)
public class AsteriskHandler
Connect to asterisk manager api. There is one connection per server. This is used both to issue Commands to Asterisk via the manager interface, and to register for, and receive asynchronous event notifications.
Usage:
<register queue=xxx key=xxx pattern=xxx [context=xxx server=xxx]> - register interest in a manager event (or events). All generated events will be available with <dequeue name=xxx ...>, where the "name" parameter of the <dequeue> matches the "queue" parameter of <register>. <unregister queue=xxx key=xxx> - unregister interest in a previously registered event. <enqueue name="queue" from="my-q" ...> - Send an command to the manager interface. "queue" is the name specified in the handler "queue" parameter. The enqueue'd data must have an "action" key. The result of the command is obtained by: <dequeue name="my-q" ...> where "my-q" is the "from" attribute of the corrosponding <enqueue> <amicommand server=xxx action=xxx ...> - A syncronous version of the <enqueue> ... <dequeue> above. See below for details.
Nested Class Summary | |
---|---|
static class |
AsteriskHandler.AmiStringMap
This class is built on top of the StringMap class and adds methods for reading Asterisk ManagerInterface replies. |
static class |
AsteriskHandler.EventItem
Keep track of an event listener entry. |
static class |
AsteriskHandler.Events
Class to manage the set of events. |
Field Summary |
---|
Fields inherited from class sunlabs.brazil.template.Template |
---|
debug |
Constructor Summary | |
---|---|
AsteriskHandler()
|
Method Summary | |
---|---|
static void |
addEvent(String queue,
String key,
String exp,
String context,
String serverName)
Java access to adding event registrations. |
boolean |
init(Server server,
String prefix)
Remember the host, port, id, and password for an asterisk manager connection. |
static int |
removeEvents(String queue,
String key,
String exp)
java access to removing event registrations. |
boolean |
respond(Request request)
The handler only registers * servers. |
void |
tag_amicommand(RewriteContext hr)
Issue a synchronous command to the Asterisk AMI interface. |
void |
tag_asterisk(RewriteContext hr)
This only emits diagnostic information to stdout. |
void |
tag_register(RewriteContext hr)
Register an event. |
void |
tag_unregister(RewriteContext hr)
Unregister an event (or events). |
Methods inherited from class sunlabs.brazil.template.Template |
---|
done, init |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AsteriskHandler()
Method Detail |
---|
public boolean init(Server server, String prefix)
When using multiple servers, only one of the server handler configurations should be listed as a template (there can only be one template instance for a given entity) which server doesn't matter, as events get registered for all servers (the "server" attribute of the response determines where it came from). As above, commands to a server are distinquished with either the "queue" or "server" attributes, depending on whether the command Qs are used directly, or the <amicommand> template is used.
To Do
Figure out where to send unregistered events, such as "reload".
init
in interface Handler
server
- The HTTP server that created this Handler
.
Typical Handler
s will use Server.props
to obtain run-time configuration information.prefix
- The handlers name.
The string this Handler
may prepend to all
of the keys that it uses to extract configuration information
from Server.props
. This is set (by the Server
and ChainHandler
) to help avoid configuration parameter
namespace collisions.
true
if this Handler
initialized
successfully, false
otherwise. If
false
is returned, this Handler
should not be used.public boolean respond(Request request) throws IOException
respond
in interface Handler
request
- The Request
object that represents the HTTP
request.
true
if the request was handled. A request was
handled if a response was supplied to the client, typically
by calling Request.sendResponse()
or
Request.sendError
.
IOException
- if there was an I/O error while sending the response to
the client. Typically, in that case, the Server
will (try to) send an error message to the client and then
close the client's connection.
The IOException
should not be used to silently
ignore problems such as being unable to access some
server-side resource (for example getting a
FileNotFoundException
due to not being able
to open a file). In that case, the Handler
's
duty is to turn that IOException
into a
HTTP response indicating, in this case, that a file could
not be found.
public void tag_asterisk(RewriteContext hr)
public void tag_amicommand(RewriteContext hr)
Attributes:
public void tag_register(RewriteContext hr)
<register queue=xxx key=xxx exp=xxx [context=xxx server=xxx]> queue: The Q name to send the results to. key: The manager response key to match on. Use "*" for all keys. exp: A regular expression that matches a key value context: If specified, only events with this context are considered. server: If specified, only events from this server are considered. The server matches the "Server" item in the event, and is the server name, followed by a ":", then the port number (e.g. pbx.com:5038).
public static void addEvent(String queue, String key, String exp, String context, String serverName)
public void tag_unregister(RewriteContext hr)
public static int removeEvents(String queue, String key, String exp)
|
Version Kenai-svn-r24, Generated 08/18/09 Copyright (c) 2001-2009, Sun Microsystems. |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |