Babylon Java Chat

Class BabylonConnection

java.lang.Object
  extended by java.lang.Thread
      extended by BabylonConnection
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
BabylonClientConnection, BabylonServerConnection

public abstract class BabylonConnection
extends java.lang.Thread

An abstract class for connections from the client or to the server. Used as a superclass for BabylonServerConnection and BabylonClientConnection, this class contains common data fields and methods for opening up the required data streams.

Author:
Andy McLaughlin

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.util.Hashtable fileTransfers
           
protected  java.util.Hashtable imageTransfers
           
protected  java.io.DataInputStream iStream
           
protected  long lastReceiveTime
           
protected  long lastSendTime
           
protected  boolean online
           
protected  java.io.DataOutputStream oStream
           
protected  double protocolVersion
           
protected  java.net.Socket socket
           
protected  java.lang.ThreadGroup threadGroup
           
protected  BabylonConnection.WatchDog watchDog
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BabylonConnection(java.lang.ThreadGroup tg, java.lang.String name, java.net.Socket s)
           
 
Method Summary
protected abstract  void lostConnection()
           
abstract  void run()
           
protected  void sendActivity(int fromId, short activity, int[] recipients)
          Send notification to the requested recipients that a user is doing some activity, such as typing or drawing.
protected  void sendAllowUser(int fromId, java.lang.String roomName, int toId)
          Send notification that a user, previously banned from a chat room, is now allowed.
protected  void sendBanUser(int fromId, java.lang.String roomName, int toId)
          Sends notification that a user has been banned from a chat room.
protected  void sendBootUser(int fromId, java.lang.String roomName, int toId)
          Send notification that a user is being booted from a chat room.
protected  void sendChatText(int fromId, boolean priv, java.lang.String data, int[] recipients)
          Send chat text to the requested recipients.
protected  void sendClearCanv(int fromId, int[] recipients)
          Send notification to the requested recipients that a user has cleared the drawing canvas.
protected  void sendConnect(java.lang.String userName)
          Send a connection notification to the other end, to let it know that a user is connecting.
protected  void sendDisconnect(int userId, java.lang.String mess)
          Send out a broadcast that a user (possibly the sender himself) is disconnecting.
