Package jfun.yan.lifecycle

Examples of jfun.yan.lifecycle.DefaultLifecycleManager


    final Container context = cinterpreter.getContainer().inherit(base);
    final Container2ApplicationContext ctxt = (Container2ApplicationContext)
    context.getInstance("appcontext");
   
    final Container nuts = spring.getContainer();
    final DefaultLifecycleManager manager = processor.getLifecycleManager();
   
    //final BeanPostProcessorQueue bppq = new BeanPostProcessorQueue();
    //nuts.registerValue(newBeanLifecycle(manager));
    //nuts.registerValue(ctxt);
    //nuts.registerValue(yan);
View Full Code Here


      final Component real_engine =
        Components.useKey("real engine").singleton(new ThreadLocalScope());
      final DefaultLifecycleDescriptor desc = new DefaultLifecycleDescriptor();
      desc.setCloser(new Phase(desc.getCloser().getPhaseKey(), ExceptionHandlers.suppresser()));
      desc.setStopper(new Phase(desc.getStopper().getPhaseKey(), ExceptionHandlers.suppresser()));
      final DefaultLifecycleManager lm = new DefaultLifecycleManager(desc);
      final DefaultLifecycleManager.DefaultLifecycle lc = lm.newLifecycle()
      .starter("start")
      .stopper("stop")
      .initializer("initialize")
      .disposer("destroy");
      final Component engine_lc = lc.manage(real_engine);
      yan.registerComponent(CarEngine.class, engine_lc);
      /*
      yan.registerComponent(CarEngine.class, LifecycleDescriptor.instance(
          Components.useKey("real engine").singleton(new ThreadLocalScope()),
          ExceptionHandlers.suppresser())
          .starter("start")
          .stopper("stop")
          .initializer("initialize")
          .disposer("destroy")
          .get());
      */
      yan.registerConstructor("real engine", CarEngine.class);
      final Component sttfrc = Components.ctor(StatefulResource.class)
      .withArgument(0, Components.useType(CarEngine.class));
      yan.registerComponent(lc.manage(sttfrc));
      /*
      yan.registerComponent(LifecycleDescriptor.instance(
          Components.ctor(StatefulResource.class)
          .withArgument(0, Components.useType(CarEngine.class))
          , ExceptionHandlers.suppresser())
          .initializer("initialize")
          .disposer("destroy")
          .starter("start")
          .stopper("stop")
          .get());
      */
      final Component car_engine = yan.getComponentOfType(CarEngine.class);
      assertNull(car_engine.getType());
     
      final StatefulResource resource = (StatefulResource)yan.getInstanceOfType(StatefulResource.class);
      final CarEngine engine = (CarEngine)yan.getInstanceOfType(CarEngine.class);
      assertEquals(0, engine.getStarted());
      assertEquals(0, engine.getStopped());
      assertEquals(0, engine.getInit());
      assertEquals(0, engine.getDisposed());

      assertEquals(0, resource.getInitCount());
      assertEquals(0, resource.getDestroyedCount());
      //new DefaultLifecycle(yan).init();
      lm.init();
      assertEquals(0, engine.getStarted());
      assertEquals(0, engine.getStopped());
      assertEquals(1, engine.getInit());
      assertEquals(0, engine.getDisposed());

      assertEquals(1, resource.getInitCount());
      assertEquals(0, resource.getDestroyedCount());
      try{
        //new DefaultLifecycle(yan).start();
        lm.start();
        fail("should have failed with unsupported");
      }
      catch(UnsupportedOperationException e){
        assertEquals("start", e.getMessage());
      }
      assertEquals(1, engine.getStarted());
      assertEquals(0, engine.getStopped());
      assertEquals(1, engine.getInit());
      assertEquals(0, engine.getDisposed());

      assertEquals(1, resource.getInitCount());
      assertEquals(0, resource.getDestroyedCount());
      //new DefaultLifecycle(yan).init();
      lm.init();
      assertEquals(1, engine.getStarted());
      assertEquals(0, engine.getStopped());
      assertEquals(1, engine.getInit());
      assertEquals(0, engine.getDisposed());

      assertEquals(1, resource.getInitCount());
      assertEquals(0, resource.getDestroyedCount());
      //new DefaultLifecycle(yan).stop();
      lm.stop();
      assertEquals(1, engine.getStarted());
      assertEquals(1, engine.getStopped());
      assertEquals(1, engine.getInit());
      assertEquals(0, engine.getDisposed());

      assertEquals(1, resource.getInitCount());
      assertEquals(0, resource.getDestroyedCount());
      //final DefaultLifecycle lc = new DefaultLifecycle(yan);
      //lc.dispose();
      lm.dispose();
      assertEquals(1, engine.getStarted());
      assertEquals(1, engine.getStopped());
      assertEquals(1, engine.getInit());
      assertEquals(1, engine.getDisposed());

      assertEquals(1, resource.getInitCount());
      assertEquals(1, resource.getDestroyedCount());
     
      try{
        //lc.start();
        lm.start();
        fail("should have failed with unsupported");
      }
      catch(UnsupportedOperationException e){
        assertEquals("start", e.getMessage());
      }
      assertEquals(2, engine.getStarted());
      assertEquals(1, engine.getStopped());
      assertEquals(1, engine.getInit());
      assertEquals(1, engine.getDisposed());

      assertEquals(1, resource.getInitCount());
      assertEquals(1, resource.getDestroyedCount());

     
      //lc.stop();
      lm.stop();
      assertEquals(2, engine.getStarted());
      assertEquals(2, engine.getStopped());
      assertEquals(1, engine.getInit());
      assertEquals(1, engine.getDisposed());

