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

Discussion in 'Java' started by Shaun Clark, Jun 28, 2003.

  1. Shaun Clark

    Shaun Clark Guest

    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--------
    Shaun Clark, Jun 28, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Saurabh
    Replies:
    6
    Views:
    4,482
    Chris Smith
    May 30, 2004
  2. Rahul
    Replies:
    1
    Views:
    2,514
    Thomas Weidenfeller
    Aug 4, 2005
  3. Replies:
    5
    Views:
    465
    Darryl L. Pierce
    Jan 30, 2006
  4. Kobijoon
    Replies:
    0
    Views:
    1,755
    Kobijoon
    May 9, 2006
  5. Replies:
    0
    Views:
    164
Loading...

Share This Page