onami-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject svn commit: r1606430 - in /onami/trunk/lifecycle: core/src/main/java/org/apache/onami/lifecycle/core/ core/src/test/java/org/apache/onami/lifecycle/core/ standard/src/main/java/org/apache/onami/lifecycle/standard/ standard/src/test/java/org/apache/onam...
Date Sun, 29 Jun 2014 05:50:38 GMT
Author: ash2k
Date: Sun Jun 29 05:50:37 2014
New Revision: 1606430

URL: http://svn.apache.org/r1606430
Log:
ONAMI-102 Redesign module API

Added:
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractBasicStageable.java
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractStageable.java
Removed:
    onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/DefaultDisposer.java
    onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/Disposable.java
    onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/DisposeHandler.java
    onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/Disposer.java
    onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/StagerWrapper.java
Modified:
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractMethodTypeListener.java
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/DefaultStager.java
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleModule.java
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleStageModule.java
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/NoOpStageableTypeMapper.java
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/Stageable.java
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableTypeMapper.java
    onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/DefaultStagerTestCase.java
    onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/MultiLifeCycleTestCase.java
    onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/AfterInjectionModule.java
    onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/DisposeModule.java
    onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeModuleTestCase.java
    onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeTestCase.java
    onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUpModule.java
    onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUper.java
    onami/trunk/lifecycle/warmup/src/test/java/org/apachi/onami/lifecycle/warmup/TestWarmUpManager.java

