private void processNextClientRequest() {
   QueueEntry qe = (QueueEntry) qClientRequests.poll();
   if (qe != null) {
     EventSocket sock = qe.sock;
     String message = qe.message;
     boolean isAllowed = false;
     LockHolder lock = getLockForCommand(message);
     if (lock != null) {
       // if the lock exists check whether the user is allowed to use this command
       int[] privs = lock.getAllowedPrivileges();
       for (int priv : privs) if (priv == sock.getPrivilege()) isAllowed = true;
       if (isAllowed) {
         if (lockHolder == null) { // if no lock is set we try to execute the command
           setLock(lock.setLockAction(message));
           Debg.print("lock set and executed");
         } else { // if a lock is already set the command might contain an abort message
           String cmd = Parser.getValue(message, NanoComm.COMMAND_CMD);
           String[] abortCmds = lockHolder.getAbortCommands();
           boolean isAbortable = false;
           if (abortCmds != null)
             for (int i = 0; i < abortCmds.length; i++) {
               if (cmd.equals(abortCmds[i])) isAbortable = true;
             }
           if (isAbortable) {
             setLock(lockHolder.takeAbortActions("Overwriting command has been sent"));
           } else sock.sendClientInfo("Please be patient, the remote experiment is still busy");
         }
       } else sock.sendClientInfo("Sorry, you are not allowed to use this command!");
     } else Debg.print("No lock found for: " + message);
   }
   if (qClientRequests.size() > 10) {
     Debg.err(
         "I have been flooded by "
             + qClientRequests.size()
             + " client requests! I dropped everything except for the oldest one");
     qe = (QueueEntry) qClientRequests.poll();
     qClientRequests.clear();
     qClientRequests.add(qe);
   }
 }
  /**
   * Informs the new client about the current state of the remote experiment. Sets the correct
   * parameters in the gui when a new client connects or changes his privileges.
   *
   * @param sock The socket that needs to be informed.
   */
  protected void sendCurrentStateTo(EventSocket sock) {
    sock.put(NanoComm.strPriv(sock.getPrivilege()));
    try {
      Thread.sleep(2000);
    } catch (InterruptedException e) {
    }
    if (isRemExpConnected) sock.put(NanoComm.strInfo(NanoComm.INFO_REMEXP_CONNECTED));
    else sock.put(NanoComm.strInfo(NanoComm.INFO_REMEXP_DISCONNECTED));
    sock.put(NanoComm.strState(currentState));
    sock.put(NanoComm.strParam(NanoComm.PARAM_SAMPLESCLEAR + " value=all"));
    for (Sample s : allSamples) {
      sock.put(
          NanoComm.strParam(
              NanoComm.PARAM_SAMPLEINFO
                  + " value="
                  + s.getSampleID()
                  + " name="
                  + s.getSampleName()
                  + " command="
                  + s.getLockCommand()));
    }
    sock.put(NanoComm.strParam(NanoComm.PARAM_SCANRANGE + " value=" + scanRange));
    int smpl;
    if (currentSample == null) smpl = -1;
    else smpl = currentSample.getSampleID();

    sock.put(NanoComm.strParam(NanoComm.PARAM_STAGEPOSITION + " value=" + smpl));
    sock.put(NanoComm.strParam(NanoComm.PARAM_SCANSTART + " value=" + scanStart));
    sock.put(NanoComm.strParam(NanoComm.PARAM_REMEXPNAME + " value=" + remExpName));
    sock.sendClientInfo("Welcome to the RAFM of the University of Basel!");
  }