protected  void sendDrawText(int fromId, short colour, short x, short y, short type, short attribs, short size, java.lang.String text, int[] recipients)
          Send drawing text (i.e.
protected  void sendEnterRoom(int fromId, java.lang.String roomName, boolean priv, java.lang.String password, boolean encrypted)
          Send notification that a user is moving from one chat room to another.
protected  void sendError(int fromId, short code, int[] recipients)
          Sends an error advisory to the requested recipients.
protected  void sendFile(int fromId, java.lang.String fileName, long totalSize, int totalBlocks, int blockSize, int expireMins, int[] recipients)
           
protected  void sendFileAccept(int fromId, int toId, java.lang.String fileName, boolean accept)
          Send a notification about whether a client is accepting a file transfer invitation.
protected  void sendFileBlock(int fromId, java.lang.String fileName, int blockNumber, byte[] data)
          Send a file block packet of a file transfer.
protected  void sendFileCancel(int fromId, java.lang.String fileName)
          Send a cancellation notification for a file transfer.
protected  void sendImage(int fromId, java.lang.String imageName, short xCoord, short yCoord, int totalSize, int totalBlocks, int blockSize, byte[] data, int[] recipients)
          Send a graphic image to the requested recipients, to be displayed on the drawing canvas.
protected  void sendImageBlock(int fromId, java.lang.String imageName, int blockNumber, byte[] data)
          Send a file block packet of an image transfer.
protected  void sendInstantMess(int fromId, int toId, java.lang.String message)
          Send an instant message request to the requested recipient.
protected  void sendInvite(int fromId, java.lang.String roomName, int toId)
          Send a chat room invitation from one user to another.
protected  void sendLeaveMess(int fromId, java.lang.String toName, java.lang.String message)
          Send a stored message to be saved for the requested user name.
protected  void sendLine(int fromId, short colour, short startX, short startY, short endX, short endY, short thick, int[] recipients)
          Send a drawing line to the requested recipients.
protected  void sendPageUser(int fromId, int[] recipients)
          Send a paging request to the requested recipients.
protected  void sendPing()
          Send a ping command to the connection on the other end, to let it know that we're still connected.
protected  void sendPoly(short kind, int fromId, short colour, short x, short y, short width, short height, short thick, boolean fill, int[] recipients)
          Send a drawing polygon to the requested recipients.
protected  void sendProtocol(double version)
          Send a message to the other end about our desired protocol.
protected  void sendReadMess(int fromId)
          Sends a request from the client to the server to retrieve stored messages.
protected  void sendRoomList(java.util.Vector rooms)
          Send a 'rooms list' request.
protected  void sendSendEmail(int fromId, java.lang.String mxHost, java.lang.String fromAddress, java.lang.String toAddress, java.lang.String subject, java.lang.String text)
          Sends a 'send email' request from the client to the server with the supplied parameters and data.
protected  void sendServerMessage(java.lang.String data)
          This will cause a message from the server to appear in a dialog window on the screen of the user.
protected  void sendServerText(java.lang.String data)
          Send chat text from the server to be displayed in the recipients' chat windows.
protected  void sendStoredMess(java.util.Vector messages)
          Send all of the stored messages to the requested recipient.
protected  void sendUserInfo(int id, java.lang.String name, java.lang.String password, boolean encrypted, java.lang.String email, java.lang.String additional, java.lang.String language)
          Send information about user.
protected  void shutdown()
           
 
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

protocolVersion

protected double protocolVersion

threadGroup

protected java.lang.ThreadGroup threadGroup

socket

protected java.net.Socket socket

iStream

protected java.io.DataInputStream iStream

oStream

protected java.io.DataOutputStream oStream

online

protected boolean online

fileTransfers

protected java.util.Hashtable fileTransfers

imageTransfers

protected java.util.Hashtable imageTransfers

lastSendTime

protected long lastSendTime

lastReceiveTime

protected long lastReceiveTime

watchDog

protected BabylonConnection.WatchDog watchDog
Constructor Detail

BabylonConnection

public BabylonConnection(java.lang.ThreadGroup tg,
                         java.lang.String name,
                         java.net.Socket s)
                  throws java.io.IOException
Throws:
java.io.IOException
Method Detail

run

public abstract void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

sendProtocol

protected void sendProtocol(double version)
Send a message to the other end about our desired protocol.


sendPing

protected void sendPing()
Send a ping command to the connection on the other end, to let it know that we're still connected.


sendConnect

protected void sendConnect(java.lang.String userName)
Send a connection notification to the other end, to let it know that a user is connecting.


sendUserInfo

protected void sendUserInfo(int id,
                            java.lang.String name,
                            java.lang.String password,
                            boolean encrypted,
                            java.lang.String email,
                            java.lang.String additional,
                            java.lang.String language)
Send information about user.


sendServerMessage

protected void sendServerMessage(java.lang.String data)
This will cause a message from the server to appear in a dialog window on the screen of the user. Can only be sent by a server connection; the server will not accept it going the other way.


sendDisconnect

protected void sendDisconnect(int userId,
                              java.lang.String mess)
Send out a broadcast that a user (possibly the sender himself) is disconnecting.


sendRoomList

protected void sendRoomList(java.util.Vector rooms)
Send a 'rooms list' request. If the Vector of rooms is null, then this is a request from the client for the server to send a list. Otherwise, it's the server sending a list.


sendInvite

protected void sendInvite(int fromId,
                          java.lang.String roomName,
                          int toId)
Send a chat room invitation from one user to another.


sendEnterRoom

protected void sendEnterRoom(int fromId,
                             java.lang.String roomName,
                             boolean priv,
                             java.lang.String password,
                             boolean encrypted)
Send notification that a user is moving from one chat room to another.


sendBootUser

protected void sendBootUser(int fromId,
                            java.lang.String roomName,
                            int toId)
Send notification that a user is being booted from a chat room.


sendBanUser

protected void sendBanUser(int fromId,
                           java.lang.String roomName,
                           int toId)
Sends notification that a user has been banned from a chat room.


sendAllowUser

protected void sendAllowUser(int fromId,
                             java.lang.String roomName,
                             int toId)
Send notification that a user, previously banned from a chat room, is now allowed.


sendActivity

protected void sendActivity(int fromId,
                            short activity,
                            int[] recipients)
Send notification to the requested recipients that a user is doing some activity, such as typing or drawing.


sendChatText

protected void sendChatText(int fromId,
                            boolean priv,
                            java.lang.String data,
                            int[] recipients)
Send chat text to the requested recipients.


sendServerText

protected void sendServerText(java.lang.String data)
Send chat text from the server to be displayed in the recipients' chat windows.


sendLine

protected void sendLine(int fromId,
                        short colour,
                        short startX,
                        short startY,
                        short endX,
                        short endY,
                        short thick,
                        int[] recipients)
Send a drawing line to the requested recipients.


sendPoly

protected void sendPoly(short kind,
                        int fromId,
                        short colour,
                        short x,
                        short y,
                        short width,
                        short height,
                        short thick,
                        boolean fill,
                        int[] recipients)
Send a drawing polygon to the requested recipients.


sendDrawText

protected void sendDrawText(int fromId,
                            short colour,
                            short x,
                            short y,
                            short type,
                            short attribs,
                            short size,
                            java.lang.String text,
                            int[] recipients)
Send drawing text (i.e. graphical text on the canvas) to the requested recipients.


sendImage

protected void sendImage(int fromId,
                         java.lang.String imageName,
                         short xCoord,
                         short yCoord,
                         int totalSize,
                         int totalBlocks,
                         int blockSize,
                         byte[] data,
                         int[] recipients)
Send a graphic image to the requested recipients, to be displayed on the drawing canvas.


sendClearCanv

protected void sendClearCanv(int fromId,
                             int[] recipients)
Send notification to the requested recipients that a user has cleared the drawing canvas.


sendPageUser

protected void sendPageUser(int fromId,
                            int[] recipients)
Send a paging request to the requested recipients.


sendInstantMess

protected void sendInstantMess(int fromId,
                               int toId,
                               java.lang.String message)
Send an instant message request to the requested recipient.


sendStoredMess

protected void sendStoredMess(java.util.Vector messages)
Send all of the stored messages to the requested recipient. This is only sent by the server to the client.


sendLeaveMess

protected void sendLeaveMess(int fromId,
                             java.lang.String toName,
                             java.lang.String message)
Send a stored message to be saved for the requested user name.


sendReadMess

protected void sendReadMess(int fromId)
Sends a request from the client to the server to retrieve stored messages.


sendError

protected void sendError(int fromId,
                         short code,
                         int[] recipients)
Sends an error advisory to the requested recipients.


sendSendEmail

protected void sendSendEmail(int fromId,
                             java.lang.String mxHost,
                             java.lang.String fromAddress,
                             java.lang.String toAddress,
                             java.lang.String subject,
                             java.lang.String text)
Sends a 'send email' request from the client to the server with the supplied parameters and data.


sendFile

protected void sendFile(int fromId,
                        java.lang.String fileName,
                        long totalSize,
                        int totalBlocks,
                        int blockSize,
                        int expireMins,
                        int[] recipients)

sendFileAccept

protected void sendFileAccept(int fromId,
                              int toId,
                              java.lang.String fileName,
                              boolean accept)
Send a notification about whether a client is accepting a file transfer invitation.


sendFileBlock

protected void sendFileBlock(int fromId,
                             java.lang.String fileName,
                             int blockNumber,
                             byte[] data)
Send a file block packet of a file transfer.


sendFileCancel

protected void sendFileCancel(int fromId,
                              java.lang.String fileName)
Send a cancellation notification for a file transfer.


sendImageBlock

protected void sendImageBlock(int fromId,
                              java.lang.String imageName,
                              int blockNumber,
                              byte[] data)
Send a file block packet of an image transfer.


lostConnection

protected abstract void lostConnection()

shutdown

protected void shutdown()

Babylon Java Chat