com.transjam.util
Class ClientBase

java.lang.Object
  |
  +--com.transjam.util.ClientBase
All Implemented Interfaces:
ClientMonitorListener
Direct Known Subclasses:
Client

public abstract class ClientBase
extends java.lang.Object
implements ClientMonitorListener

Root class for TransJam clients. Communicates with server.

Author:
(C) 1997-2001 Phil Burk, SoftSynth.com, All Rights Reserved

Field Summary
static int APPLICATION_LEVEL
           
static int DEFAULT_TIMEOUT_MSEC
           
 boolean hadError
           
 boolean ifValid
           
static int LOBBY_LEVEL
           
static int LOGIN_LEVEL
           
 ProtocolWriter writer
           
 
Constructor Summary
ClientBase()
           
 
Method Summary
 void addMeeting(java.util.Date when, int numClients)
           
 void beginGracefulShutdown()
           
 boolean checkValidationMessage(java.lang.String validationMsg)
          Verify that client and server are matching and valid.
 void checkValidity()
          Check to make sure that validity has already been determined.
 void closeSocket(java.lang.String reason)
          Shut down and close the socket, then set the internal variable to null.
 void debugln(int code, java.lang.String msg)
           
 void deleteThing(java.lang.String name)
          Delete the named thing.
 void denyLock(java.lang.String name)
          Deny a request for a lock on the named thing.
 java.lang.String getName()
           
 java.net.Socket getSocket()
           
 int getUserID()
          The userID is a unique number that identifies each client logged in to the server.
abstract  void gotMessage(TransjamMessage message)
          Called by ClientMonitor.
abstract  void gotStart()
          Called one when monitor starts.
abstract  void gotStop()
           
abstract  void gotThrowable(java.lang.Throwable thr)
          Called by ClientMonitor.
abstract  void gotTimeout(int numTimeOuts)
          A timeout has been detected on a socket input stream read().
 boolean isActive()
          Is this client still useable?
 boolean isBroken()
           
 void joinMeeting(java.util.Date when)
          Request to join a meeting.
 void lockThing(java.lang.String name)
          Request a lock on a Thing for editing.
 void modifyThing(java.lang.String name, java.lang.String contents)
          Change the contents of the named thing.
 void replyEcho(java.lang.String msg)
          Reply to a request for an echo.
 void requestEcho(java.lang.String msg)
          Request that the receiver send the same string back as an echo.
 void requestMeetingList()
          Request the meeting schedule.
 void requestValidation()
           
 void sendAll(java.lang.String msg)
           
 void sendInfo(int version, java.lang.String info)
           
 void sendOthers(java.lang.String msg)
           
 void sendSelf(java.lang.String msg)
          Send a message string to oneself.
 void sendSync(java.lang.String msg)
           
 void sendUser(int targetUserID, java.lang.String msg)
           
 void setActive(boolean flag)
           
 void setName(java.lang.String name)
           
 void setSocket(java.net.Socket pSocket, int pTimeoutMSec)
          Use this network socket for communication with server.
 void setUserID(int id)
           
 void start()
          Start a thread that reads messages from the server, parses them and calls processMessage.
 void stop()
          Tell background thread to stop reading from socket.
abstract  void write(java.lang.String msg)
           
 void writeSocket(java.lang.String msg)
          Write a raw string to socket.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGIN_LEVEL

public static final int LOGIN_LEVEL

LOBBY_LEVEL

public static final int LOBBY_LEVEL

APPLICATION_LEVEL

public static final int APPLICATION_LEVEL

DEFAULT_TIMEOUT_MSEC

public static final int DEFAULT_TIMEOUT_MSEC

writer

public ProtocolWriter writer

ifValid

public boolean ifValid

hadError

public boolean hadError
Constructor Detail

ClientBase

public ClientBase()
Method Detail

gotTimeout

public abstract void gotTimeout(int numTimeOuts)
                         throws java.io.IOException
A timeout has been detected on a socket input stream read(). Called by ClientMonitor.
Specified by:
gotTimeout in interface ClientMonitorListener

gotThrowable

public abstract void gotThrowable(java.lang.Throwable thr)
Called by ClientMonitor.
Specified by:
gotThrowable in interface ClientMonitorListener
Parameters:
exc -  

gotMessage

