[jboss-cvs] JBossAS SVN: r96720 - in projects/kernel/trunk: dependency/src/main/java/org/jboss/dependency/plugins/helpers and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 23 04:16:08 EST 2009


Author: alesj
Date: 2009-11-23 04:16:07 -0500 (Mon, 23 Nov 2009)
New Revision: 96720

Added:
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/tracker/
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/tracker/AbstractContextTracker.java
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextFilter.java
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextTracker.java
Removed:
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/ContextTracker.java
Modified:
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java
   projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/spi/dependency/KernelController.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mock/MockController.java
Log:
Extract tracker.

Modified: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2009-11-23 09:05:03 UTC (rev 96719)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2009-11-23 09:16:07 UTC (rev 96720)
@@ -39,8 +39,10 @@
 
 import org.jboss.dependency.plugins.action.ControllerContextAction;
 import org.jboss.dependency.plugins.action.SimpleControllerContextAction;
+import org.jboss.dependency.plugins.tracker.AbstractContextTracker;
 import org.jboss.dependency.spi.CallbackItem;
-import org.jboss.dependency.spi.ContextTracker;
+import org.jboss.dependency.spi.tracker.ContextTracker;
+import org.jboss.dependency.spi.tracker.ContextFilter;
 import org.jboss.dependency.spi.Controller;
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.ControllerContextActions;
@@ -116,8 +118,8 @@
    /** The install stats */
    private volatile StateStatistics installStats = null;
 
-   /** The contexts by class Map<Class, Set<ControllerContext>> */
-   private Map<Class<?>, ClassContext> contextsByClass = new ConcurrentHashMap<Class<?>, ClassContext>();
+   /** The context tracker */
+   private ContextTracker tracker;
 
    /**
     * Create an abstract controller
@@ -132,6 +134,8 @@
       addState(ControllerState.CREATE, null);
       addState(ControllerState.START, null);
       addState(ControllerState.INSTALLED, null);
+
+      tracker = new AbstractContextTracker(this);
    }
 
    /**
@@ -2533,253 +2537,45 @@
       }
    }
 
-   /**
-    * Get contexts by class.
-    * This method should be taken with read lock.
-    *
-    * @param clazz the class type
-    * @return contexts by class
-    */
-   protected Set<ControllerContext> getContexts(Class<?> clazz)
+   // Context tracker
+
+   public Set<ControllerContext> filter(Iterable<ControllerContext> contexts, ContextFilter filter)
    {
-      ClassContext classContext = contextsByClass.get(clazz);
-      if (classContext != null)
-      {
-         if (log.isTraceEnabled())
-         {
-            log.trace("Marking class " + clazz + " as used.");
-         }
-         classContext.used = true;
-         return classContext.contexts;
-      }
-      return null;
+      return tracker.filter(contexts, filter);
    }
 
-   /**
-    * Get instantiated contexts.
-    *
-    * @param clazz the class to match
-    * @return all instantiated contexts whose target is instance of this class clazz param
-    */
    public Set<ControllerContext> getInstantiatedContexts(Class<?> clazz)
    {
-      lockRead();
-      try
-      {
-         Set<ControllerContext> contexts = getContexts(clazz);
-         return contexts != null && contexts.isEmpty() == false ? Collections.unmodifiableSet(contexts) : null;
-      }
-      finally
-      {
-         unlockRead();
-      }
+      return tracker.getInstantiatedContexts(clazz);
    }
 
    public Set<ControllerContext> getContexts(Class<?> clazz, ControllerState state)
    {
-      lockRead();
-      try
-      {
-         Set<ControllerContext> contexts = getContexts(clazz);
-         if (contexts != null && contexts.isEmpty() == false)
-         {
-            Set<ControllerContext> kccs = new HashSet<ControllerContext>();
-            for(ControllerContext context : contexts)
-            {
-               if (getStates().isBeforeState(context.getState(), state) == false)
-                  kccs.add(context);
-            }
-            return kccs;
-         }
-         else
-            return null;
-      }
-      finally
-      {
-         unlockRead();
-      }
+      return tracker.getContexts(clazz, state);
    }
 
-   public void addInstantiatedContext(ControllerContext context)
+   public ControllerContext getContextByClass(Class<?> clazz)
    {
-      prepareToTraverse(context, true);
+      return tracker.getContextByClass(clazz);
    }
 
