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); } }
/** 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; }
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); } } }
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()); }
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); }
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); } }
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); } }
//////////////////////////////////////////////////////////// // // 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; } }
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; } }
CellRoute routeFind(CellAddressCore addr) { return __cellGlue.getRoutingTable().find(addr); }
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); }
// // package // Thread[] getThreads(String cellName) { return __cellGlue.getThreads(cellName); }
int getUnique() { return __cellGlue.getUnique(); }
public CellInfo getCellInfo() { return __cellGlue.getCellInfo(getCellName()); }
/** * 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); }
public void setDomainContext(String contextName, Object context) { __cellGlue.getCellContext().put(contextName, context); }
CellRoute[] getRoutingList() { return __cellGlue.getRoutingList(); }
public Class<?> loadClass(String className) throws ClassNotFoundException { return __cellGlue.loadClass(className); }
public void addCellEventListener(CellEventListener listener) { __cellGlue.addCellEventListener(this, listener); }
public Object getDomainContext(String str) { return __cellGlue.getCellContext(str); }
public String[][] getClassProviders() { return __cellGlue.getClassProviders(); }
public synchronized void setClassProvider(String selection, String provider) { __cellGlue.setClassProvider(selection, provider); }
public void export() { __cellGlue.export(this); }
public Map<String, Object> getDomainContext() { return __cellGlue.getCellContext(); }
public void routeDelete(CellRoute route) throws IllegalArgumentException { __cellGlue.routeDelete(route); }
/** * 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); }
CellRoutingTable getRoutingTable() { return __cellGlue.getRoutingTable(); }
/** * 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); }
List<CellTunnelInfo> getCellTunnelInfos() { return __cellGlue.getCellTunnelInfos(); }
/** List the threads of some cell to stdout. This is indended for diagnostic information. */ public void listThreadGroupOf(String cellName) { __cellGlue.threadGroupList(cellName); }