コード例 #1
0
 /**
  * Initializes the remote experiment by aborting eventual locks and setting the remote experiment
  * into a calibrated stage.
  */
 protected void initRemExp() {
   String msg;
   initMonitorVars();
   if (lockHolder != null) lockHolder.takeAbortActions("RemExp RESET");
   msg = NanoComm.strCmd(NanoComm.CMD_CALIBRATESTAGE);
   LockHolder lock = getLockForCommand(msg);
   sendToRemExp(msg);
   setLock(lock.setLockAction(msg));
 }
コード例 #2
0
 /** Checks the lockHolder for timeout on the lock. */
 @Override
 public void doTask() {
   if (lockHolder != null) {
     long now = new Date().getTime();
     if (lockStarted + lockHolder.getLockTimeoutInSeconds() * 1000 < now) {
       setLock(lockHolder.takeAbortActions("Lock timed out"));
       Debg.print("Lock timed out, took abort actions");
       lockStarted = 0;
     }
   }
   processNextClientRequest();
   try {
     Thread.sleep(500);
   } catch (InterruptedException e) {
     Debg.err("Failed sleeping");
   }
 }
コード例 #3
0
 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);
   }
 }