-   public void registerInstantiatedContext(ControllerContext context, Class<?>... classes)
+   public void addInstantiatedContext(ControllerContext context)
    {
-      handleInstantiatedContext(context, true, classes);
+      tracker.addInstantiatedContext(context);
    }
 
-   /**
-    * Register / unregister contexts against explicit classes.
-    *
-    * @param context the context
-    * @param addition whether this is an addition
-    * @param classes the exposed classes
-    */
-   protected void handleInstantiatedContext(ControllerContext context, boolean addition, Class<?>... classes)
+   public void registerInstantiatedContext(ControllerContext context, Class<?>... classes)
    {
-      if (classes != null && classes.length > 0)
-      {
-         boolean trace = log.isTraceEnabled();
-
-         lockWrite();
-         try
-         {
-            for (Class<?> clazz : classes)
-               handleContext(context, clazz, addition, trace);
-         }
-         finally
-         {
-            unlockWrite();
-         }
-      }
+      tracker.registerInstantiatedContext(context, classes);
    }
 
    public void unregisterInstantiatedContext(ControllerContext context, Class<?>... classes)
    {
-      handleInstantiatedContext(context, false, classes);
+      tracker.unregisterInstantiatedContext(context, classes);
    }
 
    public void removeInstantiatedContext(ControllerContext context)
    {
-      prepareToTraverse(context, false);
+      tracker.removeInstantiatedContext(context);
    }
-
-   protected void prepareToTraverse(ControllerContext context, boolean addition)
-   {
-      lockWrite();
-      try
-      {
-         Object target = context.getTarget();
-         try
-         {
-            if (target != null)
-            {
-               traverseBean(context, target.getClass(), addition, log.isTraceEnabled());
-            }
-         }
-         finally
-         {
-            context.ungetTarget();
-         }
-      }
-      finally
-      {
-         unlockWrite();
-      }
-   }
-
-   /**
-    * Traverse over target and map it to all its superclasses
-    * and interfaces - using recursion.
-    *
-    * @param context context whose target is instance of clazz
-    * @param clazz current class to map context to
-    * @param addition whether this is an addition
-    * @param trace whether trace is enabled
-    */
-   protected void traverseBean(ControllerContext context, Class<?> clazz, boolean addition, boolean trace)
-   {
-      if (clazz == null || clazz == Object.class)
-      {
-         return;
-      }
-
-      handleContext(context, clazz, addition, trace);
-
-      // traverse superclass
-      traverseBean(context, clazz.getSuperclass(), addition, trace);
-      Class<?>[] interfaces = clazz.getInterfaces();
-      // traverse interfaces
-      for(Class<?> intface : interfaces)
-      {
-         traverseBean(context, intface, addition, trace);
-      }
-   }
-
-   /**
-    * Map or remove context against class.
-    * This method should be used with write lock taken before.
-    *
-    * @param context the context
-    * @param clazz the class
-    * @param addition whether this is an addition
-    * @param trace trace is enabled
-    */
-   protected void handleContext(ControllerContext context, Class<?> clazz, boolean addition, boolean trace)
-   {
-      ClassContext classContext = contextsByClass.get(clazz);
-      if (addition)
-      {
-         if (classContext == null)
-         {
-            classContext = new ClassContext();
-            classContext.contexts = new HashSet<ControllerContext>();
-            contextsByClass.put(clazz, classContext);
-         }
-         else if (classContext.used)
-         {
-            log.debug("Additional matching bean - contextual injection already used for class: " + clazz);
-         }
-         if (trace)
-         {
-            log.trace("Mapping contex " + context + " to class: " + clazz);
-         }
-         classContext.contexts.add(context);
-      }
-      else
-      {
-         if (classContext != null)
-         {
-            if (trace)
-            {
-               log.trace("Removing contex " + context + " to class: " + clazz);
-            }
-            classContext.contexts.remove(context);
-         }
-      }
-   }
-
-   private static class ClassContext
-   {
-      private boolean used;
-      private Set<ControllerContext> contexts;
-   }
-
-   /**
-    * If zero or multiple instances match class clazz
-    * a warning is issued, but no throwable is thrown
-    *
-    * @param clazz the class to match
-    * @return context whose target is instance of this class clazz param or null if zero or multiple such instances
-    */
-   public ControllerContext getContextByClass(Class<?> clazz)
-   {
-      Set<ControllerContext> contexts = getInstantiatedContexts(clazz);
-      int numberOfMatchingBeans = 0;
-      if (contexts != null)
-      {
-         numberOfMatchingBeans = contexts.size();
-      }
-
-      if (log.isTraceEnabled())
-      {
-         log.trace("Checking for contextual injection, current matches: " + numberOfMatchingBeans + " - " + clazz);
-      }
-
-      if (numberOfMatchingBeans != 1)
-      {
-         if (numberOfMatchingBeans > 1)
-         {
-            log.warn("Multiple beans match class type [enable trace log for details]: " + clazz);
-            if (log.isTraceEnabled())
-            {
-               log.trace("Matching contexts: " + contexts);
-            }
-         }
-         return null;
-      }
-      return contexts.iterator().next();
-   }
 }

