예제 #1
0
 /** Checks for components with unresolved dependencies and logs them. */
 private int componentAudit() {
   int waiting = 0;
   if (runList != null) {
     if (running != null) {
       ComponentLog.trace(
           "Component:" + running + " is running. Did you forget to call complete()?");
       ++waiting;
     }
     for (Component c : runList) {
       String component_msg = "Component:" + c + " is waiting: ";
       int count = 0;
       ArrayList<String> missing = c.getDependencies();
       for (String msg : missing) {
         ++count;
         component_msg += msg;
         if (missing.indexOf(msg) != (missing.size() - 1)) component_msg += ", ";
       }
       if (count == 0) component_msg += " No outstanding dependencies.";
       ComponentLog.trace(component_msg);
       ++waiting;
     }
   }
   if (componentRequests.size() != 0) {
     for (String c : componentRequests) {
       ComponentLog.trace("Waiting on component request: " + c);
     }
     ComponentLog.trace(
         "Some components may not be implemented by the factory or are taking a long time to load.");
   }
   return (waiting);
 }
예제 #2
0
 /**
  * Removes a specific component from the register; effectively turning it off.
  *
  * <p>It's quite tricky to go through a cleanly rebind events and remove events, worry about
  * components that depend on this one, etc., so none of that happens here; handle it manually in
  * the component's shutdown() call.
  */
 public void removeComponent(Component c) throws Exception {
   c.shutdown();
   try {
     elementCache.remove(c.getContainer().getRootElement());
     idCache.remove(c.getContainer().getRootElement().getId());
   } catch (Exception e) {
   }
 }
예제 #3
0
 /** Returns a the first component of the given type. */
 public Component getComponentByType(String type) {
   Component rtn = null;
   for (Element root : elementCache.keySet()) {
     Component c = getComponent(root);
     if (c.getContainer().getType().equals(type)) {
       rtn = c;
       break;
     }
   }
   return (rtn);
 }
예제 #4
0
 /** Inits all components. */
 private ArrayList<Component> runComponentInit() {
   ArrayList<Component> rtn = new ArrayList<Component>();
   Set<Element> elements = elementCache.keySet();
   for (Element key : elements) {
     Component c = elementCache.get(key);
     if (!c.active()) {
       c.init();
       rtn.add(c);
     }
   }
   return (rtn);
 }
예제 #5
0
 /** Invoked async when a componet has been created. */
 public void componentCreated(Component c, String requestId) {
   Element root = c.getContainer().getRootElement();
   elementCache.put(root, c);
   if ((root.getId() != null) && (!root.getId().equals(""))) idCache.put(root.getId(), c);
   if (componentRequests.contains(requestId)) componentRequests.remove(requestId);
   if (componentRequests.size() == 0) componentCreationComplete();
 }
예제 #6
0
  /**
   * Runs the next component in the run list.
   *
   * <p>If null is passed it is assumed the call is from internal not a component; otherwise the
   * notifyDependants() call is made on the target.
   *
   * <p>After the notification, the next component with no dependencies is found and run via async
   * call; if none, the register stops.
   */
  public void componentReady(Component target) {
    if (runList != null) {

      // Nothing is running if we got this callback.
      running = null;

      // This target has run, so it is considered a resolved
      // dependency; notify any one depending on it, so our
      // next search finds (hopefully) another dependency
      // free component to run.
      if (target != null) {
        target.notifyWaiting();
        if (runList.contains(target)) runList.remove(target);
      }

      // Find next
      Component next = null;
      for (Component c : runList) {
        if (c.getDependencyCount() == 0) {
          next = c;
          break;
        }
      }

      // More?
      if (next != null) runComponentAsync(next);

      // Done?
      else {
        // Stop wait for components to load.
        if ((timer != null) && (runList.size() == 0)) {
          timer.cancel();
          timer = null;
        }
        invokeReadyCallbacks();
      }
    }
  }
예제 #7
0
 /**
  * Runs the next component in the run list.
  *
  * <p>However, components depending on this component are not activated; we simply skip over it
  * and wait for other ones which are ready to finish running.
  */
 public void componentFailed(Component target) {
   if (runList.contains(target)) runList.remove(target);
   ComponentLog.trace("Failed trying to run component: " + target.toString());
   componentReady(null);
 }