public abstract void gotMessage(TransjamMessage message)
Called by ClientMonitor.
Specified by:
gotMessage in interface ClientMonitorListener
Parameters:
message -  

gotStart

public abstract void gotStart()
Description copied from interface: ClientMonitorListener
Called one when monitor starts.
Specified by:
gotStart in interface ClientMonitorListener

gotStop

public abstract void gotStop()
Specified by:
gotStop in interface ClientMonitorListener

write

public abstract void write(java.lang.String msg)
                    throws java.io.IOException

debugln

public void debugln(int code,
                    java.lang.String msg)

writeSocket

public void writeSocket(java.lang.String msg)
                 throws java.io.IOException
Write a raw string to socket. All writes must go through this method.

setSocket

public void setSocket(java.net.Socket pSocket,
                      int pTimeoutMSec)
               throws java.io.IOException
Use this network socket for communication with server.

getSocket

public java.net.Socket getSocket()

getUserID

public int getUserID()
The userID is a unique number that identifies each client logged in to the server.

setUserID

public void setUserID(int id)

getName

public java.lang.String getName()
Returns:
userName of this Client

setName

public void setName(java.lang.String name)

start

public void start()
Start a thread that reads messages from the server, parses them and calls processMessage.

closeSocket

public void closeSocket(java.lang.String reason)
                 throws java.io.IOException
Shut down and close the socket, then set the internal variable to null.

beginGracefulShutdown

public void beginGracefulShutdown()

stop

public void stop()
Tell background thread to stop reading from socket.

isBroken

public boolean isBroken()

isActive

public boolean isActive()
Is this client still useable?

setActive

public void setActive(boolean flag)

checkValidationMessage

public boolean checkValidationMessage(java.lang.String validationMsg)
Verify that client and server are matching and valid.

checkValidity

public void checkValidity()
                   throws java.io.IOException
Check to make sure that validity has already been determined.

requestValidation

public void requestValidation()
                       throws java.io.IOException

sendSync

public void sendSync(java.lang.String msg)
              throws java.io.IOException

sendSelf

public void sendSelf(java.lang.String msg)
              throws java.io.IOException
Send a message string to oneself. This is a handy way to communicate from an AWT event handler to the message listener in a synchronized manner.

sendOthers

public void sendOthers(java.lang.String msg)
                throws java.io.IOException

sendUser

public void sendUser(int targetUserID,
                     java.lang.String msg)
              throws java.io.IOException

sendAll

public void sendAll(java.lang.String msg)
             throws java.io.IOException

requestEcho

public void requestEcho(java.lang.String msg)
                 throws java.io.IOException
Request that the receiver send the same string back as an echo. This is used internally to maintain the connection between client and server.

replyEcho

public void replyEcho(java.lang.String msg)
               throws java.io.IOException
Reply to a request for an echo.

modifyThing

public void modifyThing(java.lang.String name,
                        java.lang.String contents)
                 throws java.io.IOException
Change the contents of the named thing. If Thing is not locked then a CMD_S_DENY_LOCK will be sent. If modification succeeds, then a CMD_CS_MODIFY_THING message will be sent to the caller, and to anyone subscribed to the ThingList.

deleteThing

public void deleteThing(java.lang.String name)
                 throws java.io.IOException
Delete the named thing. If Thing is not locked then a CMD_S_DENY_LOCK will be sent. If deletion succeeds, then a CMD_CS_DELETE_THING message will be sent to the caller, and to anyone subscribed to the ThingList.

lockThing

public void lockThing(java.lang.String name)
               throws java.io.IOException
Request a lock on a Thing for editing. Server: If the Thing does not exist then it will be created. If it cannot be locked then the server will send CMD_S_DENY_LOCK. Client: Can decide whether to grant or deny the lock.

denyLock

public void denyLock(java.lang.String name)
              throws java.io.IOException
Deny a request for a lock on the named thing.

sendInfo

public void sendInfo(int version,
                     java.lang.String info)
              throws java.io.IOException

joinMeeting

public void joinMeeting(java.util.Date when)
                 throws java.io.IOException
Request to join a meeting.

requestMeetingList

public void requestMeetingList()
                        throws java.io.IOException
Request the meeting schedule.

addMeeting

public void addMeeting(java.util.Date when,
                       int numClients)
                throws java.io.IOException