コード例 #1
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public Cell createNewCell(
     String className, String cellName, String[] argsClassNames, Object[] args)
     throws ClassNotFoundException, NoSuchMethodException, InstantiationException,
         IllegalAccessException, InvocationTargetException, ClassCastException {
   if (argsClassNames == null) {
     return __cellGlue._newInstance(className, cellName, args, false);
   } else {
     return __cellGlue._newInstance(className, cellName, argsClassNames, args, false);
   }
 }
コード例 #2
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 /** Returns the CellNucleus to which log messages tagged with a given cell are associated. */
 public static CellNucleus getLogTargetForCell(String cell) {
   CellNucleus nucleus = null;
   if (__cellGlue != null) {
     if (cell != null) {
       nucleus = __cellGlue.getCell(cell);
     }
     if (nucleus == null) {
       nucleus = __cellGlue.getSystemNucleus();
     }
   }
   return nucleus;
 }
コード例 #3
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
  public void sendMessage(
      CellMessage msg, boolean local, boolean remote, CellMessageAnswerable callback, long timeout)
      throws SerializationException {
    if (!msg.isStreamMode()) {
      msg.touch();
    }

    msg.setTtl(timeout);

    EventLogger.sendBegin(this, msg, "callback");
    UOID uoid = msg.getUOID();
    boolean success = false;
    try {
      CellLock lock = new CellLock(msg, callback, timeout);
      synchronized (_waitHash) {
        _waitHash.put(uoid, lock);
      }

      __cellGlue.sendMessage(this, msg, local, remote);
      success = true;
    } catch (NoRouteToCellException e) {
      if (callback != null) {
        callback.exceptionArrived(msg, e);
      }
    } finally {
      if (!success) {
        synchronized (_waitHash) {
          _waitHash.remove(uoid);
        }
        EventLogger.sendEnd(msg);
      }
    }
  }
コード例 #4
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public Reader getDomainContextReader(String contextName) throws FileNotFoundException {
   Object o = __cellGlue.getCellContext(contextName);
   if (o == null) {
     throw new FileNotFoundException("Context not found : " + contextName);
   }
   return new StringReader(o.toString());
 }
コード例 #5
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
  public Cell createNewCell(String cellClass, String cellName, Socket socket, boolean systemOnly)
      throws ClassNotFoundException, NoSuchMethodException, SecurityException,
          InstantiationException, InvocationTargetException, IllegalAccessException,
          ClassCastException {

    Object[] args = new Object[1];
    args[0] = socket;

    return __cellGlue._newInstance(cellClass, cellName, args, systemOnly);
  }
コード例 #6
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
  public CellMessage sendAndWait(CellMessage msg, boolean local, boolean remote, long timeout)
      throws SerializationException, NoRouteToCellException, InterruptedException {
    if (!msg.isStreamMode()) {
      msg.touch();
    }

    msg.setTtl(timeout);

    EventLogger.sendBegin(this, msg, "blocking");
    UOID uoid = msg.getUOID();
    try {
      CellLock lock = new CellLock();
      synchronized (_waitHash) {
        _waitHash.put(uoid, lock);
      }
      LOGGER.trace("sendAndWait : adding to hash : {}", uoid);

      __cellGlue.sendMessage(this, msg, local, remote);

      //
      // because of a linux native thread problem with
      // wait(n > 0), we have to use a interruptedFlag
      // and the time messurement.
      //
      synchronized (lock) {
        long start = System.currentTimeMillis();
        while (lock.getObject() == null && timeout > 0) {
          lock.wait(timeout);
          timeout -= (System.currentTimeMillis() - start);
        }
      }
      CellMessage answer = (CellMessage) lock.getObject();
      if (answer == null) {
        return null;
      }
      answer = answer.decode();

      Object obj = answer.getMessageObject();
      if (obj instanceof NoRouteToCellException) {
        throw (NoRouteToCellException) obj;
      } else if (obj instanceof SerializationException) {
        throw (SerializationException) obj;
      }
      return answer;
    } finally {
      synchronized (_waitHash) {
        _waitHash.remove(uoid);
      }
      EventLogger.sendEnd(msg);
    }
  }
コード例 #7
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
  public void sendMessage(CellMessage msg, boolean locally, boolean remotely)
      throws SerializationException, NoRouteToCellException {

    if (!msg.isStreamMode()) {
      msg.touch();
    }

    EventLogger.sendBegin(this, msg, "async");
    try {
      __cellGlue.sendMessage(this, msg, locally, remotely);
    } finally {
      EventLogger.sendEnd(msg);
    }
  }
