示例#1
0
 /** Safely disconnects this ClientHandler from the Server */
 public void disconnect() {
   try {
     pool.removeFromAllQueues(this);
     if (game != null) {
       game.endGame(false); // End the game the client was in.
     }
     reader.close();
     writer.close();
     client.close();
     System.out.println("[Server] Debug (ClientHandler) - Client has disconnected.");
     pool.removeClient(name);
     connected = false;
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
  public void stopTFS() throws Exception {
    mClientPool.close();

    mWorker.stop();
    for (int k = 0; k < mNumOfMasters; k++) {
      mMasters.get(k).stop();
    }
    mCuratorServer.stop();
  }
  public void stopTFS() throws Exception {
    mClientPool.close();

    mWorker.stop();
    if (LineageUtils.isLineageEnabled(WorkerContext.getConf())) {
      mLineageWorker.stop();
    }
    for (int k = 0; k < mNumOfMasters; k++) {
      mMasters.get(k).stop();
    }
    mCuratorServer.stop();
  }
示例#4
0
  @Override
  public void run() {
    System.out.println("Server is running on port 8080");
    while (!shutdown) {
      try {
        Socket clientSocket = serverSocket.accept();
        Request request = new Request(clientSocket);

        // check if admin has issued a shutdown command
        shutdown = request.isShutdown();

        if (shutdown == false) {
          ClientFuture future = clientThreadPool.submit(request, new ClientCallback());
        }
      } catch (Exception e) {
        System.out.println("505..server has stopped running");
        e.printStackTrace();
      }
    }
    // kill all any open client connection
    killClientConnections();
    System.out.println("Server is shutdown");
  }
示例#5
0
  /**
   * parses a message
   *
   * @param message is a String array
   */
  public void parse(String[] message) {
    switch (message[0]) {
      case IProtocol.CLIENT_IDENTIFY:
        if (message.length < 1) {
          break;
        }

        String userName = message[1];

        try {
          pool.addClient(name, this);
          name = userName;
          sendRaw(IProtocol.SERVER_IDENTIFY);
        } catch (InvalidNameException e) {
          sendError(IProtocol.Error.NAME_INVALID.ordinal() + " Invalid name");
        } catch (UsedNameException e) {
          sendError(IProtocol.Error.NAME_USED.ordinal() + " Name is already in use");
        }

        break;
      case IProtocol.CLIENT_QUIT:
        disconnect();
        break;
      case IProtocol.CLIENT_MOVE_PUT:
        if (game == null) {
          break;
        }
        if (game.getTurnClient().equals(this)) {
          doMovePut(Arrays.copyOfRange(message, 1, message.length));
        } else {
          sendError(IProtocol.Error.ILLEGAL_STATE.ordinal() + " It is not your turn");
        }
        break;
      case IProtocol.CLIENT_MOVE_TRADE:
        if (game == null) {
          break;
        }
        if (game.getTurnClient().equals(this)) {
          doMoveTrade(Arrays.copyOfRange(message, 1, message.length));
        } else {
          sendError(IProtocol.Error.ILLEGAL_STATE.ordinal() + " It is not your turn");
        }
        break;
      case IProtocol.CLIENT_QUEUE:
        if (message.length < 1) {
          break;
        } else if (game != null) {
          sendError(
              IProtocol.Error.ILLEGAL_STATE.ordinal()
                  + " You cannot queue while you are in a game");
          break;
        }

        String[] queues = message[1].split(",");

        try {
          for (String queue : queues) {
            try {
              int queueSize = Integer.parseInt(queue);
              pool.addClientToQueue(this, queueSize);
            } catch (NumberFormatException e) {
              System.out.println("Player tried to join invalid queue.");
            }
          }
          sendRaw(IProtocol.SERVER_QUEUE);
        } catch (NumberFormatException e) {
          sendRaw(String.valueOf(IProtocol.Error.QUEUE_INVALID));
        }
        break;
      default:
        sendRaw(
            String.valueOf(
                IProtocol.Error.INVALID_COMMAND.ordinal()
                    + " The server does not recognise this command"));
        break;
    }
  }
示例#6
0
 public TachyonFileSystem getClient() throws IOException {
   return mClientPool.getClient(MasterContext.getConf());
 }
示例#7
0
 public void clearClients() throws IOException {
   mClientPool.close();
   mOldClientPool.close();
 }
示例#8
0
 /**
  * Stop waiting for connections, close all connected clients, and close this server's {@link
  * ServerSocket}.
  *
  * @throws IOException if any socket is invalid.
  */
 public void kill() throws IOException {
   _running = false;
   _clients.killall();
   _botSocket.close();
   _socket.close();
 }
 public synchronized TachyonFileSystem getClient() throws IOException {
   return mClientPool.getClient(mMasterConf);
 }
 public synchronized TachyonFileSystem getClient() throws IOException {
   return mClientPool.getClient(ClientContext.getConf());
 }
示例#11
0
 /**
  * @return the client from the pool
  * @throws IOException if the client cannot be retrieved
  */
 public FileSystem getClient() throws IOException {
   return mClientPool.getClient();
 }
示例#12
0
 private void killClientConnections() {
   System.out.println("Killing all open client connections");
   if (clientThreadPool != null) {
     clientThreadPool.shutdown();
   }
 }