Class SharedServerClient


  • public class SharedServerClient
    extends InteractiveClient
    This class implements a client the can connect to the NanoDB shared server and send/receive commands and data.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  SharedServerClient.Receiver
      This helper class prints out the results that come back from the server.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.apache.logging.log4j.Logger logger  
      private java.io.ObjectInputStream objectInput
      This stream is used to receive objects (tuples, messages, etc.) from the server.
      private java.io.ObjectOutputStream objectOutput
      This stream is used to send objects (commands, specifically) to the server.
      private SharedServerClient.Receiver receiver
      This object receives data from the server asynchronously, and prints out whatever it receives.
      private java.lang.Thread receiverThread
      This is the thread that the receiver object runs within.
      private java.util.concurrent.Semaphore semCommandDone
      This semaphore is used to coordinate when a command has been sent to the server, and when the server is finished sending results back to the client, so that another command cannot be sent until the current one is finished.
      private java.net.Socket socket
      The socket used to communicate with the shared server.
    • Constructor Summary

      Constructors 
      Constructor Description
      SharedServerClient​(java.lang.String hostname, int port)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CommandResult handleCommand​(java.lang.String command)
      Subclasses can implement this method to handle each command entered by the user.
      void shutdown()
      Shut down the interactive client.
      void startup()
      Start up the interactive client.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        private static org.apache.logging.log4j.Logger logger
      • socket

        private java.net.Socket socket
        The socket used to communicate with the shared server.
      • objectInput

        private java.io.ObjectInputStream objectInput
        This stream is used to receive objects (tuples, messages, etc.) from the server.
      • objectOutput

        private java.io.ObjectOutputStream objectOutput
        This stream is used to send objects (commands, specifically) to the server.
      • receiverThread

        private java.lang.Thread receiverThread
        This is the thread that the receiver object runs within.
      • semCommandDone

        private java.util.concurrent.Semaphore semCommandDone
        This semaphore is used to coordinate when a command has been sent to the server, and when the server is finished sending results back to the client, so that another command cannot be sent until the current one is finished.
    • Constructor Detail

      • SharedServerClient

        public SharedServerClient​(java.lang.String hostname,
                                  int port)
                           throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • startup

        public void startup()
        Description copied from class: InteractiveClient
        Start up the interactive client. The specific way the client interacts with the server dictates how this startup mechanism will work.
        Specified by:
        startup in class InteractiveClient
      • handleCommand

        public CommandResult handleCommand​(java.lang.String command)
        Description copied from class: InteractiveClient
        Subclasses can implement this method to handle each command entered by the user. For example, a subclass may send the command over a socket to the server, wait for a response, then output the response to the console.
        Specified by:
        handleCommand in class InteractiveClient
        Parameters:
        command - the command to handle.
        Returns:
        the command-result from executing the command
      • shutdown

        public void shutdown()
                      throws java.io.IOException
        Description copied from class: InteractiveClient
        Shut down the interactive client. The specific way the client interacts with the server dictates how this shutdown mechanism will work.
        Specified by:
        shutdown in class InteractiveClient
        Throws:
        java.io.IOException