Package cruise.umple

Class ConnectionToClient

java.lang.Object
java.lang.Thread
cruise.umple.ConnectionToClient
All Implemented Interfaces:
java.lang.Runnable

public class ConnectionToClient
extends java.lang.Thread
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Thread

    java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
  • Field Summary

    Fields inherited from class java.lang.Thread

    MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
      ConnectionToClient​(AbstractServer aServer, java.net.Socket aClientSocket, java.io.BufferedReader aInput, java.io.Writer aOutput, boolean aReadyToStop)  
    protected ConnectionToClient​(java.lang.ThreadGroup group, java.net.Socket clientSocket, AbstractServer server)
    CONSTRUCTORS ***************************************************** Constructs a new connection to a client.
  • Method Summary

    Modifier and Type Method Description
    void close()  
    void delete()  
    protected void finalize()
    This method is called by garbage collection.
    java.net.Socket getClientSocket()
    Sockets are used in the operating system as channels of communication between two processes.
    java.net.InetAddress getInetAddress()  
    java.lang.Object getInfo​(java.lang.String infoType)
    Returns information about the client saved using setInfo.
    java.io.BufferedReader getInput()
    Stream used to read from the client.
    java.io.Writer getOutput()
    Stream used to write to the client.
    boolean getReadyToStop()
    Indicates if the thread is ready to stop.
    java.util.HashMap getSavedInfo()
    Map to save information about the client such as its login ID.
    AbstractServer getServer()
    INSTANCE VARIABLES *********************************************** A reference to the Server that created this instance.
    void run()  
    void sendToClient​(java.lang.String msg)
    INSTANCE METHODS ************************************************* Sends an object to the client.
    boolean setClientSocket​(java.net.Socket aClientSocket)  
    void setInfo​(java.lang.String infoType, java.lang.Object info)
    Saves arbitrary information about this client.
    boolean setInput​(java.io.BufferedReader aInput)  
    boolean setOutput​(java.io.Writer aOutput)  
    boolean setReadyToStop​(boolean aReadyToStop)  
    boolean setSavedInfo​(java.util.HashMap aSavedInfo)  
    boolean setServer​(AbstractServer aServer)  
    java.lang.String toString()
    Returns a string representation of the client.

    Methods inherited from class java.lang.Thread

    activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, yield

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ConnectionToClient

      public ConnectionToClient​(AbstractServer aServer, java.net.Socket aClientSocket, java.io.BufferedReader aInput, java.io.Writer aOutput, boolean aReadyToStop)
    • ConnectionToClient

      protected ConnectionToClient​(java.lang.ThreadGroup group, java.net.Socket clientSocket, AbstractServer server) throws java.io.IOException
      CONSTRUCTORS ***************************************************** Constructs a new connection to a client.
      Parameters:
      group - the thread group that contains the connections.
      clientSocket - contains the client's socket.
      server - a reference to the server that created this instance
      Throws:
      java.io.IOException - if an I/O error occur when creating the connection.
  • Method Details

    • setServer

      public boolean setServer​(AbstractServer aServer)
    • setClientSocket

      public boolean setClientSocket​(java.net.Socket aClientSocket)
    • setInput

      public boolean setInput​(java.io.BufferedReader aInput)
    • setOutput

      public boolean setOutput​(java.io.Writer aOutput)
    • setReadyToStop

      public boolean setReadyToStop​(boolean aReadyToStop)
    • setSavedInfo

      public boolean setSavedInfo​(java.util.HashMap aSavedInfo)
    • getServer

      public AbstractServer getServer()
      INSTANCE VARIABLES *********************************************** A reference to the Server that created this instance.
    • getClientSocket

      public java.net.Socket getClientSocket()
      Sockets are used in the operating system as channels of communication between two processes.
      See Also:
      Socket
    • getInput

      public java.io.BufferedReader getInput()
      Stream used to read from the client.
    • getOutput

      public java.io.Writer getOutput()
      Stream used to write to the client.
    • getReadyToStop

      public boolean getReadyToStop()
      Indicates if the thread is ready to stop. Set to true when closing of the connection is initiated.
    • getSavedInfo

      public java.util.HashMap getSavedInfo()
      Map to save information about the client such as its login ID. The initial size of the map is small since it is not expected that concrete servers will want to store many different types of information about each client. Used by the setInfo and getInfo methods.
    • delete

      public void delete()
    • sendToClient

      public void sendToClient​(java.lang.String msg) throws java.io.IOException
      INSTANCE METHODS ************************************************* Sends an object to the client. This method can be overriden, but if so it should still perform the general function of sending to client, by calling the super.sendToClient() method perhaps after some kind of filtering is done.
      Parameters:
      msg - the message to be sent.
      Throws:
      java.io.IOException - if an I/O error occur when sending the
    • toString

      public java.lang.String toString()
      Returns a string representation of the client.
      Overrides:
      toString in class java.lang.Thread
      Returns:
      the client's description.
    • setInfo

      public void setInfo​(java.lang.String infoType, java.lang.Object info)
      Saves arbitrary information about this client. Designed to be used by concrete subclasses of AbstractServer. Based on a hash map.
      Parameters:
      infoType - identifies the type of information
      info - the information itself.
    • getInfo

      public java.lang.Object getInfo​(java.lang.String infoType)
      Returns information about the client saved using setInfo. Based on a hash map.
      Parameters:
      infoType - identifies the type of information
    • finalize

      protected void finalize()
      This method is called by garbage collection.
      Overrides:
      finalize in class java.lang.Object
    • close

      public final void close() throws java.io.IOException
      Throws:
      java.io.IOException
    • getInetAddress

      public final java.net.InetAddress getInetAddress()
    • run

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