/**
  * Kick the given user. Kill all the connections where the user has been seen.
  *
  * @param username
  * @throws NotConnectedException
  * @throws NotFoundException
  */
 public void kickUser(UserNameDTO username)
     throws BadParameterException, NotConnectedException, NotFoundException {
   if (username.getUsername() != null && !username.getUsername().trim().isEmpty()) {
     User user = users.get(username.getUsername());
     if (user != null) {
       List<WorkerConnection> connections = user.getWorkerConnections();
       if (connections != null && !connections.isEmpty()) {
         for (WorkerConnection connection : connections) {
           connection.close();
           onWorkerDisconnection(
               connection,
               new Exception(
                   "Connection closed since user "
                       + username.getUsername()
                       + " has been kicked."));
         }
       } else {
         throw new NotConnectedException("The user " + user.getName() + " has no connections.");
       }
     } else {
       throw new NotFoundException("User " + username.getUsername() + " not found.");
     }
   } else {
     throw new BadParameterException("Invalid username: " + username.getUsername());
   }
 }
 /**
  * Link the connection to the user
  *
  * @param connection
  * @param request
  */
 private void linkConnectionToUser(WorkerConnection connection, MiningAuthorizeRequest request) {
   User user = users.get(request.getUsername());
   if (user == null) {
     user = new User(request.getUsername());
     user.setSamplingHashesPeriod(
         ConfigurationManager.getInstance().getUserHashrateSamplingPeriod());
     users.put(request.getUsername(), user);
   }
   user.addConnection(connection);
 }
  /**
   * Update the share lists of all pools, users and worker connections.
   *
   * @param request
   * @param response
   * @param workerConnection
   */
  private void updateShareLists(
      MiningSubmitRequest request,
      MiningSubmitResponse response,
      WorkerConnection workerConnection) {
    if (workerConnection.getPool() != null) {
      Share share = new Share();
      share.setDifficulty(workerConnection.getPool().getDifficulty());
      share.setTime(System.currentTimeMillis());

      boolean isAccepted = response.getIsAccepted() != null && response.getIsAccepted();

      workerConnection.updateShareLists(share, isAccepted);

      workerConnection.getPool().updateShareLists(share, isAccepted);

      User user = users.get(request.getWorkerName());
      if (user != null) {
        user.updateShareLists(share, isAccepted);
      }
    }
  }