CSTA Simple Example - explaining the download example
Here is an explanation of the CSTA Simple Example that is available for download from the February 1, 2010 snapshot. It is aimed at a Hipath 3000 PBX connected to the opencsta server with a network connection. This client connects to that server.
1. main()
Load some properties from a file.
Create SimpleExample object.
public static void main(String[] args) {
System.out.println(System.getProperty("file.encoding")) ;
System.setProperty("file.encoding", "ISO-8859-1") ;
System.out.println(System.getProperty("file.encoding")) ;
Properties someProps = loadPropertiesFromFile() ;
SimpleExample app = new SimpleExample(someProps) ;
app.run() ;
}
2. SimpleExample constructor
public SimpleExample(Properties _theProps){
this.theProps = _theProps ;
csta = new CSTAMulti(this,theProps) ;
cstaThread = new Thread(csta,"CSTA Thread") ;
cstaThread.start();
}
The constructor accepts some properties that were loaded.
CSTAMulti object is instantiated passing this which implements CSTAApplication. CSTAMulti only accepts implementations of CSTAApplication so you must implement it.
The CSTAMulti object is given it's own thread - you would do something like this in a GUI app.
Within the CSTAMulti object, it parses the properties it is passed. These are things like where the CSTA Server is (address:port) and whether to convert DLE characters (0x10) to DLE DLE (0x10 0x10) and vice versa during client/server communications. A Siemens PBX requires double DLE, and Ericsson connected with AppLink does not.
3. SimpleExample run()
public void run() {
getMonitoredExtensions() ;
setRunFlag(true) ;
for( int i = 0 ; i < monitorThese.length ; i++ ){
csta.MonitorStart(monitorThese[i]);
}
while( isRunFlag() ){
try{
synchronized(this){
wait(2000) ;
}
} catch (InterruptedException ex) {
}
}
try{
//shutdown or something like that.
}catch(Exception e){
e.printStackTrace() ;
}
}
Get the list of extensions to monitor. This is configured for SimpleExample in the configuration file simpleexample.conf using the property MONITORSTARTS. The getMonitoredExtensions() function just parses the value.
The app then waits for 2000ms for something to do. It is here you would let the CSTAMulti thread interrupt your app to possibly update a GUI or something.
4. Handling CSTA Events - e.g. Service Initiated, Connection Cleared, Originated, Delivered etc
public void CSTACallEventReceived(CallEvent event) {
alog.info(event.toString()) ;
}
Every CSTAApplication implementation must implement 4 methods. One is CSTACallEventReceived(CallEvent event). In this example, it simple logs the event to the log4j logger.
You will usually need to cast the CallEvent to it's specific type
e.g.
if( event instanceof ConnectionCleared){
ConnectionCleared cc_event = (ConnectionCleared)event ;
cc_event.getCause() ;
cc_event.get_releasingDevice() ;
}
For now, the code only allows for toString for the events. The cc_event functions listed here will be implemented this month.
I hope this explains the flow of the example application to you,
Cheers
Chris