Modified: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java	2009-11-23 09:05:03 UTC (rev 96719)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java	2009-11-23 09:16:07 UTC (rev 96720)
@@ -25,7 +25,7 @@
 import java.util.Set;
 
 import org.jboss.dependency.plugins.AbstractController;
-import org.jboss.dependency.spi.ContextTracker;
+import org.jboss.dependency.spi.tracker.ContextTracker;
 import org.jboss.dependency.spi.Controller;
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.ControllerState;

Copied: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/tracker/AbstractContextTracker.java (from rev 96686, projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java)
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/tracker/AbstractContextTracker.java	                        (rev 0)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/tracker/AbstractContextTracker.java	2009-11-23 09:16:07 UTC (rev 96720)
@@ -0,0 +1,358 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.dependency.plugins.tracker;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.ControllerStateModel;
+import org.jboss.dependency.spi.tracker.ContextFilter;
+import org.jboss.dependency.spi.tracker.ContextTracker;
+import org.jboss.util.JBossObject;
+
+/**
+ * Abstract context tracker
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractContextTracker extends JBossObject implements ContextTracker
+{
+   /** The lock */
+   private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+   /** The contexts by class Map<Class, Set<ControllerContext>> */
+   private Map<Class<?>, ClassContext> contextsByClass = new ConcurrentHashMap<Class<?>, ClassContext>();
+
+   /** The controller */
+   private Controller controller;
+
+   public AbstractContextTracker(Controller controller)
+   {
+      if (controller == null)
+         throw new IllegalArgumentException("Null controller");
+      this.controller = controller;
+   }
+
+   public Set<ControllerContext> filter(Iterable<ControllerContext> contexts, ContextFilter filter)
+   {
+      if (contexts == null)
+         return null;
+
+      Set<ControllerContext> set = new HashSet<ControllerContext>();
+      for (ControllerContext context : contexts)
+      {
+         if (filter == null || filter.accepts(context))
+            set.add(context);
+      }
+      return set;
+   }
+
+   /**
+    * Get contexts by class.
+    * This method should be taken with read lock.
+    *
+    * @param clazz the class type
+    * @return contexts by class
+    */
+   protected Set<ControllerContext> getContexts(Class<?> clazz)
+   {
+      ClassContext classContext = contextsByClass.get(clazz);
+      if (classContext != null)
+      {
+         if (log.isTraceEnabled())
+         {
+            log.trace("Marking class " + clazz + " as used.");
+         }
+         classContext.used = true;
+         return classContext.contexts;
+      }
+      return null;
+   }
+
+   /**
+    * Get instantiated contexts.
+    *
+    * @param clazz the class to match
+    * @return all instantiated contexts whose target is instance of this class clazz param
+    */
+   public Set<ControllerContext> getInstantiatedContexts(Class<?> clazz)
+   {
+      lockRead();
+      try
+      {
+         Set<ControllerContext> contexts = getContexts(clazz);
+         return contexts != null && contexts.isEmpty() == false ? Collections.unmodifiableSet(contexts) : null;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+
+   public Set<ControllerContext> getContexts(Class<?> clazz, ControllerState state)
+   {
+      lockRead();
+      try
+      {
+         Set<ControllerContext> contexts = getContexts(clazz);
+         if (contexts != null && contexts.isEmpty() == false)
+         {
+            ControllerStateModel model = controller.getStates();
+            Set<ControllerContext> kccs = new HashSet<ControllerContext>();
+            for(ControllerContext context : contexts)
+            {
+               if (model.isBeforeState(context.getState(), state) == false)
+                  kccs.add(context);
+            }
+            return kccs;
+         }
+         else
+            return null;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+
+   public void addInstantiatedContext(ControllerContext context)
+   {
+      prepareToTraverse(context, true);
+   }
+
+   public void registerInstantiatedContext(ControllerContext context, Class<?>... classes)
+   {
+      handleInstantiatedContext(context, true, classes);
+   }
+
+   /**
+    * Register / unregister contexts against explicit classes.
+    *
+    * @param context the context
+    * @param addition whether this is an addition
+    * @param classes the exposed classes
+    */
+   protected void handleInstantiatedContext(ControllerContext context, boolean addition, Class<?>... classes)
+   {
+      if (classes != null && classes.length > 0)
+      {
+         boolean trace = log.isTraceEnabled();
+
+         lockWrite();
+         try
+         {
+            for (Class<?> clazz : classes)
+               handleContext(context, clazz, addition, trace);
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+
+   public void unregisterInstantiatedContext(ControllerContext context, Class<?>... classes)
+   {
+      handleInstantiatedContext(context, false, classes);
+   }
+
+   public void removeInstantiatedContext(ControllerContext context)
+   {
+      prepareToTraverse(context, false);
+   }
+
+   protected void prepareToTraverse(ControllerContext context, boolean addition)
+   {
+      lockWrite();
+      try
+      {
+         Object target = context.getTarget();
+         try
+         {
+            if (target != null)
+            {
+               traverseBean(context, target.getClass(), addition, log.isTraceEnabled());
+            }
+         }
+         finally
+         {
+            context.ungetTarget();
+         }
+      }
+      finally
+      {
+         unlockWrite();
+      }
+   }
+
+   /**
+    * Traverse over target and map it to all its superclasses
+    * and interfaces - using recursion.
+    *
+    * @param context context whose target is instance of clazz
+    * @param clazz current class to map context to
+    * @param addition whether this is an addition
+    * @param trace whether trace is enabled
+    */
+   protected void traverseBean(ControllerContext context, Class<?> clazz, boolean addition, boolean trace)
+   {
+      if (clazz == null || clazz == Object.class)
+      {
+         return;
+      }
+
+      handleContext(context, clazz, addition, trace);
+
+      // traverse superclass
+      traverseBean(context, clazz.getSuperclass(), addition, trace);
+      Class<?>[] interfaces = clazz.getInterfaces();
+      // traverse interfaces
+      for(Class<?> intface : interfaces)
+      {
+         traverseBean(context, intface, addition, trace);
+      }
+   }
+
+   /**
+    * Map or remove context against class.
+    * This method should be used with write lock taken before.
+    *
+    * @param context the context
+    * @param clazz the class
+    * @param addition whether this is an addition
+    * @param trace trace is enabled
+    */
+   protected void handleContext(ControllerContext context, Class<?> clazz, boolean addition, boolean trace)
+   {
+      ClassContext classContext = contextsByClass.get(clazz);
+      if (addition)
+      {
+         if (classContext == null)
+         {
+            classContext = new ClassContext();
+            classContext.contexts = new HashSet<ControllerContext>();
+            contextsByClass.put(clazz, classContext);
+         }
+         else if (classContext.used)
+         {
+            log.debug("Additional matching bean - contextual injection already used for class: " + clazz);
+         }
+         if (trace)
+         {
+            log.trace("Mapping contex " + context + " to class: " + clazz);
+         }
+         classContext.contexts.add(context);
+      }
+      else
+      {
+         if (classContext != null)
+         {
+            if (trace)
+            {
+               log.trace("Removing contex " + context + " to class: " + clazz);
+            }
+            classContext.contexts.remove(context);
+         }
+      }
+   }
+
+   /**
+    * If zero or multiple instances match class clazz
+    * a warning is issued, but no throwable is thrown
+    *
+    * @param clazz the class to match
+    * @return context whose target is instance of this class clazz param or null if zero or multiple such instances
+    */
+   public ControllerContext getContextByClass(Class<?> clazz)
+   {
+      Set<ControllerContext> contexts = getInstantiatedContexts(clazz);
+      int numberOfMatchingBeans = 0;
+      if (contexts != null)
+      {
+         numberOfMatchingBeans = contexts.size();
+      }
+
+      if (log.isTraceEnabled())
+      {
+         log.trace("Checking for contextual injection, current matches: " + numberOfMatchingBeans + " - " + clazz);
+      }
+
+      if (numberOfMatchingBeans != 1)
+      {
+         if (numberOfMatchingBeans > 1)
+         {
+            log.warn("Multiple beans match class type [enable trace log for details]: " + clazz);
+            if (log.isTraceEnabled())
+            {
+               log.trace("Matching contexts: " + contexts);
+            }
+         }
+         return null;
+      }
+      return contexts.iterator().next();
+   }
+
+   /**
+    * Lock for read
+    */
+   protected void lockRead()
+   {
+      lock.readLock().lock();
+   }
+
+   /**
+    * Unlock for read
+    */
+   protected void unlockRead()
+   {
+      lock.readLock().unlock();
+   }
+
+   /**
+    * Lock for write
+    */
+   protected void lockWrite()
+   {
+      lock.writeLock().lock();
+   }
+
+   /**
+    * Unlock for write
+    */
+   protected void unlockWrite()
+   {
+      lock.writeLock().unlock();
+   }
+
+   private static class ClassContext
+   {
+      private boolean used;
+      private Set<ControllerContext> contexts;
+   }
+}
\ No newline at end of file


Property changes on: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/tracker/AbstractContextTracker.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Deleted: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/ContextTracker.java
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/ContextTracker.java	2009-11-23 09:05:03 UTC (rev 96719)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/ContextTracker.java	2009-11-23 09:16:07 UTC (rev 96720)
@@ -1,96 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.dependency.spi;
-
-import java.util.Set;
-
-/**
- * Track contexts.
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-public interface ContextTracker
-{
-   /**
-    * Get all instantiated contexts of a given type
-    *
-    * @param clazz the type
-    * @return the contexts
-    */
-   Set<ControllerContext> getInstantiatedContexts(Class<?> clazz);
-
-   /**
-    * Get all contexts of a type which are in the given state or above
-    *
-    * @param clazz the type
-    * @param state the required state
-    * @return the contexts
-    */
-   Set<ControllerContext> getContexts(Class<?> clazz, ControllerState state);
-
-   /**
-    * Get an instantiated context that is of the type passed in.
-    * If zero or multiple instances match class clazz
-    * a warning is issued, but no throwable is thrown
-    *
-    * @param clazz the type
-    * @return context whose target is instance of this class clazz param or null if zero or multiple such instances
-    */
-   ControllerContext getContextByClass(Class<?> clazz);
-
-   /**
-    * Add instantiated context into the map used by {@link #getContextByClass(Class)}.
-    * Look at all the context's target's superclasses and interfaces.
-    *
-    * @param context the context
-    */
-   void addInstantiatedContext(ControllerContext context);
-
-   /**
-    * Add instantiated context into the map used by {@link #getContextByClass(Class)}.
-    * Only map against explicit classes.
-    *
-    * Note: it is up to the caller to make sure the context's target implements
-    * all of the exposed classes.
-    *
-    * @param context the context
-    * @param classes the classes to expose
-    */
-   void registerInstantiatedContext(ControllerContext context, Class<?>... classes);
-
-   /**
-    * Remove instantiated context from the map used by {@link #getContextByClass(Class)}.
-    * Only remove explicit classes.
-    *
-    * @param context the context
-    * @param classes the classes to expose
-    */
-   void unregisterInstantiatedContext(ControllerContext context, Class<?>... classes);
-
-   /**
-    * Remove instantiated context from the map used by {@link #getContextByClass(Class)}.
-    * Look at all target's superclasses and interfaces.
-    *
-    * @param context the context
-    */
-   void removeInstantiatedContext(ControllerContext context);
-}
\ No newline at end of file

Copied: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextFilter.java (from rev 96682, projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/ContextTracker.java)
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextFilter.java	                        (rev 0)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextFilter.java	2009-11-23 09:16:07 UTC (rev 96720)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.dependency.spi.tracker;
+
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * Context filter.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ContextFilter
+{
+   /**
+    * Do we accept this context.
+    *
+    * @param context the context to check
+    * @return true if context is accepted, false otherwise
+    */
+   boolean accepts(ControllerContext context);
+}
\ No newline at end of file


Property changes on: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextFilter.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextTracker.java (from rev 96682, projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/ContextTracker.java)
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextTracker.java	                        (rev 0)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextTracker.java	2009-11-23 09:16:07 UTC (rev 96720)
@@ -0,0 +1,108 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.dependency.spi.tracker;
+
+import java.util.Set;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Track contexts.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ContextTracker
+{
+   /**
+    * Filter existing contexts.
+    *
+    * @param contexts the contexts
+    * @param filter the filter
+    * @return filtered contexts
+    */
+   Set<ControllerContext> filter(Iterable<ControllerContext> contexts, ContextFilter filter);
+
+   /**
+    * Get all instantiated contexts of a given type
+    *
+    * @param clazz the type
+    * @return the contexts
+    */
+   Set<ControllerContext> getInstantiatedContexts(Class<?> clazz);
+
+   /**
+    * Get all contexts of a type which are in the given state or above
+    *
+    * @param clazz the type
+    * @param state the required state
+    * @return the contexts
+    */
+   Set<ControllerContext> getContexts(Class<?> clazz, ControllerState state);
+
+   /**
+    * Get an instantiated context that is of the type passed in.
+    * If zero or multiple instances match class clazz
+    * a warning is issued, but no throwable is thrown
+    *
+    * @param clazz the type
+    * @return context whose target is instance of this class clazz param or null if zero or multiple such instances
+    */
+   ControllerContext getContextByClass(Class<?> clazz);
+
+   /**
+    * Add instantiated context into the map used by {@link #getContextByClass(Class)}.
+    * Look at all the context's target's superclasses and interfaces.
+    *
+    * @param context the context
+    */
+   void addInstantiatedContext(ControllerContext context);
+
+   /**
+    * Add instantiated context into the map used by {@link #getContextByClass(Class)}.
+    * Only map against explicit classes.
+    *
+    * Note: it is up to the caller to make sure the context's target implements
+    * all of the exposed classes.
+    *
+    * @param context the context
+    * @param classes the classes to expose
+    */
+   void registerInstantiatedContext(ControllerContext context, Class<?>... classes);
+
+   /**
+    * Remove instantiated context from the map used by {@link #getContextByClass(Class)}.
+    * Only remove explicit classes.
+    *
+    * @param context the context
+    * @param classes the classes to expose
+    */
+   void unregisterInstantiatedContext(ControllerContext context, Class<?>... classes);
+
+   /**
+    * Remove instantiated context from the map used by {@link #getContextByClass(Class)}.
+    * Look at all target's superclasses and interfaces.
+    *
+    * @param context the context
+    */
+   void removeInstantiatedContext(ControllerContext context);
+}
\ No newline at end of file


Property changes on: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/spi/tracker/ContextTracker.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/spi/dependency/KernelController.java
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/spi/dependency/KernelController.java	2009-11-23 09:05:03 UTC (rev 96719)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/spi/dependency/KernelController.java	2009-11-23 09:16:07 UTC (rev 96720)
@@ -22,7 +22,7 @@
 package org.jboss.kernel.spi.dependency;
 
 import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.dependency.spi.ContextTracker;
+import org.jboss.dependency.spi.tracker.ContextTracker;
 import org.jboss.dependency.spi.Controller;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.kernel.Kernel;

Modified: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mock/MockController.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mock/MockController.java	2009-11-23 09:05:03 UTC (rev 96719)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mock/MockController.java	2009-11-23 09:16:07 UTC (rev 96720)
@@ -27,6 +27,7 @@
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.dependency.spi.ControllerStateModel;
+import org.jboss.dependency.spi.tracker.ContextFilter;
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
@@ -64,6 +65,11 @@
       return null;
    }
 
+   public Set<ControllerContext> filter(Iterable<ControllerContext> contexts, ContextFilter filter)
+   {
+      return null;
+   }
+
    public Set<ControllerContext> getContextsByState(ControllerState state)
    {
       return null;




More information about the jboss-cvs-commits mailing list