[Asterisk-java-users] Support for EventGeneratingActions in Asterisk-Java CVS-HEAD
Brought to you by:
srt
From: Stefan R. <sr...@re...> - 2005-07-17 01:03:21
|
Hi, I just finished to implement support for what I call EventGeneratingActions in Asterisk-Java. Let me explain what that means. The problem: An increasing number of Actions in Asterisk's Manager API doesn't send their result in the Response but generate a series of Events that contain the payload. An old example of this is the StatusAction. It sends a Response indicating success and a StatusEvent for each active channel and finally a StatusCompleteEvent to indicate that all StatusEvents have been sent. This concept is also used in newer Actions in Asterisk CVS-HEAD like the AgentsAction or the DBGetAction. The concept is always the same: =3D> send action <=3D receive response (only indicating success) <=3D receive events <=3D receive action complete event The Events are linked to the Action that generated them by a common actionId attribute. The problem is that when using Asterisk-Java processing these Actions has been a nightmare. You had to register an event handler, send the Action and instruct the event handler to collect the corresponding events and finally put them together. An example of this nightmare is the initialize phase in DefaultAsteriskManager in Asterisk-Java 0.1. The solution: Now Asterisk-Java provides support for EventGeneratingActions at ManagerConnection level. There is a new EventGeneratingAction interface that is implemented by all ManagerAction classes that result in events being sent. It extends the ManagerAction interface by a method called getActionCompleteEventClass() that returns the class of the event that indicates completion. The ManagerConnection interface now includes two synchronous sendEventGeneratingAction() methods that return the Response and all Events that have been received in response to the Action. If you are interested have a look at the latest snapshot of Asterisk-Java available at=20 http://maven.reucon.com/maven/asterisk-java/distributions/ or browse the updated Asterisk-Java sources at http://asterisk-java.sourceforge.net/xref/index.html The latest implementation of DefaultAsteriskManager already uses this new feature of ManagerConnection and is much cleaner now. A little hack (see EventTimeoutException in net.sf.asterisk.manager if you are interested) also solves the queue initialization problem in DefaultAsteriskManager with buggy (i.e. current stable) Asterisk servers. =3DStefan |