Full HTML for

Basic foilset General Tango API Java JavaScript and C

Given by TangoInteractive Team at Tango Tutorial San Diego MRA on June 26 27 98 Datemod;June 26 98. Foils prepared
Outside Index Summary of Material


Java basic API
JavaScript API
Java Object API
C/C++ API
Channel Interface for linking compund applications
TANGOBean Interface described separately

Table of Contents for full HTML of General Tango API Java JavaScript and C

Denote Foils where Image Critical
Denote Foils where Image has important information
Denote Foils where HTML is sufficient

1 TANGO Interactive Tutorial Overview of TANGO API
2 TANGO Interactive APIs - outline
3 Types of TANGO APIs
4 Types of TANGO APIs - continued
5 TANGO Basic API - Overview
6 TANGO event distribution model
7 TANGO API for Java applets
8 TANGO API - AppEventMessage
9 TANGO API Control types
10 HelloWorld for TANGO - Java Applet (1)
11 HelloWorld for TANGO - Java Applet (2)
12 Java API - code example II
13 Java API - code example II Contd
14 Java API - code example II Contd
15 Other TANGO APIs
16 Uses of JavaScript interface to TANGO
17 JavaScript channel interface
18 HelloWorld for TANGO - JavaScript Application
19 JavaScript HelloWorld for TANGO, continued
20 Java Object API
21 Java Object API - description
22 Java Object API -example
23 Sending and Receiving Messages in C
24 Automatic synchronization in TANGO (1)
25 Automatic synchronization in TANGO (2)
26 Automatic synchronization in TANGO (3)
27 Automatic synchronization in TANGO (4)
28 TANGO API for C Applications
29 Registering an Application in C API
30 TANGO Message in C API
31 TANGO C Message (cont.)
32 TANGO C Message (cont.)

Outside Index Summary of Material



HTML version of Basic Foils prepared

Foil 1 TANGO Interactive Tutorial Overview of TANGO API

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Prepared by Marek Podgorny and TANGO Team
Presented by Geoffrey Fox
NPAC, Syracuse University
MRA Meeting June 26-27 1998

HTML version of Basic Foils prepared

Foil 2 TANGO Interactive APIs - outline

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Java basic API
JavaScript API
Java Object API
C/C++ API
Channel Interface for linking compund applications
TANGOBean Interface described separately

HTML version of Basic Foils prepared

Foil 3 Types of TANGO APIs

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
TANGO has an API which is differentiated by language, level of user interface and by functionality
At the highest level, a "TANGOBean" uses JavaBean technology to automate sharing of events with details hidden from user
  • uses IDEs to design collaborative applications
  • TANGOBean implements black box collaboration bus
At the lowest level (at which we start), there is a basic message passing interface for Java, JavaScript, C/C++ and LISP
  • communication primitives only
  • ensures maximum flexibility
  • only way to integrate non-object languages

HTML version of Basic Foils prepared

Foil 4 Types of TANGO APIs - continued

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
At an intermediate level, the Object Interface hides the object serialization needed to get a byte stream from the user (Java and C++)
Finally there is a special Channel Interface for establishing specialized linkages between groups of related shared applications
  • This can be used if for instance one component of an application uses a shared whiteboard. This allows whiteboards to maintain shared state without overall application becoming involved
All APIs are build hierarchically, with message-passing API as root

HTML version of Basic Foils prepared

Foil 5 TANGO Basic API - Overview

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Basic functionality - sending and receiving data
Application calling `send' method puts some information into the system
Information is carried via the TANGO Server to all the applications connected to the same session
When a message arrives the `receive' method is invoked on the destination application
Message distribution is handled automatically and transparently

HTML version of Basic Foils prepared

Foil 6 TANGO event distribution model

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index

HTML version of Basic Foils prepared

Foil 7 TANGO API for Java applets

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
public void register()
  • connects application with the rest of the system; this method should be called during the program startup
