示例#1
0
  @Override
  public void getInfo(PrintWriter pw) {
    pw.append(" CellDomainName   = ").println(getCellDomainName());
    pw.format(
        " I/O rcv=%d;asw=%d;frw=%d;rpy=%d;exc=%d\n",
        _packetsReceived, _packetsAnswered, _packetsForwarded, _packetsReplied, _exceptionCounter);
    long fm = _runtime.freeMemory();
    long tm = _runtime.totalMemory();

    pw.format(" Memory : tot=%d;free=%d;used=%d\n", tm, fm, tm - fm);
    pw.println(" Cells (Threads)");
    for (String name : _nucleus.getCellNames()) {
      pw.append(" ").append(name).append("(");
      Thread[] threads = _nucleus.getThreads(name);
      if (threads != null) {
        boolean first = true;
        for (Thread thread : threads) {
          pw.print(thread.getName());
          if (first) {
            first = false;
          } else {
            pw.print(",");
          }
        }
      }
      pw.println(")");
    }
  }
示例#2
0
  private void shutdownSystem() {
    List<String> names = _nucleus.getCellNames();
    List<String> nonSystem = new ArrayList<>(names.size());
    List<String> system = new ArrayList<>(names.size());

    for (String name : names) {
      CellInfo info = _nucleus.getCellInfo(name);
      if (info == null) {
        continue;
      }
      String cellName = info.getCellName();
      if (cellName.equals("System")) {
        // Don't kill the system cell
      } else if (info.getCellType().equals("System")) {
        system.add(cellName);
      } else {
        nonSystem.add(cellName);
      }
    }

    _log.info("Will try to shutdown non-system cells {}", nonSystem);
    shutdownCells(nonSystem, 3000);

    _log.info("Will try to shutdown remaining cells {}", system);
    shutdownCells(system, 5000);
  }
示例#3
0
  @Override
  protected void startUp() {
    _cellShell.addCommandListener(this);
    _cellShell.addCommandListener(new LogbackShell());
    _cellShell.addCommandListener(new FilterShell(_nucleus.getLoggingThresholds()));
    _cellShell.addCommandListener(_cellShell.new HelpCommands());
    useInterpreter(false);

    _runtime.addShutdownHook(new TheKiller());
  }
示例#4
0
  /**
   * Shuts down named cells. The method will block until the cells are dead or until a timeout has
   * occurred.
   *
   * @param cells List of names of cells to kill.
   * @param timeout Time in milliseconds to wait for a cell to die.
   */
  private void shutdownCells(List<String> cells, long timeout) {
    for (String cellName : cells) {
      try {
        _nucleus.kill(cellName);
      } catch (IllegalArgumentException e) {
        _log.info("Problem killing : {} -> {}", cellName, e.getMessage());
      }
    }

    for (String cellName : cells) {
      try {
        if (_nucleus.join(cellName, timeout)) {
          _log.info("Killed {}", cellName);
        } else {
          _log.warn("Timeout waiting for {}", cellName);
          _nucleus.listThreadGroupOf(cellName);
          break;
        }
      } catch (InterruptedException e) {
        _log.warn("Problem killing : {} -> {}", cellName, e.getMessage());
        break;
      }
    }
  }
示例#5
0
 public int enableInterrupts(String handlerName) {
   Class<? extends DomainInterruptHandler> handlerClass;
   try {
     handlerClass = Class.forName(handlerName).asSubclass(DomainInterruptHandler.class);
   } catch (ClassNotFoundException cnfe) {
     _log.warn("Couldn't install interrupt handler (" + handlerName + ") : " + cnfe);
     return -1;
   }
   try {
     _interruptHandler = handlerClass.newInstance();
   } catch (Exception ee) {
     _log.warn("Couldn't install interrupt handler (" + handlerName + ") : " + ee);
     return -2;
   }
   _interruptThread = _nucleus.newThread(this);
   _interruptThread.start();
   return 0;
 }
示例#6
0
  public HsmControlOsm(String name, String args) throws Exception {
    super(name, args, false);
    _nucleus = getNucleus();
    _args = getArgs();
    try {
      if (_args.argc() < 1) {
        throw new IllegalArgumentException("Usage : ... <database>");
      }

      _database = new File(_args.argv(0));
      if (!_database.isDirectory()) {
        throw new IllegalArgumentException("Not a directory : " + _database);
      }
    } catch (Exception e) {
      start();
      kill();
      throw e;
    }
    useInterpreter(true);
    _nucleus.newThread(this, "queueWatch").start();
    start();
    export();
  }
示例#7
0
文件: CDC.java 项目: jstarek/dcache
 /**
  * Setup the cell diagnostic context of the calling thread. Threads created from the calling
  * thread automatically inherit this information. The old diagnostic context is captured and
  * returned.
  */
 public static CDC reset(CellNucleus cell) {
   return reset(cell.getCellName(), cell.getCellDomainName());
 }
示例#8
0
  public CellNucleus(Cell cell, String name, String type) {
    setPinboard(new Pinboard(PINBOARD_DEFAULT_SIZE));

    if (__cellGlue == null) {
      //
      // the cell gluon hasn't yet been created
      // (we insist in creating a SystemCell first.)
      //
      if (cell instanceof SystemCell) {
        __cellGlue = new CellGlue(name);
        _cellName = "System";
        _cellType = "System";
        __cellGlue.setSystemNucleus(this);
      } else {
        throw new IllegalArgumentException("System must be first Cell");
      }

    } else {
      //
      // we don't accept more then one System.cells
      //
      if (cell instanceof SystemCell) {
        throw new IllegalArgumentException("System already exists");
      } else {
        String cellName = name.replace('@', '+');

        if ((cellName == null) || (cellName.equals(""))) {
          cellName = "*";
        }
        if (cellName.charAt(cellName.length() - 1) == '*') {
          if (cellName.length() == 1) {
            cellName = "$-" + getUnique();
          } else {
            cellName = cellName.substring(0, cellName.length() - 1) + "-" + getUnique();
          }
        }

        _cellName = cellName;
        _cellType = type;
      }
    }

    _cell = cell;
    _cellClass = _cell.getClass().getName();

    /* Instantiate management component for log filtering.
     */
    CellNucleus parentNucleus = CellNucleus.getLogTargetForCell(MDC.get(CDC.MDC_CELL));
    FilterThresholds parentThresholds =
        (parentNucleus.isSystemNucleus() || parentNucleus == this)
            ? RootFilterThresholds.getInstance()
            : parentNucleus.getLoggingThresholds();
    setLoggingThresholds(new FilterThresholds(parentThresholds));

    //
    // for the use in restricted sandboxes
    //
    try {

      _threads = new ThreadGroup(__cellGlue.getMasterThreadGroup(), _cellName + "-threads");

    } catch (SecurityException se) {
      _threads = null;
    }

    _callbackExecutor =
        new ThreadPoolExecutor(
            1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), this);
    _messageExecutor =
        new ThreadPoolExecutor(
            1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), this);

    _state = ACTIVE;

    //
    // make ourself known to the world
    //
    __cellGlue.addCell(_cellName, this);

    LOGGER.info("Created {}", name);
  }
 @Override
 protected void started() {
   _nucleus.newThread(_queueWatch, "queueWatch").start();
 }