View Full Code Here

      assertBool(data.getter("inners", 1).getter("active"), true);

    }
    public void testComponentManagedByMoreThanOneLifecycleManagers()
    throws Throwable{
      DefaultLifecycleManager man1 = new DefaultLifecycleManager();
      DefaultLifecycleManager man2 = new DefaultLifecycleManager();
      Component c = Components.ctor(Automobile.class);
      c = man1.newLifecycle()
        .starter("start1")
        .stopper("stop1")
        .manage(c);
      c = man2.newLifecycle()
        .starter("start2")
        .stopper("stop2")
        .manage(c);
      Container yan = createYanContainer();
      yan.registerComponent("target", c);
      Automobile a = (Automobile)yan.getInstance("target");
      assertFalse(a.isRunning1());
      assertFalse(a.isRunning2());
      man1.start();
      assertTrue(a.isRunning1());
      assertFalse(a.isRunning2());
      man2.start();
      assertTrue(a.isRunning1());
      assertTrue(a.isRunning2());  
      man1.stop();
      assertFalse(a.isRunning1());
      assertTrue(a.isRunning2());
      man2.stop();
      assertFalse(a.isRunning1());
      assertFalse(a.isRunning2());
    }
View Full Code Here

      assertEquals("Ben", acc1.getOwner().getName());
    }
    public void testVerify1()
    throws Throwable{
      final Container yan = this.createYanContainer();
      final DefaultLifecycleManager man = new DefaultLifecycleManager();

      Component mybean = Components.bean(MyBean.class, new String[]{"1","short"});
      mybean = man.newLifecycle()
      .verifier("verify")
      .manage(mybean);
      yan.registerValue(new Short((short)1));
      yan.registerValue(Boolean.valueOf(true));
      yan.registerComponent("target", mybean);
      MyBean bean = (MyBean)yan.getInstance("target");
      assertTrue(bean.is1());
      try{
        man.verify();
      }
      catch(IllegalStateException e){
        return;
      }
      fail("should have failed with illegal state");
View Full Code Here

   * @param yan the container that registeres the components.
   */
  public NutsProcessor(ClassLoader cloader, ResourceLoader rloader,
      Container yan){
    this(cloader, rloader, yan,
        new DefaultLifecycleManager(), new File(".").getAbsoluteFile());
  }
View Full Code Here

TOP

Related Classes of jfun.yan.lifecycle.DefaultLifecycleManager

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.