public void send (AppEventMessage m)
  • sends information wrapped in a AppEventMessage class through TANGO system
public abstract void receive (AppEventMessage m)
  • callback method called each time a new message arrives; it's implementation is application dependent and has to contain application-specific code for event handling

HTML version of Basic Foils prepared

Foil 8 TANGO API - AppEventMessage

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
AppEventMessage can contain two types of messages:
DATA - information sent between applications in one session
  • examples: a string representing sentence in chat; a list of x,y coordinates describing a figure in paint
CONTROL - system-specific information exchanged between application and Control Application
  • examples: request for list of users or floor control information

HTML version of Basic Foils prepared

Foil 9 TANGO API Control types

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
ISMASTER - request for master/slave status
USERNAME - request for user name
MASTERNAME- request for the name of master
HOSTNAME - request for hostname
PARTICIPANTS - request for list of participants in the current session
ACTIVEUSERS - request for list of users logged into the system
LOCALAPPS - request for the list of applications
DATAPASS - request for data transfer between different applications on the same host

HTML version of Basic Foils prepared

Foil 10 HelloWorld for TANGO - Java Applet (1)

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Let us Construct a Simple Chat application in Java
create any Java class which extends TANGOApplet
  • public JExamp( ) {
  • text = new TextField( );
  • setLayout( new BorderLayout( ) );
  • add( "North", text);
  • }
Now we must add as explained on next foil Collaboratory function for this applet and register it in a TANGO Control Application

HTML version of Basic Foils prepared

Foil 11 HelloWorld for TANGO - Java Applet (2)

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
First add collaboratory functionality to the previous class
  • call send(byte[ ]) when Return pressed
    • if ((evt.target == text) && (evt.id == Event.ACTION_EVENT ))
    • send(stringToBytes(text.getText()));
  • define method receive(byte[] b) when data arrives
    • text.setText(bytesToString(b));
Embed the applet in an HTML page
  • <applet codebase="." archive="tm.jar,JExamp.class" code="JExamp.class" width=280 height=33 mayscript>
  • </applet>
Register the page in a TANGO Control Application

HTML version of Basic Foils prepared

