edu.washington.biostr.sig.brainj3d.core.client
Class Callback

java.lang.Object
  extended by java.lang.Thread
      extended by edu.washington.biostr.sig.brainj3d.core.client.Callback
All Implemented Interfaces:
Runnable

public class Callback
extends Thread

Title:

Description:

Copyright: Copyright (c) 2003

Company:

A Callback is used to provide communication initiated by the server. This could be done using 2 way RMI, but issues may arise if this were an applet or in the case of a firewall (often firewalls block incoming messages to non registered computers). The system that the callback uses is based on blocking. It initiates communication with the server and blocks until a reponse is returned. A response only comes back when something on the server wants to callback to the client.

When the callback's function completes with a command, it initiates a thread that was provided for that command that initiates the appropriate response. It does nothing if no response was registered for that command. It is the developers responsibility to make sure that the command contains sufficient information so that the right tool will be called.

To use a tool creates a CallbackRunnable that implements the command and then registers the command with the callback. It should already have been started by the Displayer.

Version:
1.0
Author:
Eider Moore

Nested Class Summary
protected  class Callback.Entry
           
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static int CLIENT_MAIN
           
static int EVENT_THREAD
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Callback(Session session, ClientManager manager)
          We only have one Callback per client, so this is protected and only called by getCallback().
 
Method Summary
 void addRunnable(String key, CallbackFactory r)
          This adds a command to the set of commands.
 void execute(Runnable runnable, int thread)
           
 void kill()
           
 void removeRunnable(String key)
          Remove a command.
 void run()
          The callback runs as a thread and this function does all the work.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EVENT_THREAD

public static final int EVENT_THREAD
See Also:
Constant Field Values

CLIENT_MAIN

public static final int CLIENT_MAIN
See Also:
Constant Field Values
Constructor Detail

Callback

public Callback(Session session,
                ClientManager manager)
We only have one Callback per client, so this is protected and only called by getCallback().

Parameters:
session - The current session. This cannot be null.
Method Detail

execute

public void execute(Runnable runnable,
                    int thread)

kill

public void kill()

run

public void run()
The callback runs as a thread and this function does all the work. It waits for a callback and then dispatches the command to the appropriate Runnable. If the same command is already running, it merely tells that command to call itself again.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

addRunnable

public void addRunnable(String key,
                        CallbackFactory r)
This adds a command to the set of commands.

Parameters:
key - The command string. This must match the command sent back by the server.
r - The CallbackRunnable that performs this command.

removeRunnable

public void removeRunnable(String key)
Remove a command. This is usually a good idea.

Parameters:
key - The command string.


Copyright © 2006 University of Washington. All Rights Reserved.