com.ibm.tspaces.examples.simple
Class AppletTst1

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--com.ibm.tspaces.examples.simple.AppletTst1

public class AppletTst1
extends java.applet.Applet
implements Callback, java.lang.Runnable

This class implements a simple Applet that interfaces with TSpaces.

 Some things to note:
   - It ensures that only one instance of the applet is 
     is running.  
   - It uses the destroy() interface to cleanup the connection 
     to the server.

 

Author:
John Thomas
See Also:
Serialized Form

Field Summary
protected static java.lang.String _host
          This is the Host where the TupleSpace Server is running
protected static int _port
           
protected static boolean _started
          This will be set true when start() called and set to false when stop() is called;
protected  TupleSpace _ts
          This holds a reference to the current TupleSpace.
protected static java.lang.String _tsName
          The Space name
 java.awt.Frame appFrame
           
protected static java.awt.Color BACKGROUND_COLOR
           
protected static int HEIGHT
           
protected static int WIDTH
           
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
AppletTst1()
          The default constructor.
 
Method Summary
 boolean call(java.lang.String eventName_, java.lang.String tsName_, int sequenceNumber_, SuperTuple tuple_, boolean isException_)
          Process the callback from the server that notifies us when anyone (including ourselves) writes to the TupleSpace.
 void destroy()
          destroy() is called when the applet is going to be permanently stoped We will decrement the instance count and if it is now zero we will cleanup the TSpaces connection.
 void init()
          Initialization: This could be entered automatically when running as an applet or by being called from main() is being run from an application.
static void main(java.lang.String[] args)
          Run the AppletTst1 as an application.
 void paint(java.awt.Graphics g)
          paint() is called to redisplay
 void run()
          run: Is entered as as a result of a start thread It is not currently being used.
 void setupButtons(java.awt.Panel appPanel)
          sets up some buttons that user can poke at Currently it only creates a "Write" button that causes a tuple to be written.
 boolean setupTS()
          setup for TSpaces access
 void start()
          start() is called when it is time for the applet to start doing stuff.
 void stop()
          stop() is called when the applet is no longer visible so we no longer need to keep painting the screen, but we should still listen for events.
 
Methods inherited from class java.applet.Applet
getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setCursor, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_started

protected static boolean _started
This will be set true when start() called and set to false when stop() is called;

WIDTH

protected static final int WIDTH

HEIGHT

protected static final int HEIGHT

appFrame

public java.awt.Frame appFrame

_ts

protected TupleSpace _ts
This holds a reference to the current TupleSpace.

BACKGROUND_COLOR

protected static java.awt.Color BACKGROUND_COLOR

_host

protected static java.lang.String _host
This is the Host where the TupleSpace Server is running

_port

protected static int _port

_tsName

protected static java.lang.String _tsName
The Space name
Constructor Detail

AppletTst1

public AppletTst1()
The default constructor. The constructor has little use in an applet but we have one just for completeness.
Method Detail

init

public void init()
Initialization: This could be entered automatically when running as an applet or by being called from main() is being run from an application. This is where all of the window and TSpace setup is done Note that we increment a static variable (_instanceCount) to keep track of how many instances of this applet are running
Overrides:
init in class java.applet.Applet

setupButtons

public void setupButtons(java.awt.Panel appPanel)
sets up some buttons that user can poke at Currently it only creates a "Write" button that causes a tuple to be written.

setupTS

public boolean setupTS()
setup for TSpaces access
Returns:
true if the setup is OK

run

public void run()
run: Is entered as as a result of a start thread It is not currently being used.
Specified by:
run in interface java.lang.Runnable

paint

public void paint(java.awt.Graphics g)
paint() is called to redisplay
Overrides:
paint in class java.awt.Container

start

public void start()
start() is called when it is time for the applet to start doing stuff. This could be called multiple times as the applet is stopped and started. If the TupleSpace setup has been terminated, then it will be restarted.
Overrides:
start in class java.applet.Applet

stop

public void stop()
stop() is called when the applet is no longer visible so we no longer need to keep painting the screen, but we should still listen for events. This could be called multiple times as the applet is stopped and started. Since the startup will reinit the TupleSpace environment, we can issue a cleanup() here but only if there are no other active instances.
Overrides:
stop in class java.applet.Applet

destroy

public void destroy()
destroy() is called when the applet is going to be permanently stoped We will decrement the instance count and if it is now zero we will cleanup the TSpaces connection.
Overrides:
destroy in class java.applet.Applet

call

public boolean call(java.lang.String eventName_,
                    java.lang.String tsName_,
                    int sequenceNumber_,
                    SuperTuple tuple_,
                    boolean isException_)
Process the callback from the server that notifies us when anyone (including ourselves) writes to the TupleSpace.
Specified by:
call in interface Callback
Parameters:
eventName_ - the name of the event command that caused this call, that is the name of the client side command of the thread that registered this call, e.g., in the case of a read, this would be TupleSpace.READ, **not** TupleSpace.WRITE which is the corresponding command that caused the actaul event.
tsName_ - the name of the tuple space this command was executed on.
sequenceNumber_ - the sequenceNumber for this event/command
tuple_ - the returned tuple or a Tuple with an exception inside
isException_ - was the command processed normaly or was there an exception
Returns:
true if this is the last call this sequence # should be getting otherwise false

main

public static void main(java.lang.String[] args)
Run the AppletTst1 as an application.
Parameters:
args - - command line arguments