Foil 12 Java API - code example II

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
import messages.*; //TANGO Packages
import interfaces.AppletBase;
import consts.*;
Public class Chat extends AppletBase{//TANGO base class
public void init() {
setLayout(new BorderLayout()); //GUI setup
add("Center",ta=new TextArea());
add("South",tf=new TextField());
register(); //TANGO API call
byte[] t=new byte[1];
t[0] = CAConsts.USERNAME; //creation of TANGO control message
AppEventMessage em=new AppEventMessage
(Const.CONTROL,t);
send(em); //TANGO API call
}

HTML version of Basic Foils prepared

Foil 13 Java API - code example II Contd

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
// TANGO api `receive' implementation
public void receive (AppEventMessage em) {
if (em.getType() == Const.CONTROL) {//check message type
CAppAnswerEventMessage msg = (CAppAnswerEventMessage) em;
//The above is conversion to control message
if (msg.getAnswerType() == CAConsts.USERNAME)
un = msg.getUserName(); //extraction of data
} else { //DATA type message
String msg=new String
(em.getData(),0,0,em.getLen()); //extraction of data
ta.appendText(msg);
}
}

HTML version of Basic Foils prepared

Foil 14 Java API - code example II Contd

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
public boolean action(Event e,Object o) {
if (o instanceof TextField) {
String msg=un+" : "+tf.getText();
byte[] t=new byte[msg.length()];//create byte table
msg.getBytes(0,msg.length(),t,0);//string to byte[]conversion
AppEventMessage em=new AppEventMessage(Const.DATA,t);
// The above is a new message
send(em); //TANGO API call
tf.setText("");
return true;
}
else
return super.action(e,o);
}

HTML version of Basic Foils prepared

Foil 15 Other TANGO APIs

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
C API - used for standalone applications; based on socket connection
  • supports low-level message-passing model
C++ API - encapsulates C API in a set of classes
JavaScript API - similar to Java, messages in form of strings
  • low-level and Channel APIs
  • enables construction of interacting Web pages
Object API - allows more complex operations (e.g. automatic update of state) for Java applets

HTML version of Basic Foils prepared

Foil 16 Uses of JavaScript interface to TANGO

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
For simple JavaScript applications:
  • send(String) / receive(String)
For compound applications:
  • JavaScript code used as a convenient integration environment
  • Supports multiple Java applets and JavaScript functions on one HTML page and in one TANGO session
  • Send/receive augmented by addition of control messages and sharing of general browser events via trapping/rerouting
  • Can build shared HTML forms; Shared Cookies etc.

HTML version of Basic Foils prepared

Foil 17 JavaScript channel interface

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Compound applications, continued:
  • Named channels for different applications
  • Arbitrary messages exchanged between Java applets (fast/scripted assembly of customized applications)
  • String messages used for functions handled directly by JavaScript:
  • sendString( channel, String ) / receiveString( channel, String )
  • Opaque byte arrays used for communicating applets: sendBytes( channel, byte[ ] ) / receiveBytes( channel, byte[ ] )

HTML version of Basic Foils prepared

Foil 18 HelloWorld for TANGO - JavaScript Application

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Chat application in pure HTML illustrates a Shared Form
Can use JavaScript 1.2 event routing mechanisms to automatically track changes in form entries
Open tangoTemplate.html file for editing
Add HTML content at will
  • <form name="chat">
  • <input type="text" name="tty" size=18>
  • <input type="button" value="send">
  • </form>

HTML version of Basic Foils prepared

Foil 19 JavaScript HelloWorld for TANGO, continued

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Add collaboratory functionality
  • call TANGO_send(m) when Send button pressed
    • onclick="TANGO_send(this.form.tty.value"
  • create method TANGO_receive(m) to use when message arrives
    • document.forms.chat.tty.value=m;
Register the application in a TANGO Control Application
JS API is transparent (i.e. pages will work the same way with and w/o TANGO
  • one can make arbitrary web pages interactive

HTML version of Basic Foils prepared

Foil 20 Java Object API

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
O2
O1
O1
O2
Client1
Client2
Object API allows direct communication between corresponding client objects.
  • Simplifies design and implementation
    • Calls to basic API implemented as object methods
  • Provides automatic distribution of initial state
  • All communication logic for an object is located within that object for improved maintainability

HTML version of Basic Foils prepared

Foil 21 Java Object API - description

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
The API consists of the class TNode and an an interface Tobject
Class TNode covers the standard TANGO API. It provides routing mechanisms for messages distributed in the system, so that they are passed only to corresponding TObject on other instances of the Applet
TNode provides methods for
  • registering TObjects
  • building messages
  • accessing general TANGO related information (information about users, sessions, etc.)
TObject interface defines methods called by the TNode when the object is created, a message for that TObject arrives or when the TObject should be discarded.
  • A.K.A. Object Marshalling

HTML version of Basic Foils prepared

Foil 22 Java Object API -example

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
See Server Address/applets/APIExample/
The applet allows adding and moving icons.
Each icon implements a TObject interface.
When icon is added or moved on one instance of the applet the changes are automatically reflected on other instances
When a new client joins the session it automatically receives the current state of the session.

HTML version of Basic Foils prepared

Foil 23 Sending and Receiving Messages in C

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Receiving messages
  • struct Event* receiveEvent(SOCKET s)
    • s - socket to receive a message from
    • returns pointer to received message or NULL
    • if there is no available data, method blocks
Sending messages
  • HRESULT sendEvent( SOCKET s, struct Event* pEv )
    • s - socket to send a message to
    • pEv - message to be sent

HTML version of Basic Foils prepared

Foil 24 Automatic synchronization in TANGO (1)

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Some applications use dynamically created objects which are essentially independent shared entities grouped together
  • existence of which needs to be synchronized
  • which themselves need to pass messages (independently) and be synchronized
Challenges:
  • replicate newly created objects in collaborating applications
  • identify all objects so they can be uniquely addressed
  • synchronize all existing objects (no server support!)
  • translate object references to different namespaces
  • assure integrity of the state across the session participants

HTML version of Basic Foils prepared

Foil 25 Automatic synchronization in TANGO (2)

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Solution for TANGO applets:
  • Synchronizer object implements synchronization logic
  • Updatable interface lets automate synchronization
  • built on the top of the basic TANGO message passing interface
Nota bene: TANGO per design does not use shared objects on the server
  • server design is kept as simple and stateless as possible to enhance system reliability and improve performance

HTML version of Basic Foils prepared

Foil 26 Automatic synchronization in TANGO (3)

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Implementation of the synchronization mechanism:
  • objects that wish to collaborate implement Updatable interface:
    • getStateUpdate(int feature, DataOutputStream update)
    • updateState( int feature, DataInputStream update)
    • feature is a particular feature which is updated
  • when state of an object changes and synchronization is needed, object notifies the synchronization mechanism about the type of change by posting event to the Synchronizer:
    • new UpdateEvent( Updatable this, int feature)
    • special feature values UPDATE_CREATE, UPDATE_DELETE are recognized
  • the rest is taken care by the Synchronizer

HTML version of Basic Foils prepared

Foil 27 Automatic synchronization in TANGO (4)

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Synchronizer tasks:
  • keep database of objects / maintain coherent state across the session
  • issue global IDs for objects / make translations ID-object
  • acquire and send updates / update objects upon receiving updates
Updatable tasks:
  • decide which features shall be updated (at least UPDATE_INIT)
  • implement reading and writing of each feature
  • notify Synchronizer when and which feature has to be updated

HTML version of Basic Foils prepared

Foil 28 TANGO API for C Applications

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Based on socket connections
Provides methods for:
  • registering an application
  • receiving messages from TANGO or other apps
  • sending messages to TANGO or other apps
  • creating/destroying/managing messages

HTML version of Basic Foils prepared

Foil 29 Registering an Application in C API

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Registering an application that uses C runtime library
  • SOCKET registerApp( int argc, char* argv[] )
    • takes program parameters as provided in main(...)
    • returns socket connected to TANGO or INVALID_SOCKET
Registering Win32 application
  • SOCKET registerWinApp( LPSTR lpCmdLine )
    • takes program parameters as provided in WinMain(...)
    • returns socket connected to TANGO or INVALID_SOCKET

HTML version of Basic Foils prepared

Foil 30 TANGO Message in C API

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Attributes
  • type
    • CONTROL: send to Control Application
    • DATA: send to other participating applications
  • len: length of data field
  • data: pointer to actual data
Creation created using createEvent method
  • struct Event* createEvent( int type, int len, char* data )

HTML version of Basic Foils prepared

Foil 31 TANGO C Message (cont.)

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
Destruction
  • to prevent memory leaks, suggested method of deallocating a message is by using destroyEvent method
  • void destroyEvent( struct Event* )
    • it takes care of data field de-allocation
    • uses appropriate destructor

HTML version of Basic Foils prepared

Foil 32 TANGO C Message (cont.)

From General Tango API Java JavaScript and C Tango Tutorial San Diego MRA -- June 26 27 98 Datemod;June 26 98. *
Full HTML Index
int getType (struct Event* pEv)
  • returns type of message (DATA or CONTROL)
int getLen (struct Event* pEv)
  • returns length of data
char* getData (struct Event* pEv)
  • returns pointer to data
  • returned pointer points to newly allocated buffer, this buffer should be freed using C free(...) function

© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Fri Jun 26 1998