コード例 #8
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 ////////////////////////////////////////////////////////////
 //
 //   create new cell by different arguments
 //   String, String [], Socket
 //   can choose between systemLoader only or
 //   Domain loader.
 //
 public Cell createNewCell(String cellClass, String cellName, String cellArgs, boolean systemOnly)
     throws ClassNotFoundException, NoSuchMethodException, SecurityException,
         InstantiationException, InvocationTargetException, IllegalAccessException,
         ClassCastException {
   try {
     Object[] args = new Object[1];
     args[0] = cellArgs;
     return __cellGlue._newInstance(cellClass, cellName, args, systemOnly);
   } catch (InvocationTargetException e) {
     Throwable t = e.getTargetException();
     if (t instanceof RuntimeException) {
       throw (RuntimeException) t;
     }
     if (t instanceof Error) {
       throw (Error) t;
     }
     throw e;
   }
 }
コード例 #9
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
  void shutdown(KillEvent event) {
    LOGGER.trace("Received {}", event);

    try (CDC ignored = CDC.reset(CellNucleus.this)) {
      _state = REMOVING;
      addToEventQueue(LAST_MESSAGE_EVENT);
      try {
        _cell.prepareRemoval(event);
      } catch (Throwable e) {
        Thread t = Thread.currentThread();
        t.getUncaughtExceptionHandler().uncaughtException(t, e);
      }

      shutdownPrivateExecutors();

      LOGGER.debug("Waiting for all threads in {} to finish", _threads);

      try {
        Collection<Thread> threads = getNonDaemonThreads(_threads);

        /* Some threads shut down asynchronously. Give them
         * one second before we start to kill them.
         */
        while (!joinThreads(threads, 1000)) {
          killThreads(threads);
        }
        _threads.destroy();
      } catch (IllegalThreadStateException e) {
        _threads.setDaemon(true);
      } catch (InterruptedException e) {
        LOGGER.warn("Interrupted while waiting for threads");
      }
      __cellGlue.destroy(CellNucleus.this);
      _state = DEAD;
    }
  }
コード例 #10
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 CellRoute routeFind(CellAddressCore addr) {
   return __cellGlue.getRoutingTable().find(addr);
 }
コード例 #11
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
  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);
  }
コード例 #12
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 //
 //  package
 //
 Thread[] getThreads(String cellName) {
   return __cellGlue.getThreads(cellName);
 }
コード例 #13
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 int getUnique() {
   return __cellGlue.getUnique();
 }
コード例 #14
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public CellInfo getCellInfo() {
   return __cellGlue.getCellInfo(getCellName());
 }
コード例 #15
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 /**
  * Blocks until the given cell is dead.
  *
  * @param timeout the maximum time to wait in milliseconds.
  * @throws InterruptedException if another thread interrupted the current thread before or while
  *     the current thread was waiting for a notification. The interrupted status of the current
  *     thread is cleared when this exception is thrown.
  * @return True if the cell died, false in case of a timeout.
  */
 public boolean join(String cellName, long timeout) throws InterruptedException {
   return __cellGlue.join(cellName, timeout);
 }
コード例 #16
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public void setDomainContext(String contextName, Object context) {
   __cellGlue.getCellContext().put(contextName, context);
 }
コード例 #17
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 CellRoute[] getRoutingList() {
   return __cellGlue.getRoutingList();
 }
コード例 #18
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public Class<?> loadClass(String className) throws ClassNotFoundException {
   return __cellGlue.loadClass(className);
 }
コード例 #19
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public void addCellEventListener(CellEventListener listener) {
   __cellGlue.addCellEventListener(this, listener);
 }
コード例 #20
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public Object getDomainContext(String str) {
   return __cellGlue.getCellContext(str);
 }
コード例 #21
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public String[][] getClassProviders() {
   return __cellGlue.getClassProviders();
 }
コード例 #22
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public synchronized void setClassProvider(String selection, String provider) {
   __cellGlue.setClassProvider(selection, provider);
 }
コード例 #23
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public void export() {
   __cellGlue.export(this);
 }
コード例 #24
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public Map<String, Object> getDomainContext() {
   return __cellGlue.getCellContext();
 }
コード例 #25
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 public void routeDelete(CellRoute route) throws IllegalArgumentException {
   __cellGlue.routeDelete(route);
 }
コード例 #26
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 /**
  * The kill method schedules the specified cell for deletion. The actual remove operation will run
  * in a different thread. So on return of this method the cell may or may not be alive.
  */
 public void kill() {
   __cellGlue.kill(this);
 }
コード例 #27
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 CellRoutingTable getRoutingTable() {
   return __cellGlue.getRoutingTable();
 }
コード例 #28
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 /**
  * The kill method schedules this Cell for deletion. The actual remove operation will run in a
  * different thread. So on return of this method the cell may or may not be alive.
  */
 public void kill(String cellName) throws IllegalArgumentException {
   __cellGlue.kill(this, cellName);
 }
コード例 #29
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 List<CellTunnelInfo> getCellTunnelInfos() {
   return __cellGlue.getCellTunnelInfos();
 }
コード例 #30
0
ファイル: CellNucleus.java プロジェクト: sureddy/dcache
 /** List the threads of some cell to stdout. This is indended for diagnostic information. */
 public void listThreadGroupOf(String cellName) {
   __cellGlue.threadGroupList(cellName);
 }