Package org.jboss.dependency.spi

Examples of org.jboss.dependency.spi.Controller


    */
   protected boolean incrementState(ControllerContext context, boolean trace)
   {
      ControllerState fromState = context.getState();

      Controller fromController = context.getController();
      Set<ControllerContext> fromContexts = null;

      int currentIndex = -1;
      if (ControllerState.ERROR.equals(fromState))
      {
         errorContexts.remove(context);
         Throwable error = null;
         unlockWrite();
         try
         {
            install(context, ControllerState.ERROR, ControllerState.NOT_INSTALLED);
         }
         catch (Throwable t)
         {
            error = t;
         }
         finally
         {
            lockWrite();
            if (error != null)
            {
               log.error("Error during initial installation: " + context.toShortString(), error);
               context.setError(error);
               errorContexts.put(context.getName(), context);
               return false;
            }
         }
         Set<ControllerContext> notInstalled = fromController.getContextsByState(ControllerState.NOT_INSTALLED);
         notInstalled.add(context);
         context.setState(ControllerState.NOT_INSTALLED);
      }
      else
      {
         currentIndex = states.indexOf(fromState);
         fromContexts = fromController.getContextsByState(fromState);
         if (fromContexts.contains(context) == false)
            throw new IllegalStateException("Context not found in previous state: " + context.toShortString());
      }

      int toIndex = currentIndex + 1;
      ControllerState toState = states.get(toIndex);

      unlockWrite();
      Throwable error = null;
      try
      {
         install(context, fromState, toState);

         if (fromContexts != null)
            fromContexts.remove(context);
         Controller toController = context.getController();
         Set<ControllerContext> toContexts = toController.getContextsByState(toState);
         toContexts.add(context);
         context.setState(toState);

         handleInstallLifecycleCallbacks(context, toState);
         resolveCallbacks(context, toState, true);
View Full Code Here


      ControllerState fromState = context.getState();

      if (trace)
         log.trace("Uninstalling " + name + " from " + fromState.getStateString());

      Controller fromController = context.getController();

      Set<ControllerContext> fromContexts = fromController.getContextsByState(fromState);
      if (fromContexts == null || fromContexts.remove(context) == false)
         throw new Error("INTERNAL ERROR: context not found in previous state " + fromState.getStateString() + " context=" + context.toShortString(), new Exception("STACKTRACE"));

      DependencyInfo dependencies = context.getDependencyInfo();
      if (dependencies != null)
      {
         try
         {
            Set<DependencyItem> dependsOnMe = dependencies.getDependsOnMe(null);
            if (dependsOnMe.isEmpty() == false)
            {
               for (DependencyItem item : dependsOnMe)
               {
                  if (item.isResolved())
                  {
                     ControllerState dependentState = item.getDependentState();
                     if (dependentState == null || dependentState.equals(fromState))
                     {
                        if (item.unresolved(this))
                        {
                           Set<ControllerContext> dependents = CollectionsFactory.createLazySet();
                           getContexts(item.getName(), dependents);
                           if (dependents.isEmpty() == false)
                           {
                              ControllerState whenRequired = item.getWhenRequired();
                              if (whenRequired == null)
                                 whenRequired = ControllerState.NOT_INSTALLED;

                              for (ControllerContext dependent : dependents)
                              {
                                 if (isBeforeState(dependent.getState(), whenRequired) == false)
                                    uninstallContext(dependent, whenRequired, trace);
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
         catch (Throwable error)
         {
            log.error("Error resolving dependencies for " + fromState.getStateString() + ": " + context.toShortString(), error);
            // Not much else we can do - no uninstall, since we are at uninstall ;-)
            errorContexts.put(context.getName(), context);
            context.setError(error);
         }
      }

      // The state could have changed while calling out to dependents
      fromState = context.getState();
      if (ControllerState.ERROR.equals(fromState))
         return;
     
      // Calculate the previous state
      int currentIndex = states.indexOf(fromState);
      int toIndex = currentIndex - 1;
      if (toIndex < 0)
      {
         // This is hack, we signal true uninstalled status by putting it in the error state
         context.setState(ControllerState.ERROR);
         return;
      }

      ControllerState toState = states.get(toIndex);

      unlockWrite();
      try
      {
         resolveCallbacks(context, fromState, false);
         handleUninstallLifecycleCallbacks(context, toState);

         uninstall(context, fromState, toState);

         Controller toController = context.getController();
         Set<ControllerContext> toContexts = toController.getContextsByState(toState);
         toContexts.add(context);
         context.setState(toState);
      }
      catch (Throwable t)
      {
View Full Code Here

    * @return  kernel controller context
    * @throws IllegalArgumentException if context not found or not KernelControllerContext
    */
   protected KernelControllerContext getKernelControllerContext(Kernel kernel, String bean)
   {
      Controller controller = kernel.getController();
      ControllerContext context = controller.getContext(bean, null);
      if (context == null)
         throw new IllegalArgumentException("Should not be here, dependency failed, no such context: " + bean);
      if (context instanceof KernelControllerContext == false)
         throw new IllegalArgumentException("Context not KernelControllerContext: " + context);

View Full Code Here

   @SuppressWarnings({"unchecked", "deprecation"})
   public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
   {
      if (context == null)
         throw new IllegalStateException("Context has not been set: " + this);
      Controller controller = context.getController();
      ControllerContext lookup = controller.getInstalledContext(name);
      if (lookup == null || lookup.getTarget() == null)
      {
         // possible call for classloader
         if (info == null && classLoader != null && classLoader.getClassLoader() == this)
         {
View Full Code Here

    * @param state the state
    * @return the controller context
    */
   protected ControllerContext getControllerContext(Object name, ControllerState state)
   {
      Controller controller = context.getController();
      LookupStrategy strategy = search.getStrategy();
      return strategy.getContext(controller, name, state);
   }
View Full Code Here

      {
         return null;
      }
      else if (isOptional())
      {
         Controller controller = context.getController();
         addOptionalDependency(controller, lookup);
      }

      Object result;
      if (property != null && property.length() > 0)
View Full Code Here

   protected KernelControllerContext getControllerContext(final Object name, final ControllerState state)
   {
      try
      {
         Controller controller = kernel.getController();
         GraphController gc = (GraphController)controller;
         KernelControllerContext context = (KernelControllerContext)gc.getContext(name, state, Search.DEPTH);
         if (context == null)
            throw new IllegalStateException("Bean not found " + name + " at state " + state);
         return context;
View Full Code Here

    * @return the actual state
    * @throws Throwable for any error
    */
   protected ControllerState change(KernelControllerContext context, ControllerState required) throws Throwable
   {
      Controller controller = kernel.getController();
      controller.change(context, required);
      return context.getState();
   }
View Full Code Here

               assertTrue(hasExpectedInterception("Intercepted", ControllerState.START));

               SimpleLifecycleCallback.clear();

               ControllerContext ctx = getControllerContext("Intercepted");
               Controller controller = ctx.getController();
              
               //Move the bean intercepted to pre-install state
               controller.change(ctx, ControllerState.PRE_INSTALL);

               assertEquals(2, SimpleLifecycleCallback.interceptions.size());
               assertTrue(hasExpectedInterception("Intercepted", ControllerState.CONFIGURED));
               assertTrue(hasExpectedInterception("Intercepted", ControllerState.START));
              
               //Undeploy the second aspect
               undeploy("UndeployLifecycleCallbackDependencyTestCaseNotAutomatic1.xml");
              
               //Move the bean back to the installed state
               controller.change(ctx, ControllerState.INSTALLED);
              
               bean = (SimpleBeanImpl)getBean("Intercepted");
//               SimpleInterceptor1.invoked = false;
//               SimpleInterceptor2.invoked = false;
//               bean.someMethod();
View Full Code Here

   }

   public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
   {
      // we're here, so it must be GraphController instance
      Controller controller = context.getController();
      GraphController gc = (GraphController)controller;

      ControllerState dependentState = state;
      if (dependentState == null)
         dependentState = ControllerState.INSTALLED;
View Full Code Here

TOP

Related Classes of org.jboss.dependency.spi.Controller

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.