Cisco CallManager 3.3 JTAPI - Putting a routed call on hold if no one is avaliable

S

Shaun Clark

Hello,

Currently I am trying to use the below to route calls for a
particular address, this thread is spawned by the main CallEngine for
each routeable address. What I want to do is check to see if some is
avaliable, which I do using a database call or a ReRoute event, either
case, when I determine that no one is avaliable I want to stick the
call in a hold state and pick it back up sometime later. Anyone know
how to do this? Thanks.

S-Dog



------BEGIN CODE-------
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import sun.jdbc.odbc.*;

//telephony imports
import javax.telephony.*;
import javax.telephony.callcenter.*;
import javax.telephony.callcontrol.*;
import javax.telephony.callcenter.events.*;
import javax.telephony.events.*;
import com.cisco.cti.util.Condition;
import javax.telephony.capabilities.*;
import com.cisco.jtapi.extensions.CiscoAddress;
import com.cisco.jtapi.extensions.CiscoTerminal;
import MasterObserver;


/*
the idea is that this thread represents ONE CTI route point
and is responsible for all routing for that address
depending on future load, we may need to thread in
a different way, but for now we will try this method
*/


public class callRouteThread extends Thread implements RouteCallback {
private static MasterObserver theObserver; //the observer that
observes all
private static CallCenterProvider myprovider; //a provider reference
private static String providerString =
"IP_Address;login=username;passwd=password";
private static RouteAddress myRouteAddress; //this is the address
we are routing for

//sql stuff
String sqltext;
java.sql.Connection sqlConn; //sql server connection
Statement sqlStatement;

//random smack variables
Random rand;

// main constructor
public callRouteThread(RouteAddress routeAddress) {
myRouteAddress = routeAddress;

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //can I do this
up here?
sqlConn = DriverManager.getConnection("jdbc:eek:dbc:IP_Address","username","password");
//sqlConn.setCatalog("db"); //change the database
sqlStatement = sqlConn.createStatement();
} catch (Exception exp) {
System.out.println("We had some sql trouble:" + exp.toString());
}
rand = new Random();

}

//run method as required when extending the thread class
public void run() {
init(); //sets up some stuff we need later
try {
// register callback to route calls for myRouteAddress
myRouteAddress.registerRouteCallback(this);
myRouteAddress.addObserver(theObserver);
} catch (Exception e) {
System.out.println("can't register call back to route calls for
myRouteAddress:" + e.toString() );
System.exit(0);
}
}

//get a reference to the provider
public static void init() {
System.out.println("Calling Main");
try {
JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);
myprovider = (CallCenterProvider)
peer.getProvider(providerString);
} catch (Exception excp) {
System.out.println("Can't get Provider: " + excp.toString());
System.exit(0);
}
}

public void routeEvent(RouteEvent event) {
System.out.println("Got routeEvent");
// call function todetermine a destination
String[] routeSelected = new String[1];
routeSelected[0] = new
String(getRoute((Terminal)event.getCallingTerminal(),(Address)event.getCurrentRouteAddress()));
try {
event.getRouteSession().selectRoute(routeSelected);
Address tempAddress =
(Address)event.getCurrentRouteAddress();

System.out.println("Adding Address Observer to " +
tempAddress.getName());
tempAddress.addObserver(theObserver);

System.out.println("Adding Call Observer to this
address");
tempAddress.addCallObserver(theObserver);
}
catch (Exception e) {
System.out.println("exception occured");
return;
}
return;
}

public void reRouteEvent(ReRouteEvent event) {
System.out.println("Got reRouteEvent");
// previous routeSelected did not work, ok
// just pick some default route, audix "77777"
String[] routeSelected = new String[1];
routeSelected[0] = new String("2010");
try {
event.getRouteSession().selectRoute(routeSelected);
}
catch (Exception e) {
System.out.println("exception occured");
return;
}
}

public void routeUsedEvent(RouteUsedEvent event) {
System.out.println("Got routeUsedEvent");
// do something
}

public void routeEndEvent(RouteEndEvent event) {
System.out.println("Got routeEndEvent");
// session is over, clear up any objects, data, threads
// associated with this session
}

public void routeCallbackEndedEvent(RouteCallbackEndedEvent event)
{
System.out.println("Got routeCallbackEndedEvent");
// callback has been terminated, clear up any objects, data,
// threads associated with this callback
}

public String getRoute(Terminal callingTerminal, Address
currentRouteAddress) {
System.out.println("Got getRoute");
String returnAddress = "";

try {
Terminal[] tempTerminals = myRouteAddress.getTerminals();
CallControlTerminal tempTerminal = (CallControlTerminal)
callingTerminal;
TerminalConnection[] tempTermConns =
tempTerminal.getTerminalConnections();
CallControlTerminalConnection CCTC =
(CallControlTerminalConnection) tempTermConns[0];
CCTC.hold();

} catch (Exception exp) {
System.out.println("Caught exception: " + exp.toString());
}

// look up some database to determine a destination
// based on callingTerminal and currentRouteAddress
String orderBy = "";

// Random integers
int i = rand.nextInt(6);
System.out.println("Random Number:" + i);

sqltext = "select top 1 phoneExtension from CTI.dbo.users
where userclass = 'csr' and phoneExtension is not null and
phoneExtension <> ''";

try {
if (sqlStatement == null) {
System.out.println("NULL STATEMENT");
}

ResultSet victimList = sqlStatement.executeQuery(sqltext);
System.out.println("Calling Next");
if (victimList.next()) {
System.out.println("Getting return Address");
returnAddress = victimList.getString("phoneExtension");
System.out.println("Closing the connection");
victimList.close();
} else {
System.out.println("We got a null result set");
}

} catch (Exception exp) {
System.out.println("We couldn't do the SELECT for some reason:" +
exp.toString());
System.exit(0);
}

//old weird code that I need to look at before I delete
try {
//System.out.println("Getting CiscoAddress from the return
address");
//CiscoAddress tempAddress = (CiscoAddress)
myprovider.getAddress(returnAddress);

//System.out.println("Adding Address Observer to " +
tempAddress.getName());
//tempAddress.addObserver(theObserver);

//System.out.println("Adding Call Observer to this
address");
//tempAddress.addCallObserver(theObserver);

//System.out.println("Adding Call Observer to this
address");
//currentRouteAddress.addCallObserver(theObserver);
//currentRouteAddress.addObserver(theObserver);
} catch (Exception excp) {
System.out.println(excp.toString());
System.exit(0);
}
System.out.println("Returning " + returnAddress);
//return (returnAddress);
return "2010";
}
}
------END CODE--------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top