Asterisk-java ami2 event listening, asterisk-javaami2
AsteriskServer article 1 does not explain how to obtain it.
AsteriskServer. addChainListener (new AsteriskeventListenerInit (); // monitors the events of the entire service and adds a listener to this service.
By implementing the ManagerEventListener class,
Public class AsteriskeventListenerInit implements ManagerEventListener {
@ Override
Public void onManagerEvent (ManagerEvent event ){
Here we can get the parameters returned by the event. The Retrieval type can be used to open the api documentation.
Domo:
// Return the sip Extension termination event
} Else if (event instanceof PeerlistCompleteEvent ){
PeerlistCompleteEvent perrs = (PeerlistCompleteEvent) event;
MapCacheUtil Instance = MapCacheUtil. getInstance ();
If (perrs. getActionId ()! = Null ){
Instance. putPerrsList (perrs. getActionId (), Instance. getPerrs (perrs. getActionId (); // get the end of the entire event
}
// The sip Extension Information event is returned.
} Else if (event instanceof PeerEntryEvent ){
PeerEntryEvent pentry = (PeerEntryEvent) event;
Mapcache. putExtensions (pentry. getObjectName (); // the container that stores all extensions. This container is used to determine whether an extension is needed.
If (pentry! = Null & pentry. getStatus ()! = Null ){
If (pentry. getStatus (). contains ("OK ")&&! String. valueOf (pentry. getPort (). equals ("0 ")){
List actionidoldList = mapcache. getActionId ();
If (actionidoldList! = Null ){
For (int I = 0; I <actionidoldList. size (); I ++ ){
String actionid = pentry. getActionId ();
If (! ToolUtils. checkNull (actionid) & actionid. equals (actionidoldList. get (I ))){
If (ToolUtils. isInteger (pentry. getObjectName () {// if the extension number is numeric
Mapcache. putPerrs (actionid, pentry. getObjectName ());
}
}
}
}
Perrlist. add (pentry. getObjectName ());
}
}
// The host information event is returned.
} Else if (event instanceof HangupEvent ){
HangupEvent hangup = (HangupEvent) event;
New WebSocket (). broadcast ("websocket" + BaseUtil. getnumber (hangup. getChannel (), "reason for hanging up:" + BaseUtil. getHangup (Integer. valueOf (hangup. getCause ()). intValue ()));
// Extension status change event
} Else if (event instanceof ExtensionStatusEvent ){
ExtensionStatusEvent extensionstatus = (ExtensionStatusEvent) event;
JSONObject jsono = new JSONObject ();
Jsono. put ("id", extensionstatus. getExten ());
Jsono. put ("statusname", BaseUtil. getExtensionState (extensionstatus. getStatus ()));
New WebSocket (). broadcastAll (jsono );
// Temporary call reservation event
} Else if (event instanceof ParkedCallEvent ){
ParkedCallEvent parkcall = (ParkedCallEvent) event;
String key = BaseUtil. getnumber (parkcall. getFrom ());
Key + = BaseUtil. CHANNELPARK_CENTENT;
Mapcache. put (key, parkcall. getExten ());
// Obtain Database Data Events
} Else if (event instanceof DbGetResponseEvent ){
DbGetResponseEvent dbget = (DbGetResponseEvent) event;
} Else if (event instanceof DisconnectEvent ){
DisconnectEvent disconn = (DisconnectEvent) event;
System. out. println ("triggered when an asterisk connection failure event occurs:" + disconn );
// All returned events are written at the end.
} Else if (event instanceof ResponseEvent ){
ResponseEvent response = (ResponseEvent) event;
}
}
}