public synchronized void setMode(Mode mode) {
   if (mode.equals(this.mode)) {
     return;
   }
   this.lastMode = this.mode;
   this.mode = mode;
   if (mode.equals(Mode.END)) {
     this.close();
   }
   if (LOGGER.isLoggable(Level.INFO)) {
     LOGGER.info("Switched from " + lastMode + " to " + mode + " " + this.runtimeId);
   }
 }