import webwisdom.tango.*;
There is one TAgent per application. Application must create its own TAgent:public class TAgent { public TAgent(TLAgent agent); public void exit(); public String getUserName(); public boolean isMaster(); public String getMasterName(); public String[] getParticipantNames(); public boolean isAudioAvailable(); public void send(byte[] data); public void selectiveSend(String[] participantNames,byte[] data); public void addTControlListener(TControlListener l); public void removeTControlListener(TControlListener l); public void addTDataListener(TDataListener l); public void removeTDataListener(TDataListener l); }
TAgent provides methods for acquiring asynchronuosly certain system information:TAgent agent=new TAgent(/*params*/);
Creating TAgent for applets can be coded as follows:public class TLAgentApplet implements TLAgent { public TLAgentApplet(Applet app) throws TangoException; }
public class AnApplet extends Applet { public void init() { try { TAgent agent=new TAgent(new TLAgentApplet(this)); } catch(TangoException e) { //cannot connect to Tango } } }
public interface TDataListener { public void receive(byte[] data); }
public interface TControlListener { public void masterChanged(boolean isMaster,String masterName); public void participantJoined(String participantName); public void participantLeft(String participantName); public void audioRequested(boolean isRequested); }
Reception of the private session data is implemented in the similar fashion:class AnApplication implements TControlListener { TAgent agent; agent.addTControlListener(this); //implementation of TControlListener interface }
orclass AnApplication implements TDataListener { TAgent agent; agent.addTDataListener(this); //implementation of TDataListener interface follows }
class AnApplication { TAgent agent; TDataListener listener; agent.addTDataListener(listener); }
import java.awt.*; import java.applet.Applet; import webwisdom.tango.*; public class JExamp extends Applet implements TDataListener { TextField text; TAgent agent=null; public JExamp() { text=new TextField(); setLayout(new BorderLayout()); add("North",text); } public void init() { try { agent=new TAgent(new TLAgentApplet(this)); agent.addTDataListener(this); text.setText(agent.getUserName()); } catch(TangoException e) { e.printStackTrace(); } } public void destroy() { if(agent!=null) agent.exit(); super.destroy(); } public boolean handleEvent(Event evt) { if((evt.target==text)&&(evt.id==Event.ACTION_EVENT)) if(agent!=null) agent.send(stringToBytes(text.getText())); return super.handleEvent(evt); } public void receive(byte b[]) { text.setText(bytesToString(b)); } private String bytesToString(byte t[]) { return new String(t,0); } private byte[] stringToBytes(String s) { int l=s.length(); byte[] t=new byte[l]; s.getBytes(0,l,t,0); return t; } }
package webwisdom.tango.fake;
public class TLAgentFake implements TLAgent { public TLAgentFake(String userName,boolean isMaster, String serverAddress,int serverPort); }
In such a setting there is no real Tango: TAgent connects to the fake server, which broadcasts application's private data, but privides no meaningful information about the system itself. Only master status is mainatined in a manner guaranteeing that there is exactly one master.public class TServerFake { public TServerFake(int portNumber); public static void main(String[] params); }
In order to use this testbed, the fake Tango server must be started:
and the application must use TLAgentFake:$ java webwisdom.tango.fake.TServerFake <portNumber>
new TAgent(new TLAgentFake(/*serverHostName*/,/*serverPortNumber*/));
These methods allows for selecting an arbitrary numerical identifier of the virtual data channel. which can be used for integrating multiple distinct applications in one Tango session. Using this interface for the purposes of a single application is strongly discouraged.addTDataListener(int channelId,TControlListener l); send(int channelId,byte[] data);