예제 #1
0
 public boolean add(IBasicScope scope) {
   // log.trace("add - Hold counts - read: {} write: {} queued: {}",
   // internalLock.getReadHoldCount(), internalLock.getWriteHoldCount(),
   // internalLock.hasQueuedThreads());
   boolean added = false;
   // check #1
   if (!containsKey(scope)) {
     log.debug("Adding child scope: {} to {}", (((IBasicScope) scope).getName()), this);
     if (hasHandler()) {
       // get the handler for the scope to which we are adding this new scope
       IScopeHandler hdlr = getHandler();
       // add the scope to the handler
       if (!hdlr.addChildScope(scope)) {
         log.warn("Failed to add child scope: {} to {}", scope, this);
         return false;
       }
     } else {
       log.debug("No handler found for {}", this);
     }
     try {
       // check #2 for entry
       if (!containsKey(scope)) {
         // add the entry
         // expected return from put is null; indicating this scope didn't already exist
         added = (super.put(scope, Boolean.TRUE) == null);
         if (added) {
           subscopeStats.increment();
         } else {
           log.debug("Subscope was not added");
         }
       } else {
         log.debug("Subscope already exists");
       }
     } catch (Exception e) {
       log.warn("Exception on add", e);
     }
     if (added && scope instanceof Scope) {
       // cast it
       Scope scp = (Scope) scope;
       // start the scope
       if (scp.start()) {
         log.debug("Child scope started");
       } else {
         log.debug("Failed to start child scope: {} in {}", scope, this);
       }
     }
   }
   return added;
 }
예제 #2
0
 /**
  * Initialization actions, start if autostart is set to
  *
  * <pre>
  * true
  * </pre>
  */
 public void init() {
   log.debug("Init scope: {} parent: {}", name, parent);
   if (hasParent()) {
     if (!parent.hasChildScope(name)) {
       if (parent.addChildScope(this)) {
         log.debug("Scope added to parent");
       } else {
         log.warn("Scope not added to parent");
         // throw new ScopeException("Scope not added to parent");
         return;
       }
     } else {
       throw new ScopeException("Scope already exists in parent");
     }
   } else {
     log.debug("Scope has no parent");
   }
   if (autoStart) {
     start();
   }
 }