Added: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractBasicStageable.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractBasicStageable.java?rev=1606430&view=auto
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractBasicStageable.java (added)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractBasicStageable.java Sun Jun 29 05:50:37 2014
@@ -0,0 +1,50 @@
+package org.apache.onami.lifecycle.core;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Base implementation for stageables.
+ *
+ * @author Mikhail Mazursky
+ */
+public abstract class AbstractBasicStageable<S>
+    implements Stageable
+{
+
+    /**
+     * Object to stage.
+     */
+    protected final S object;
+
+    protected AbstractBasicStageable( S object )
+    {
+        this.object = object;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final String toString()
+    {
+        return object.toString();
+    }
+
+}

Modified: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractMethodTypeListener.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractMethodTypeListener.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractMethodTypeListener.java (original)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractMethodTypeListener.java Sun Jun 29 05:50:37 2014
@@ -42,14 +42,14 @@ abstract class AbstractMethodTypeListene
     /**
      * The lifecycle annotations to search on methods in the order to be searched.
      */
-    private final List<Class<? extends Annotation>> annotationTypes;
+    protected final List<? extends Class<? extends Annotation>> annotationTypes;
 
     /**
      * Creates a new methods listener instance.
      *
      * @param annotationTypes the lifecycle annotations to search on methods in the order to be searched.
      */
-    public AbstractMethodTypeListener( List<Class<? extends Annotation>> annotationTypes )
+    public AbstractMethodTypeListener( List<? extends Class<? extends Annotation>> annotationTypes )
     {
         this.annotationTypes = annotationTypes;
     }
@@ -97,16 +97,6 @@ abstract class AbstractMethodTypeListene
     }
 
     /**
-     * Returns the lifecycle annotation to search on methods.
-     *
-     * @return the lifecycle annotation to search on methods.
-     */
-    protected final List<Class<? extends Annotation>> getAnnotationTypes()
-    {
-        return annotationTypes;
-    }
-
-    /**
      * Allows implementations to define the behavior when lifecycle annotation is found on the method.
      *
      * @param method         encountered by this type handler.

Added: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractStageable.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractStageable.java?rev=1606430&view=auto
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractStageable.java (added)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/AbstractStageable.java Sun Jun 29 05:50:37 2014
@@ -0,0 +1,60 @@
+package org.apache.onami.lifecycle.core;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Base implementation for stageables.
+ *
+ * @author Mikhail Mazursky
+ */
+public abstract class AbstractStageable<S>
+    extends AbstractBasicStageable<S>
+{
+
+    protected AbstractStageable( S object )
+    {
+        super( object );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final void stage( StageHandler stageHandler )
+    {
+        try
+        {
+            doStage();
+        }
+        catch ( Throwable e )
+        {
+            stageHandler.onError( object, e );
+            return;
+        }
+        stageHandler.onSuccess( object );
+    }
+
+    /**
+     * Does actual object staging.
+     *
+     * @throws Exception
+     */
+    protected abstract void doStage() throws Exception;
+}

Modified: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/DefaultStager.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/DefaultStager.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/DefaultStager.java (original)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/DefaultStager.java Sun Jun 29 05:50:37 2014
@@ -39,9 +39,17 @@ public class DefaultStager<A extends Ann
 
     /**
      * @param stage the annotation that specifies this stage
+     */
+    public DefaultStager( Class<A> stage )
+    {
+        this( stage, Order.FIRST_IN_FIRST_OUT );
+    }
+
+	/**
+     * @param stage the annotation that specifies this stage
      * @param mode  execution order
      */
-    protected DefaultStager( Class<A> stage, Order mode )
+    public DefaultStager( Class<A> stage, Order mode )
     {
         this.stage = stage;
 
@@ -69,29 +77,6 @@ public class DefaultStager<A extends Ann
     }
 
     /**
-     * Allocate a new stager
-     *
-     * @param stage the stage annotation
-     * @return stager
-     */
-    public static <A extends Annotation> Stager<A> newStager( Class<A> stage )
-    {
-        return newStager( stage, Order.FIRST_IN_FIRST_OUT );
-    }
-
-    /**
-     * Allocate a new stager
-     *
-     * @param stage the stage annotation
-     * @param mode  execution order
-     * @return stager
-     */
-    public static <A extends Annotation> Stager<A> newStager( Class<A> stage, Order mode )
-    {
-        return new DefaultStager<A>( stage, mode );
-    }
-
-    /**
      * {@inheritDoc}
      */
     public void register( Stageable stageable )

Modified: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleModule.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleModule.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleModule.java (original)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleModule.java Sun Jun 29 05:50:37 2014
@@ -19,6 +19,7 @@ package org.apache.onami.lifecycle.core;
  * under the License.
  */
 
+import com.google.inject.AbstractModule;
 import com.google.inject.ProvisionException;
 import com.google.inject.TypeLiteral;
 import com.google.inject.matcher.Matcher;
@@ -30,68 +31,47 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.Method;
 import java.util.List;
 
+import static com.google.inject.matcher.Matchers.any;
 import static java.lang.String.format;
+import static java.util.Arrays.asList;
 
 /**
  * Guice module to register methods to be invoked after injection is complete.
  */
-public final class LifeCycleModule
-    extends AbstractLifeCycleModule
+public abstract class LifeCycleModule
+    extends AbstractModule
 {
 
     /**
-     * Creates a new module which looks for the input lifecycle annotation on methods in any type.
+     * Binds lifecycle listener.
      *
-     * @param annotationType the lifecycle annotation to be searched.
+     * @param annotation the lifecycle annotation to be searched.
      */
-    public <A extends Annotation> LifeCycleModule( Class<A> annotationType )
+    protected final void bindLifeCycle( Class<? extends Annotation> annotation )
     {
-        super( annotationType );
+        bindLifeCycle( annotation, any() );
     }
 
     /**
-     * Creates a new module which looks for the input lifecycle annotation on methods
-     * in types filtered by the input matcher.
+     * Binds lifecycle listener.
      *
-     * @param annotationType the lifecycle annotation to be searched.
-     * @param typeMatcher    the filter for injectee types.
+     * @param annotation  the lifecycle annotation to be searched.
+     * @param typeMatcher the filter for injectee types.
      */
-    public <A extends Annotation> LifeCycleModule( Class<A> annotationType,
-                                                   Matcher<? super TypeLiteral<?>> typeMatcher )
+    protected final void bindLifeCycle( Class<? extends Annotation> annotation, Matcher<? super TypeLiteral<?>> typeMatcher )
     {
-        super( annotationType, typeMatcher );
+        bindLifeCycle( asList( annotation ), typeMatcher );
     }
 
     /**
-     * Creates a new module which looks for the input lifecycle annotations on methods in any type.
+     * Binds lifecycle listener.
      *
-     * @param annotationTypes the lifecycle annotations to be searched in the order to be searched.
+     * @param annotations  the lifecycle annotations to be searched in the order to be searched.
+     * @param typeMatcher the filter for injectee types.
      */
-    public LifeCycleModule( List<Class<? extends Annotation>> annotationTypes )
+    protected final void bindLifeCycle( List<? extends Class<? extends Annotation>> annotations, Matcher<? super TypeLiteral<?>> typeMatcher )
     {
-        super( annotationTypes );
-    }
-
-    /**
-     * Creates a new module which looks for the input lifecycle annotations on methods
-     * in types filtered by the input matcher.
-     *
-     * @param annotationTypes the lifecycle annotations to be searched in the order to be searched.
-     * @param typeMatcher     the filter for injectee types.
-     */
-    public LifeCycleModule( List<Class<? extends Annotation>> annotationTypes,
-                            Matcher<? super TypeLiteral<?>> typeMatcher )
-    {
-        super( annotationTypes, typeMatcher );
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void configure()
-    {
-        bindListener( getTypeMatcher(), new AbstractMethodTypeListener( getAnnotationTypes() )
+        bindListener( typeMatcher, new AbstractMethodTypeListener( annotations )
         {
 
             @Override

Modified: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleStageModule.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleStageModule.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleStageModule.java (original)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/LifeCycleStageModule.java Sun Jun 29 05:50:37 2014
@@ -29,68 +29,22 @@ import com.google.inject.util.Types;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
+import java.util.ArrayList;
+import java.util.List;
 
 import static com.google.inject.matcher.Matchers.any;
+import static java.util.Arrays.asList;
 
 /**
  * Guice module to register methods to be invoked when {@link Stager#stage()} is invoked.
  * <p/>
  * Module instance have has so it must not be used to construct more than one {@link com.google.inject.Injector}.
  */
-public final class LifeCycleStageModule<A extends Annotation>
-    extends AbstractLifeCycleModule
+public abstract class LifeCycleStageModule
+    extends LifeCycleModule
 {
 
-    private final Stager<A> stager;
-
-    private final StageableTypeMapper<A> typeMapper;
-
-    /**
-     * Creates a new module which register methods annotated with input annotation on methods in any type.
-     *
-     * @param stager the annotation that represents this stage and the methods with this annotation
-     */
-    public LifeCycleStageModule( Stager<A> stager )
-    {
-        this( stager, any() );
-    }
-
-    /**
-     * Creates a new module which register methods annotated with input annotation on methods
-     * in types filtered by the input matcher.
-     *
-     * @param stager      the annotation that represents this stage and the methods with this annotation
-     * @param typeMatcher the filter for injectee types.
-     */
-    public LifeCycleStageModule( Stager<A> stager, Matcher<? super TypeLiteral<?>> typeMatcher )
-    {
-        super( stager.getStage(), typeMatcher );
-        this.stager = stager;
-        typeMapper = new NoOpStageableTypeMapper<A>();
-    }
-
-    /**
-     * Creates a new module from the supplied {@link Builder}.
-     *
-     * @param builder settings container.
-     */
-    LifeCycleStageModule( Builder<A> builder )
-    {
-        super( builder.stager.getStage(), builder.typeMatcher );
-        this.stager = builder.stager;
-        this.typeMapper = builder.typeMapper;
-    }
-
-    /**
-     * Allows one to create {@link LifeCycleStageModule} with builder pattern.
-     *
-     * @param stage the annotation that represents this stage and the methods with this annotation
-     * @return builder for {@link LifeCycleStageModule}.
-     */
-    public static <A extends Annotation> Builder<A> builder( Class<A> stage )
-    {
-        return new Builder<A>( stage );
-    }
+    private List<BindingBuilder<?>> bindings;
 
     /**
      * Convenience to generate the correct key for retrieving stagers from an injector.
@@ -122,11 +76,34 @@ public final class LifeCycleStageModule<
      * {@inheritDoc}
      */
     @Override
-    protected void configure()
+    protected final void configure()
+    {
+        if ( bindings != null )
+        {
+            throw new IllegalStateException( "Re-entry is not allowed" );
+        }
+        bindings = new ArrayList<BindingBuilder<?>>();
+        try
+        {
+            configureBindings();
+            for ( BindingBuilder<?> binding : bindings )
+            {
+                bind( binding );
+            }
+        }
+        finally
+        {
+            bindings = null;
+        }
+    }
+
+    private <A extends Annotation> void bind( BindingBuilder<A> binding )
     {
+        final Stager<A> stager = binding.stager;
+        final StageableTypeMapper typeMapper = binding.typeMapper;
         bind( type( stager.getStage() ) ).toInstance( stager );
 
-        bindListener( getTypeMatcher(), new AbstractMethodTypeListener( getAnnotationTypes() )
+        bindListener( binding.typeMatcher, new AbstractMethodTypeListener( asList( stager.getStage() ) )
         {
 
             @Override
@@ -150,78 +127,73 @@ public final class LifeCycleStageModule<
         } );
     }
 
+    protected abstract void configureBindings();
+
+    protected final <A extends Annotation> MapperBinding bindStager( Stager<A> stager )
+    {
+        BindingBuilder<A> builder = new BindingBuilder<A>( checkNotNull( stager, "Argument 'stager' must be not null" ) );
+        bindings.add( builder );
+        return builder;
+    }
+
+    protected interface MatcherBinding
+    {
+        /**
+         * Sets the filter for injectee types.
+         *
+         * @param typeMatcher the filter for injectee types.
+         */
+        void matching( Matcher<? super TypeLiteral<?>> typeMatcher );
+    }
+
+    protected interface MapperBinding extends MatcherBinding
+    {
+        /**
+         * Sets the container to register mappings from {@link Stageable}s to the types that created them.
+         *
+         * @param typeMapper container to map {@link Stageable}s to types.
+         */
+        MatcherBinding mappingWith( StageableTypeMapper typeMapper );
+    }
+
     /**
      * Builder pattern helper.
      */
-    public static final class Builder<A extends Annotation>
+    private static class BindingBuilder<A extends Annotation> implements MapperBinding
     {
 
         private Matcher<? super TypeLiteral<?>> typeMatcher = any();
 
-        private Stager<A> stager;
-
-        private StageableTypeMapper<A> typeMapper = new NoOpStageableTypeMapper<A>();
+        private final Stager<A> stager;
 
-        Builder( Class<A> annotationClass )
-        {
-            stager = new DefaultStager<A>( annotationClass, DefaultStager.Order.FIRST_IN_FIRST_OUT );
-        }
+        private StageableTypeMapper typeMapper = new NoOpStageableTypeMapper();
 
-        private static <T> T checkNotNull( T object, String message )
-        {
-            if ( object == null )
-            {
-                throw new IllegalArgumentException( message );
-            }
-            return object;
-        }
-
-        /**
-         * Builds {@link LifeCycleStageModule} with given settings.
-         *
-         * @return {@link LifeCycleStageModule} with given settings.
-         */
-        public LifeCycleStageModule<A> build()
+        public BindingBuilder( Stager<A> stager )
         {
-            return new LifeCycleStageModule<A>( this );
+            this.stager = stager;
         }
 
-        /**
-         * Sets the filter for injectee types.
-         *
-         * @param typeMatcher the filter for injectee types.
-         * @return self
-         */
-        public Builder<A> withTypeMatcher( Matcher<? super TypeLiteral<?>> typeMatcher )
+        @Override
+        public MatcherBinding mappingWith( StageableTypeMapper typeMapper )
         {
-            this.typeMatcher = checkNotNull( typeMatcher, "Argument 'typeMatcher' must be not null." );
+            this.typeMapper = checkNotNull( typeMapper, "Argument 'typeMapper' must be not null." );
             return this;
         }
 
-        /**
-         * Sets the container to register disposable objects.
-         *
-         * @param stager container to register disposable objects.
-         * @return self
-         */
-        public Builder<A> withStager( Stager<A> stager )
+        @Override
+        public void matching( Matcher<? super TypeLiteral<?>> typeMatcher )
         {
-            this.stager = checkNotNull( stager, "Argument 'stager' must be not null." );
-            return this;
+            this.typeMatcher = checkNotNull( typeMatcher, "Argument 'typeMatcher' must be not null" );
         }
 
-        /**
-         * Sets the container to register mappings from {@link Stageable}s to the types that created them.
-         *
-         * @param typeMapper container to map {@link Stageable}s to types
-         * @return self
-         */
-        public Builder<A> withTypeMapper( StageableTypeMapper<A> typeMapper )
+    }
+
+    private static <T> T checkNotNull( T object, String message )
+    {
+        if ( object == null )
         {
-            this.typeMapper = checkNotNull( typeMapper, "Argument 'typeMapper' must be not null." );
-            return this;
+            throw new IllegalArgumentException( message );
         }
-
+        return object;
     }
-
 }

Modified: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/NoOpStageableTypeMapper.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/NoOpStageableTypeMapper.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/NoOpStageableTypeMapper.java (original)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/NoOpStageableTypeMapper.java Sun Jun 29 05:50:37 2014
@@ -21,10 +21,8 @@ package org.apache.onami.lifecycle.core;
 
 import com.google.inject.TypeLiteral;
 
-import java.lang.annotation.Annotation;
-
-class NoOpStageableTypeMapper<A extends Annotation>
-    implements StageableTypeMapper<A>
+class NoOpStageableTypeMapper
+    implements StageableTypeMapper
 {
 
     public <I> void registerType( Stageable stageable, TypeLiteral<I> parentType )

Modified: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/Stageable.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/Stageable.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/Stageable.java (original)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/Stageable.java Sun Jun 29 05:50:37 2014
@@ -33,4 +33,9 @@ public interface Stageable
      */
     void stage( StageHandler stageHandler );
 
+    /**
+     * @return Description of a stageable resource.
+     */
+    @Override
+    String toString();
 }

Modified: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java (original)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java Sun Jun 29 05:50:37 2014
@@ -27,7 +27,7 @@ import java.lang.reflect.Method;
  * and related method to release resources.
  */
 final class StageableMethod
-    implements Stageable
+    extends AbstractBasicStageable<Object>
 {
 
     /**
@@ -36,11 +36,6 @@ final class StageableMethod
     private final Method stageMethod;
 
     /**
-     * The target injectee has to stage the resources.
-     */
-    private final Object injectee;
-
-    /**
      * Creates a new {@link StageableMethod} reference.
      *
      * @param stageMethod the method to be invoked to stage resources.
@@ -48,32 +43,34 @@ final class StageableMethod
      */
     StageableMethod( Method stageMethod, Object injectee )
     {
+        super( injectee );
         this.stageMethod = stageMethod;
-        this.injectee = injectee;
     }
 
     /**
      * {@inheritDoc}
      */
-    public void stage( StageHandler stageHandler )
+    public final void stage( StageHandler stageHandler )
     {
         try
         {
-            stageMethod.invoke( injectee );
-            stageHandler.onSuccess( injectee );
+            if ( !stageMethod.isAccessible() )
+            {
+                stageMethod.setAccessible( true );
+            }
+            stageMethod.invoke( object );
         }
-        catch ( IllegalArgumentException e )
-        {
-            stageHandler.onError( injectee, e );
-        }
-        catch ( IllegalAccessException e )
+        catch ( InvocationTargetException e )
         {
-            stageHandler.onError( injectee, e );
+            stageHandler.onError( object, e.getCause() );
+            return;
         }
-        catch ( InvocationTargetException e )
+        catch ( Throwable e )
         {
-            stageHandler.onError( injectee, e.getCause() );
+            stageHandler.onError( object, e );
+            return;
         }
+        stageHandler.onSuccess( object );
     }
 
-}
\ No newline at end of file
+}

Modified: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableTypeMapper.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableTypeMapper.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableTypeMapper.java (original)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableTypeMapper.java Sun Jun 29 05:50:37 2014
@@ -21,13 +21,11 @@ package org.apache.onami.lifecycle.core;
 
 import com.google.inject.TypeLiteral;
 
-import java.lang.annotation.Annotation;
-
 /**
  * Container for mapping a {@link Stageable} to the parent type
  * that created it. Useful in specialty Stage containers.
  */
-public interface StageableTypeMapper<A extends Annotation>
+public interface StageableTypeMapper
 {
 
     /**

Modified: onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/DefaultStagerTestCase.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/DefaultStagerTestCase.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/DefaultStagerTestCase.java (original)
+++ onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/DefaultStagerTestCase.java Sun Jun 29 05:50:37 2014
@@ -31,7 +31,7 @@ public class DefaultStagerTestCase
     public void stagerShouldStageObjectsRegisteredWhileStaging()
     {
         final Stager<TestAnnotationA> stager =
-                DefaultStager.newStager( TestAnnotationA.class );
+                new DefaultStager<TestAnnotationA>( TestAnnotationA.class );
         final AtomicBoolean staged = new AtomicBoolean();
         stager.register( new Stageable()
         {
@@ -63,7 +63,7 @@ public class DefaultStagerTestCase
     {
         final AtomicBoolean staged = new AtomicBoolean();
         final Stager<TestAnnotationA> stager =
-                DefaultStager.newStager( TestAnnotationA.class );
+                new DefaultStager<TestAnnotationA>( TestAnnotationA.class );
         stager.register( new Stageable()
         {
             public void stage( StageHandler stageHandler )

Modified: onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/MultiLifeCycleTestCase.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/MultiLifeCycleTestCase.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/MultiLifeCycleTestCase.java (original)
+++ onami/trunk/lifecycle/core/src/test/java/org/apache/onami/lifecycle/core/MultiLifeCycleTestCase.java Sun Jun 29 05:50:37 2014
@@ -19,6 +19,9 @@ package org.apache.onami.lifecycle.core;
  * under the License.
  */
 
+import static com.google.inject.matcher.Matchers.any;
+import static java.util.Arrays.asList;
+
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Inject;
@@ -27,14 +30,16 @@ import com.google.inject.Module;
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.lang.annotation.Annotation;
+import java.util.List;
+
 public class MultiLifeCycleTestCase
 {
     @Test
     public void testOrdering()
     {
-        LifeCycleModule lifeCycleModule = new LifeCycleModule(
-            ListBuilder.builder().append( TestAnnotationA.class ).append( TestAnnotationB.class ).append(
-                TestAnnotationC.class ).build() );
+        Module lifeCycleModule = new TestLifeCycleModule(
+            asList( TestAnnotationA.class, TestAnnotationB.class, TestAnnotationC.class ) );
         MultiLifeCycleObject obj = Guice.createInjector( lifeCycleModule ).getInstance( MultiLifeCycleObject.class );
         Assert.assertEquals( "aaabbbc", obj.toString() );
     }
@@ -51,12 +56,12 @@ public class MultiLifeCycleTestCase
     @Test
     public void testStaging()
     {
-        LifeCycleStageModule<TestAnnotationA> moduleA =
-            new LifeCycleStageModule<TestAnnotationA>( DefaultStager.newStager( TestAnnotationA.class ) );
-        LifeCycleStageModule<TestAnnotationB> moduleB =
-            new LifeCycleStageModule<TestAnnotationB>( DefaultStager.newStager( TestAnnotationB.class ) );
-        LifeCycleStageModule<TestAnnotationC> moduleC =
-            new LifeCycleStageModule<TestAnnotationC>( DefaultStager.newStager( TestAnnotationC.class ) );
+        Module moduleA =
+            new TestLifeCycleStageModule( new DefaultStager<TestAnnotationA>( TestAnnotationA.class ) );
+        Module moduleB =
+            new TestLifeCycleStageModule( new DefaultStager<TestAnnotationB>( TestAnnotationB.class ) );
+        Module moduleC =
+            new TestLifeCycleStageModule( new DefaultStager<TestAnnotationC>( TestAnnotationC.class ) );
 
         Injector injector = Guice.createInjector( moduleA, moduleB, moduleC );
         MultiLifeCycleObject obj = injector.getInstance( MultiLifeCycleObject.class );
@@ -76,10 +81,10 @@ public class MultiLifeCycleTestCase
     @Test
     public void testStagingOrdering()
     {
-        LifeCycleStageModule<TestAnnotationA> moduleA =
-            new LifeCycleStageModule<TestAnnotationA>( DefaultStager.newStager( TestAnnotationA.class, DefaultStager.Order.FIRST_IN_FIRST_OUT ) );
-        LifeCycleStageModule<TestAnnotationB> moduleB =
-            new LifeCycleStageModule<TestAnnotationB>( DefaultStager.newStager( TestAnnotationB.class, DefaultStager.Order.FIRST_IN_LAST_OUT ) );
+        Module moduleA =
+            new TestLifeCycleStageModule( new DefaultStager<TestAnnotationA>( TestAnnotationA.class, DefaultStager.Order.FIRST_IN_FIRST_OUT ) );
+        Module moduleB =
+            new TestLifeCycleStageModule( new DefaultStager<TestAnnotationB>( TestAnnotationB.class, DefaultStager.Order.FIRST_IN_LAST_OUT ) );
 
         final StringBuilder str = new StringBuilder();
         Module m = new AbstractModule()
@@ -102,4 +107,38 @@ public class MultiLifeCycleTestCase
         injector.getInstance( LifeCycleStageModule.key( TestAnnotationB.class ) ).stage();
         Assert.assertEquals( "2b1b", str.toString() );
     }
+
+    private static class TestLifeCycleModule extends LifeCycleModule
+    {
+
+        private final List<? extends Class<? extends Annotation>> annotations;
+
+        public TestLifeCycleModule( List<? extends Class<? extends Annotation>> annotations )
+        {
+            this.annotations = annotations;
+        }
+
+        @Override
+        protected void configure()
+        {
+            bindLifeCycle( annotations, any() );
+        }
+    }
+
+    private static class TestLifeCycleStageModule extends LifeCycleStageModule
+    {
+
+        private final Stager<?> stager;
+
+        public TestLifeCycleStageModule( Stager<?> stager )
+        {
+            this.stager = stager;
+        }
+
+        @Override
+        protected void configureBindings()
+        {
+            bindStager( stager );
+        }
+    }
 }

Modified: onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/AfterInjectionModule.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/AfterInjectionModule.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/AfterInjectionModule.java (original)
+++ onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/AfterInjectionModule.java Sun Jun 29 05:50:37 2014
@@ -19,18 +19,19 @@ package org.apache.onami.lifecycle.stand
  * under the License.
  */
 
-import com.google.inject.AbstractModule;
 import org.apache.onami.lifecycle.core.LifeCycleModule;
 
 /**
  * Guice module to register methods to be invoked after injection is complete.
  */
 public class AfterInjectionModule
-    extends AbstractModule
+    extends LifeCycleModule
 {
+
     @Override
     protected void configure()
     {
-        binder().install( new LifeCycleModule( AfterInjection.class ) );
+        bindLifeCycle( AfterInjection.class );
     }
+
 }

Modified: onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/DisposeModule.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/DisposeModule.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/DisposeModule.java (original)
+++ onami/trunk/lifecycle/standard/src/main/java/org/apache/onami/lifecycle/standard/DisposeModule.java Sun Jun 29 05:50:37 2014
@@ -19,14 +19,9 @@ package org.apache.onami.lifecycle.stand
  * under the License.
  */
 
-import com.google.inject.AbstractModule;
-import com.google.inject.TypeLiteral;
-import com.google.inject.matcher.Matcher;
+import org.apache.onami.lifecycle.core.DefaultStager;
 import org.apache.onami.lifecycle.core.LifeCycleStageModule;
-
-import java.lang.annotation.Annotation;
-
-import static com.google.inject.matcher.Matchers.any;
+import org.apache.onami.lifecycle.core.Stager;
 
 /**
  * Guice module to register methods to be invoked when {@link org.apache.onami.lifecycle.core.Stager#stage()} is invoked.
@@ -34,145 +29,21 @@ import static com.google.inject.matcher.
  * Module instance have state so it must not be used to construct more than one {@link com.google.inject.Injector}.
  */
 public class DisposeModule
-    extends AbstractModule
+    extends LifeCycleStageModule
 {
-    private final LifeCycleStageModule<?> lifeCycleStageModule;
-
-    private final Disposer disposer;
-
-    public DisposeModule()
-    {
-        disposer = new DefaultDisposer();
-        lifeCycleStageModule = new LifeCycleStageModule<Dispose>( new StagerWrapper<Dispose>( disposer, Dispose.class ) );
-    }
-
-    /**
-     * Creates a new module which register methods annotated with input annotation on methods
-     * in types filtered by the input matcher.
-     *
-     * @param disposeAnnotationType the <i>Dispose</i> annotation to be searched.
-     * @param typeMatcher           the filter for injectee types.
-     */
-    public <A extends Annotation> DisposeModule( Class<A> disposeAnnotationType,
-                                                 Matcher<? super TypeLiteral<?>> typeMatcher )
-    {
-        disposer = new DefaultDisposer();
-        lifeCycleStageModule =
-            LifeCycleStageModule.builder( disposeAnnotationType )
-                .withTypeMatcher( typeMatcher )
-                .withStager( new StagerWrapper<A>( disposer, disposeAnnotationType ) )
-                .build();
-    }
-
-    protected DisposeModule( Builder builder )
-    {
-        disposer = builder.disposer;
-        lifeCycleStageModule = buildModule( builder.disposer, builder.disposeAnnotationType,
-                builder.typeMatcher );
-    }
-
-    // Wildcard capturing method. Bloch, item 28.
-    private static <A extends Annotation> LifeCycleStageModule<A> buildModule( Disposer disposer,
-    	    Class<A> stage, Matcher<? super TypeLiteral<?>> typeMatcher )
-    {
-    	StagerWrapper<A> wrapper = new StagerWrapper<A>( disposer, stage );
-    	return LifeCycleStageModule.builder( stage )
-                .withStager( wrapper )
-                .withTypeMatcher( typeMatcher )
-                .build();
-    }
 
-    public static Builder builder()
-    {
-        return new Builder();
-    }
+    private final Stager<Dispose> stager = new DefaultStager<Dispose>(
+        Dispose.class, DefaultStager.Order.FIRST_IN_LAST_OUT );
 
     @Override
-    protected void configure()
+    protected void configureBindings()
     {
-        bind( Disposer.class ).toInstance( disposer );
-        install( lifeCycleStageModule );
+        bindStager( stager );
     }
 
-    /**
-     * Builder pattern helper.
-     *
-     * @since 0.2.0
-     */
-    public static final class Builder
+    public Stager<Dispose> getStager()
     {
-
-        private Class<? extends Annotation> disposeAnnotationType = Dispose.class;
-
-        private Matcher<? super TypeLiteral<?>> typeMatcher = any();
-
-        private Disposer disposer = new DefaultDisposer();
-
-        /**
-         * Hidden constructor.
-         */
-        Builder()
-        {
-        }
-
-        private static <T> T checkNotNull( T object, String message )
-        {
-            if ( object == null )
-            {
-                throw new IllegalArgumentException( message );
-            }
-            return object;
-        }
-
-        /**
-         * Builds {@link org.apache.onami.lifecycle.standard.DisposeModule} with given settings.
-         *
-         * @return {@link org.apache.onami.lifecycle.standard.DisposeModule} with given settings.
-         * @since 0.2.0
-         */
-        public DisposeModule build()
-        {
-            return new DisposeModule( this );
-        }
-
-        /**
-         * Sets <i>Dispose</i> annotation to be searched.
-         *
-         * @param disposeAnnotationType <i>Dispose</i> annotation to be searched.
-         * @return self
-         * @since 0.2.0
-         */
-        public Builder withDisposeAnnotationType( Class<? extends Annotation> disposeAnnotationType )
-        {
-            this.disposeAnnotationType =
-                checkNotNull( disposeAnnotationType, "Argument 'disposeAnnotationType' must be not null." );
-            return this;
-        }
-
-        /**
-         * Sets the filter for injectee types.
-         *
-         * @param typeMatcher the filter for injectee types.
-         * @return self
-         * @since 0.2.0
-         */
-        public Builder withTypeMatcher( Matcher<? super TypeLiteral<?>> typeMatcher )
-        {
-            this.typeMatcher = checkNotNull( typeMatcher, "Argument 'typeMatcher' must be not null." );
-            return this;
-        }
-
-        /**
-         * Sets the container to register disposable objects.
-         *
-         * @param disposer container to register disposable objects.
-         * @return self
-         * @since 0.2.0
-         */
-        public Builder withDisposer( Disposer disposer )
-        {
-            this.disposer = checkNotNull( disposer, "Argument 'disposer' must be not null." );
-            return this;
-        }
+        return stager;
     }
+
 }

Modified: onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeModuleTestCase.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeModuleTestCase.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeModuleTestCase.java (original)
+++ onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeModuleTestCase.java Sun Jun 29 05:50:37 2014
@@ -22,6 +22,9 @@ package org.apache.onami.lifecycle.stand
 import com.google.inject.AbstractModule;
 import com.google.inject.CreationException;
 import com.google.inject.Provides;
+import org.apache.onami.lifecycle.core.StageHandler;
+import org.apache.onami.lifecycle.core.Stageable;
+import org.apache.onami.lifecycle.core.Stager;
 import org.junit.Test;
 
 import java.util.concurrent.ExecutorService;
@@ -37,10 +40,10 @@ public final class DisposeModuleTestCase
     @Test
     public void disposeUsingModuleOnInjectorFailure()
     {
-        Disposer disposer = new DefaultDisposer();
+        DisposeModule disposeModule = new DisposeModule();
         try
         {
-            createInjector( DisposeModule.builder().withDisposer( disposer ).build(), new AbstractModule()
+            createInjector( disposeModule, new AbstractModule()
             {
 
                 @Override
@@ -60,7 +63,7 @@ public final class DisposeModuleTestCase
         }
         finally
         {
-            disposer.dispose( new DisposeHandler()
+            disposeModule.getStager().stage( new StageHandler()
             {
 
                 public <I> void onSuccess( I injectee )
@@ -81,10 +84,10 @@ public final class DisposeModuleTestCase
     @Test
     public void disposeUsingModuleWithProvidesMethodOnInjectorFailure()
     {
-        Disposer disposer = new DefaultDisposer();
+        DisposeModule disposeModule = new DisposeModule();
         try
         {
-            createInjector( DisposeModule.builder().withDisposer( disposer ).build(), new AbstractModule()
+            createInjector( disposeModule, new AbstractModule()
             {
 
                 @Override
@@ -94,23 +97,23 @@ public final class DisposeModuleTestCase
                 }
 
                 @Provides
-                public ExecutorService provideExecutorService( Disposer disposer )
+                public ExecutorService provideExecutorService( Stager<Dispose> stager )
                 {
                     final ExecutorService executorService = Executors.newCachedThreadPool();
-                    disposer.register( new Disposable()
+                    stager.register( new Stageable()
                     {
 
-                        public void dispose( DisposeHandler disposeHandler )
+                        public void stage( StageHandler stageHandler )
                         {
                             executorService.shutdown();
                             try
                             {
                                 executorService.awaitTermination( 1, TimeUnit.MINUTES );
-                                disposeHandler.onSuccess( executorService );
+                                stageHandler.onSuccess( executorService );
                             }
                             catch ( InterruptedException e )
                             {
-                                disposeHandler.onError( executorService, e );
+                                stageHandler.onError( executorService, e );
                             }
                         }
 
@@ -129,7 +132,7 @@ public final class DisposeModuleTestCase
         }
         finally
         {
-            disposer.dispose( new DisposeHandler()
+            disposeModule.getStager().stage( new StageHandler()
             {
 
                 public <I> void onSuccess( I injectee )

Modified: onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeTestCase.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeTestCase.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeTestCase.java (original)
+++ onami/trunk/lifecycle/standard/src/test/java/org/apache/onami/lifecycle/standard/DisposeTestCase.java Sun Jun 29 05:50:37 2014
@@ -3,6 +3,10 @@ package org.apache.onami.lifecycle.stand
 import com.google.inject.AbstractModule;
 import com.google.inject.ConfigurationException;
 import com.google.inject.Inject;
+import com.google.inject.Key;
+import com.google.inject.TypeLiteral;
+import org.apache.onami.lifecycle.core.StageHandler;
+import org.apache.onami.lifecycle.core.Stager;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -14,13 +18,13 @@ public final class DisposeTestCase
 {
 
     @Inject
-    private Disposer disposer;
+    private Stager<Dispose> stager;
 
     private boolean disposeInvoked = false;
 
-    public void setDisposer( Disposer disposer )
+    public void setStager( Stager<Dispose> stager )
     {
-        this.disposer = disposer;
+        this.stager = stager;
     }
 
     @Dispose
@@ -40,7 +44,7 @@ public final class DisposeTestCase
     @Test
     public void disposeMethodInvoked()
     {
-        disposer.dispose();
+        stager.stage();
         assertTrue( disposeInvoked );
     }
 
@@ -62,7 +66,7 @@ public final class DisposeTestCase
                 bind( ThrowingExceptionDisposeMethod.class ).toInstance( new ThrowingExceptionDisposeMethod() );
             }
 
-        } ).getInstance( Disposer.class ).dispose( new DisposeHandler()
+        } ).getInstance( Key.get( new TypeLiteral<Stager<Dispose>>() {} ) ).stage( new StageHandler()
         {
 
             public <I> void onSuccess( I injectee )

Modified: onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUpModule.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUpModule.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUpModule.java (original)
+++ onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUpModule.java Sun Jun 29 05:50:37 2014
@@ -19,161 +19,23 @@ package org.apache.onami.lifecycle.warmu
  * under the License.
  */
 
-import com.google.inject.AbstractModule;
-import com.google.inject.TypeLiteral;
-import com.google.inject.matcher.Matcher;
-import org.apache.onami.lifecycle.core.LifeCycleStageModule;
-import org.apache.onami.lifecycle.core.StageableTypeMapper;
-
-import java.lang.annotation.Annotation;
 import java.util.concurrent.TimeUnit;
 
-import static com.google.inject.matcher.Matchers.any;
+import org.apache.onami.lifecycle.core.LifeCycleStageModule;
 
 /**
  * The module for preparing for warm ups.
  */
-public class WarmUpModule<A extends Annotation>
-    extends AbstractModule
+public class WarmUpModule
+    extends LifeCycleStageModule
 {
-    private final LifeCycleStageModule<A> lifeCycleStageModule;
 
     private static final long DEFAULT_WAIT_MS = TimeUnit.DAYS.toMillis( Integer.MAX_VALUE );    // essentially forever
 
-    /**
-     * Creates a new module which register methods annotated with input annotation on methods
-     * in types filtered by the input matcher.
-     *
-     * @param stage       the annotation to be searched.
-     */
-    public WarmUpModule( Class<A> stage )
-    {
-        this( stage, any() );
-    }
-
-    /**
-     * Creates a new module which register methods annotated with input annotation on methods
-     * in types filtered by the input matcher.
-     *
-     * @param stage       the annotation to be searched.
-     * @param typeMatcher the filter for injectee types.
-     */
-    public WarmUpModule( Class<A> stage, Matcher<? super TypeLiteral<?>> typeMatcher )
-    {
-        WarmUper<A> stager = new WarmUper<A>( stage, DEFAULT_WAIT_MS );
-        lifeCycleStageModule =
-            LifeCycleStageModule.builder( stage ).withTypeMatcher( typeMatcher ).withStager( stager ).withTypeMapper(
-                stager ).build();
-    }
-
-    /**
-     * Return a new standard warm up module
-     *
-     * @return warm up module
-     */
-    public static WarmUpModule<WarmUp> newWarmUpModule()
-    {
-        return new WarmUpModule<WarmUp>( WarmUp.class );
-    }
-
-    /**
-     * Return a new standard warm up module
-     *
-     * @param typeMatcher     the filter for injectee types.
-     * @return warm up module
-     */
-    public static WarmUpModule<WarmUp> newWarmUpModule( Matcher<? super TypeLiteral<?>> typeMatcher )
-    {
-        return new WarmUpModule<WarmUp>( WarmUp.class, typeMatcher );
-    }
-
-    /**
-     * Allows one to create WarmUpModule with builder pattern.
-     *
-     * @return builder for WarmUpModule.
-     */
-    public static Builder<WarmUp> builder()
-    {
-        WarmUper<WarmUp> stager = new WarmUper<WarmUp>( WarmUp.class, DEFAULT_WAIT_MS );
-        return new Builder<WarmUp>( WarmUp.class, stager ).withTypeMapper( stager );
-    }
-
-    /**
-     * Allows one to create WarmUpModule with builder pattern.
-     *
-     * @param stage       the annotation to be searched.
-     * @return builder for WarmUpModule.
-     */
-    public static <A extends Annotation> Builder<A> builder( Class<A> stage )
-    {
-        WarmUper<A> stager = new WarmUper<A>( stage, DEFAULT_WAIT_MS );
-        return new Builder<A>( stage, stager ).withTypeMapper( stager );
-    }
-
     @Override
-    protected void configure()
-    {
-        install( lifeCycleStageModule );
-    }
-
-    public static class Builder<A extends Annotation>
+    protected void configureBindings()
     {
-        private final WarmUper<A> stager;
-
-        private LifeCycleStageModule.Builder<A> internalBuilder;
-
-        Builder( Class<A> annotationClass, WarmUper<A> stager )
-        {
-            this.stager = stager;
-            internalBuilder = LifeCycleStageModule.builder( annotationClass ).withStager( stager );
-        }
-
-        /**
-         * Builds {@link LifeCycleStageModule} with given settings.
-         *
-         * @return {@link LifeCycleStageModule} with given settings.
-         */
-        public LifeCycleStageModule<A> build()
-        {
-            return internalBuilder.build();
-        }
-
-        /**
-         * Sets the filter for injectee types.
-         *
-         * @param typeMatcher the filter for injectee types.
-         * @return self
-         */
-        public Builder<A> withTypeMatcher( Matcher<? super TypeLiteral<?>> typeMatcher )
-        {
-            internalBuilder.withTypeMatcher( typeMatcher );
-            return this;
-        }
-
-        /**
-         * Sets the container to register mappings from {@link org.apache.onami.lifecycle.core.Stageable}s to the types that created them.
-         *
-         * @param typeMapper container to map {@link org.apache.onami.lifecycle.core.Stageable}s to types
-         * @return self
-         */
-        public Builder<A> withTypeMapper( StageableTypeMapper<A> typeMapper )
-        {
-            internalBuilder.withTypeMapper( typeMapper );
-            return this;
-        }
-
-        /**
-         * When the warm up is staged, it will wait until this maximum time for warm ups to finish.
-         * The default is to wait forever
-         *
-         * @param maxWait max time to wait
-         * @param unit    time unit
-         * @return self
-         */
-        public Builder<A> withMaxWait( long maxWait, TimeUnit unit )
-        {
-            stager.setMaxWait( maxWait, unit );
-            return this;
-        }
+        WarmUper<WarmUp> stager = new WarmUper<WarmUp>( WarmUp.class, DEFAULT_WAIT_MS );
+        bindStager( stager ).mappingWith( stager );
     }
 }

Modified: onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUper.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUper.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUper.java (original)
+++ onami/trunk/lifecycle/warmup/src/main/java/org/apache/onami/lifecycle/warmup/WarmUper.java Sun Jun 29 05:50:37 2014
@@ -42,7 +42,7 @@ import java.util.concurrent.TimeoutExcep
  * <strong>must</strong> use WarmUper.
  */
 public class WarmUper<A extends Annotation>
-    implements Stager<A>, StageableTypeMapper<A>
+    implements Stager<A>, StageableTypeMapper
 {
     private final ConcurrentMap<TypeLiteral<?>, Set<Stageable>> reverseLookup =
         new ConcurrentHashMap<TypeLiteral<?>, Set<Stageable>>();

Modified: onami/trunk/lifecycle/warmup/src/test/java/org/apachi/onami/lifecycle/warmup/TestWarmUpManager.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/warmup/src/test/java/org/apachi/onami/lifecycle/warmup/TestWarmUpManager.java?rev=1606430&r1=1606429&r2=1606430&view=diff
==============================================================================
--- onami/trunk/lifecycle/warmup/src/test/java/org/apachi/onami/lifecycle/warmup/TestWarmUpManager.java (original)
+++ onami/trunk/lifecycle/warmup/src/test/java/org/apachi/onami/lifecycle/warmup/TestWarmUpManager.java Sun Jun 29 05:50:37 2014
@@ -23,7 +23,6 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
@@ -36,6 +35,7 @@ import org.apache.onami.lifecycle.core.S
 import org.apache.onami.lifecycle.core.Stager;
 import org.apache.onami.lifecycle.warmup.WarmUp;
 import org.apache.onami.lifecycle.warmup.WarmUpModule;
+import org.apache.onami.lifecycle.warmup.WarmUper;
 import org.junit.Test;
 
 import com.google.inject.AbstractModule;
@@ -59,7 +59,7 @@ public class TestWarmUpManager
                 bind( WarmUpWithException.class ).asEagerSingleton();
             }
         };
-        Injector injector = Guice.createInjector( WarmUpModule.newWarmUpModule(), module );
+        Injector injector = Guice.createInjector( new WarmUpModule(), module );
 
         final AtomicInteger errorCount = new AtomicInteger( 0 );
         StageHandler stageHandler = new StageHandler()
@@ -89,7 +89,7 @@ public class TestWarmUpManager
                 bind( CountDownLatch.class ).toInstance( new CountDownLatch( 3 ) );
             }
         };
-        Injector injector = Guice.createInjector( WarmUpModule.newWarmUpModule(), module );
+        Injector injector = Guice.createInjector( new WarmUpModule(), module );
         injector.getInstance( Dag1.A.class );
         injector.getInstance( LifeCycleStageModule.key( WarmUp.class ) ).stage();
         Recorder recorder = injector.getInstance( Recorder.class );
@@ -110,7 +110,7 @@ public class TestWarmUpManager
     public void testDag2()
         throws Exception
     {
-        Injector injector = Guice.createInjector( WarmUpModule.newWarmUpModule() );
+        Injector injector = Guice.createInjector( new WarmUpModule() );
         injector.getInstance( Dag2.A1.class );
         injector.getInstance( Dag2.A2.class );
         injector.getInstance( Dag2.A3.class );
@@ -154,7 +154,7 @@ public class TestWarmUpManager
     public void testDag3()
         throws Exception
     {
-        Injector injector = Guice.createInjector( WarmUpModule.newWarmUpModule() );
+        Injector injector = Guice.createInjector( new WarmUpModule() );
         injector.getInstance( Dag3.A.class );
         injector.getInstance( LifeCycleStageModule.key( WarmUp.class ) ).stage();
         Recorder recorder = injector.getInstance( Recorder.class );
@@ -191,7 +191,7 @@ public class TestWarmUpManager
                 bind( RecorderSleepSettings.class ).toInstance( recorderSleepSettings );
             }
         };
-        Injector injector = Guice.createInjector( WarmUpModule.newWarmUpModule(), module );
+        Injector injector = Guice.createInjector( new WarmUpModule(), module );
         injector.getInstance( Dag4.A.class );
         injector.getInstance( LifeCycleStageModule.key( WarmUp.class ) ).stage();
         Recorder recorder = injector.getInstance( Recorder.class );
@@ -211,7 +211,7 @@ public class TestWarmUpManager
     public void testFlat()
         throws Exception
     {
-        Injector injector = Guice.createInjector( WarmUpModule.newWarmUpModule() );
+        Injector injector = Guice.createInjector( new WarmUpModule() );
         Recorder recorder = injector.getInstance( Recorder.class );
         injector.getInstance( Flat.A.class ).recorder = recorder;
         injector.getInstance( Flat.B.class ).recorder = recorder;
@@ -242,8 +242,7 @@ public class TestWarmUpManager
                 bind( CountDownLatch.class ).toInstance( latch );
             }
         };
-        LifeCycleStageModule<WarmUp> warmUpModule = WarmUpModule.builder().withMaxWait( 1, TimeUnit.SECONDS ).build();
-        Injector injector = Guice.createInjector( warmUpModule, module );
+        Injector injector = Guice.createInjector( new TestWarmUpModule(), module );
         injector.getInstance( Dag1.A.class );
         Stager<WarmUp> stager = injector.getInstance( LifeCycleStageModule.key( WarmUp.class ) );
 
@@ -306,4 +305,16 @@ public class TestWarmUpManager
         }
     }
 
+    private static class TestWarmUpModule extends LifeCycleStageModule
+    {
+
+        @Override
+        protected void configureBindings()
+        {
+            WarmUper<WarmUp> stager = new WarmUper<WarmUp>( WarmUp.class, TimeUnit.SECONDS.toMillis( 1 ) );
+            bindStager( stager ).mappingWith( stager );
+        }
+
+    }
+
 }



Mime
View raw message