Table Of Contents
Cisco JTAPI Examples
Introduction
makecall.java
Actor.java
Originator.java
Receiver.java
StopSignal.java
Trace.java
TraceWindow.java
Running makecall
Invoking makecall
On the client workstation
Cisco JTAPI Examples
Introduction
This chapter provides the source code for makecall, the Cisco JTAPI program used to test the JTAPI installation. The makecall program is comprised of a series of programs written in Java using the Cisco JTAPI implementation.
This chapter contains the following sections:
•
makecall.java
•
Actor.java
•
Originator.java
•
Receiver.java
•
StopSignal.java
•
Trace.java
•
TraceWindow.java
This Chapter also provides instructions on how to invoke makecall:
•
Running makecall
makecall.java
* Copyright Cisco Systems, Inc.
* Performance-testing application (first pass) for Cisco JTAPI
* Due to synchronization problems between Actors, calls may
* not be cleared when this application shuts down.
import javax.telephony.*;
import javax.telephony.events.*;
import com.cisco.cti.util.Condition;
public class makecall extends TraceWindow implements ProviderObserver {
Vector actors = new Vector ();
Condition conditionInService = new Condition ();
public makecall ( String [] args ) {
this.setText ( "makecall" );
println ( "Initializing Jtapi" );
String providerName = args[curArg++];
String login = args[curArg++];
String passwd = args[curArg++];
int actionDelayMillis = Integer.parseInt ( args[curArg++] );
JtapiPeer peer = JtapiPeerFactory.getJtapiPeer ( null );
if ( curArg < args.length ) {
String providerString = providerName + ";login=" + login + ";passwd=" +
passwd;
println ( "Opening " + providerString + "...\n" );
Provider provider = peer.getProvider ( providerString );
provider.addObserver ( this );
conditionInService.waitTrue ();
println ( "Constructing actors" );
for ( ; curArg < args.length; curArg++ ) {
new Receiver ( provider.getAddress ( dest ), this,
actionDelayMillis )
new Originator ( provider.getAddress ( src ), dest, this,
actionDelayMillis )
println ( "Skipping last originating address \"" + src + "\"; no
destination specified" );
new Receiver ( provider.getAddress ( dest ), this, actionDelayMillis )
new OriginateNoDrop ( provider.getAddress ( args[curArg++] ), dest,
this, actionDelayMillis )
new OriginateNoDrop ( provider.getAddress ( args[curArg++] ),
args[curArg++], this, actionDelayMillis )
println ( "Starting actors" );
Enumeration e = actors.elements ();
while ( e.hasMoreElements () ) {
Actor actor = (Actor) e.nextElement ();
println ( "Caught exception " + e );
println ( "Stopping actors" );
Enumeration e = actors.elements ();
while ( e.hasMoreElements () ) {
Actor actor = (Actor) e.nextElement ();
public static void main ( String [] args ) {
System.out.println ( "Usage: makecall <server> <login> <password> <delay>
<origin> <destination> ..." );
Application.run (new makecall ( args ));
public void providerChangedEvent ( ProvEv [] eventList ) {
if ( eventList != null ) {
for ( int i = 0; i < eventList.length; i++ ) {
if ( eventList[i] instanceof ProvInServiceEv ) {
conditionInService.set ();
Actor.java
* Copyright Cisco Systems, Inc.
import javax.telephony.*;
import javax.telephony.events.*;
import javax.telephony.callcontrol.*;
import javax.telephony.callcontrol.events.*;
public abstract class Actor implements CallControlCallObserver, Trace {
private int actionDelayMillis;
public Actor ( Trace trace, Object observed, int actionDelayMillis ) {
this.observed = observed;
this.actionDelayMillis = actionDelayMillis;
public final void start () {
if ( observed != null ) {
if ( observed instanceof Terminal ) {
"Adding Call observer to terminal "
+ ((Terminal)observed).getName ()
((Terminal)observed).addCallObserver ( this );
else if ( observed instanceof Address ) {
"Adding Call observer to address "
+ ((Address)observed).getName ()
((Address)observed).addCallObserver ( this );
else if ( observed instanceof Call ) {
"Adding Call observer to call "
((Call)observed).addObserver ( this );
throw new Exception ( "Object " + observed + " is not observable;
no observation is possible" );
println ( "Caught exception " + e );
public final void stop () {
if ( observed != null ) {
if ( observed instanceof Terminal ) {
"Removing Call observer from terminal "
+ ((Terminal)observed).getName ()
((Terminal)observed).removeCallObserver ( this );
else if ( observed instanceof Address ) {
"Removing Call observer from address "
+ ((Address)observed).getName ()
((Address)observed).removeCallObserver ( this );
else if ( observed instanceof Call ) {
"Removing Call observer from call "
((Call)observed).removeObserver ( this );
throw new Exception ( "Object " + observed + " is not observable;
no observation needs removal" );
println ( "Caught exception " + e );
public final void callChangedEvent ( CallEv [] events ) {
// for now, all metaevents are delivered in the
final void delay ( String action ) {
if ( actionDelayMillis != 0 ) {
println ( "Pausing " + actionDelayMillis + " milliseconds before " + action );
Thread.sleep ( actionDelayMillis );
catch ( InterruptedException e ) {}
protected abstract void metaEvent ( CallEv [] events );
protected abstract void onStart ();
protected abstract void onStop ();
public final void print ( String string ) {
public final void print ( char character ) {
trace.print ( character );
public final void print ( int integer ) {
public final void println ( String string ) {
trace.println ( string );
public final void println ( char character ) {
trace.println ( character );
public final void println ( int integer ) {
trace.println ( integer );
public final void flush () {
Originator.java
* Copyright Cisco Systems, Inc.
import javax.telephony.*;
import javax.telephony.events.*;
import javax.telephony.callcontrol.*;
import javax.telephony.callcontrol.events.*;
public class Originator extends Actor {
public Originator ( Address srcAddress, String destAddress, Trace trace, int
actionDelayMillis ) {
super ( trace, srcAddress, actionDelayMillis ); // observe srcAddress
this.srcAddress = srcAddress;
this.destAddress = destAddress;
protected final void metaEvent ( CallEv [] eventList ) {
for ( int i = 0; i < eventList.length; i++ ) {
CallEv curEv = eventList[i];
if ( curEv instanceof CallCtlTermConnTalkingEv ) {
TerminalConnection tc =
((CallCtlTermConnTalkingEv)curEv).getTerminalConnection ();
Connection conn = tc.getConnection ();
if ( conn.getAddress ().getName ().equals ( destAddress ) ) {
delay ( "disconnecting" );
println ( "Disconnecting Connection " + conn );
else if ( curEv instanceof CallCtlConnDisconnectedEv ) {
Connection conn = ((CallCtlConnDisconnectedEv)curEv).getConnection ();
if ( conn.getAddress ().equals ( srcAddress ) ) {
println ( "Caught exception " + e );
protected void makecall ()
throws ResourceUnavailableException, InvalidStateException,
PrivilegeViolationException, MethodNotSupportedException,
InvalidPartyException, InvalidArgumentException {
delay ( "making the next call" );
println ( "Making call #" + ++iteration + " from " + srcAddress + " to " +
destAddress );
Call call = srcAddress.getProvider ().createCall ();
call.connect ( srcAddress.getTerminals ()[0], srcAddress, destAddress );
println ( "Done making call" );
protected final void onStart () {
stopSignal = new StopSignal ();
println ( "Caught exception " + e );
protected final void onStop () {
Receiver.java
* Copyright Cisco Systems, Inc.
import javax.telephony.*;
import javax.telephony.events.*;
import javax.telephony.callcontrol.*;
import javax.telephony.callcontrol.events.*;
public class Receiver extends Actor {
public Receiver ( Address address, Trace trace, int actionDelayMillis ) {
super ( trace, address, actionDelayMillis );
protected final void metaEvent ( CallEv [] eventList ) {
for ( int i = 0; i < eventList.length; i++ ) {
TerminalConnection tc = null;
CallEv curEv = eventList[i];
if ( curEv instanceof CallCtlTermConnRingingEv ) {
tc = ((CallCtlTermConnRingingEv)curEv).getTerminalConnection ();
println ( "Answering TerminalConnection " + tc );
println ( "Caught exception " + e );
println ( "tc = " + tc );
protected final void onStart () {
stopSignal = new StopSignal ();
protected final void onStop () {
StopSignal.java
* Copyright Cisco Systems, Inc.
boolean stopping = false;
synchronized boolean isStopped () {
synchronized boolean isStopping () {
synchronized void stop () {
catch ( InterruptedException e ) {}
synchronized void canStop () {
Trace.java
* Copyright Cisco Systems, Inc.
public void print ( String string );
public void print ( char character );
public void print ( int integer );
public void println ( String string );
public void println ( char character );
public void println ( int integer );
TraceWindow.java
* Copyright Cisco Systems, Inc.
import com.ms.wfc.core.*;
import com.ms.wfc.html.*;
import com.ms.win32.User32.*;
public class TraceWindow extends Form implements Trace {
boolean traceEnabled = true;
StringBuffer buffer = new StringBuffer ();
// Required for Visual J++ Form Designer support
private void updateSize () {
Point dimensions = getSize ();
Rectangle bounds = new Rectangle ( 0, 1, dimensions.x, dimensions.y );
text.setBounds ( bounds );
* MyTextArea overrides dispose so it can clean up the
private void MyTextArea_layout(Object source, LayoutEvent e) {
* NOTE: The following code is required by the Visual J++ form
* designer. It can be modified using the form editor. Do not
* modify it using the code editor.
Container components = new Container();
RichEdit text = new RichEdit();
private void initForm() {
this.setAutoScaleBaseSize(new Point(5, 13));
this.setClientSize(new Point(374, 245));
this.addOnLayout(new LayoutEventHandler(this.MyTextArea_layout));
text.setFont(Font.DEFAULT_GUI);
text.setForeColor(Color.WINDOWTEXT);
text.setLocation(new Point(8, 8));
text.setSize(new Point(360, 232));
text.setScrollBars(RichEditScrollBars.BOTH);
this.setNewControls(new Control[] {
public final void print ( String str ) {
public final void print ( char character ) {
buffer.append ( character );
public final void print ( int integer ) {
buffer.append ( integer );
public final void println ( String str ) {
public final void println ( char character ) {
public final void println ( int integer ) {
public final void setTrace ( boolean traceEnabled ) {
this.traceEnabled = traceEnabled;
public final void flush () {
text.invoke ( new MethodInvoker ( setSelText ) );
final void setSelText () {
if ( buffer.length () > 0 ) {
text.setSelText ( buffer.toString () );
if ( buffer.length () > 0 ) {
text.sendMessage ( wine.EM_SCROLLCARET, 0, 0 );
buffer = new StringBuffer ();
public final void clear () {
Running makecall
Invoking makecall
On the client workstation
From the Windows NT command line, navigate to the makecall directory where JTAPI Tools directory was installed and execute the following command:
jview makecall <server name> <login> <password> 1000 <device 1> <device2>
<server name> is the hostname or IP address of your Cisco CallManager and <device1> <device2> are directory numbers of IP phones. The phones must be part of the associated devices of a given user as administered in the Cisco CallManager's directory administration web page. The <logic> and <password> are similarly as administered in the directory. This will test that you have installed and configured everything correctly. The application will make calls between the two devices with an action delay of 1000 msecs until terminated.