[jbosscache-commits] JBoss Cache SVN: r7874 - in core/branches/flat/src/main/java/org/horizon: factories and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Sat Mar 7 07:27:53 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-03-07 07:27:52 -0500 (Sat, 07 Mar 2009)
New Revision: 7874

Modified:
   core/branches/flat/src/main/java/org/horizon/config/CustomInterceptorConfig.java
   core/branches/flat/src/main/java/org/horizon/factories/InterceptorChainFactory.java
   core/branches/flat/src/main/java/org/horizon/interceptors/base/CommandInterceptor.java
   core/branches/flat/src/main/java/org/horizon/interceptors/base/JmxStatsCommandInterceptor.java
Log:
Interceptor chain optimisations

Modified: core/branches/flat/src/main/java/org/horizon/config/CustomInterceptorConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/CustomInterceptorConfig.java	2009-03-07 10:52:16 UTC (rev 7873)
+++ core/branches/flat/src/main/java/org/horizon/config/CustomInterceptorConfig.java	2009-03-07 12:27:52 UTC (rev 7874)
@@ -36,30 +36,50 @@
    private boolean isFirst;
    private boolean isLast;
    private int index = -1;
-   private String afterClass;
-   private String beforeClass;
+   private String after;
+   private String before;
 
    /**
-    * Builds a custom interceptor.
+    * Builds a custom interceptor configuration.
     *
     * @param interceptor interceptor instance, already initialized with all attributes specified in the configuration
     * @param first       true if you wan this to be the first interceptor in the chain
     * @param last        true if you wan this to be the last interceptor in the chain
     * @param index       an absolute position within the interceptor chain
-    * @param afterClass  if you want this interceptor immediately after the specified class in the chain
-    * @param beforeClass immediately before the specified class in the chain
+    * @param after       if you want this interceptor immediately after the specified class in the chain
+    * @param before      immediately before the specified class in the chain
     */
    public CustomInterceptorConfig(CommandInterceptor interceptor, boolean first, boolean last, int index,
-                                  String afterClass, String beforeClass) {
+                                  String after, String before) {
       this.interceptor = interceptor;
       isFirst = first;
       isLast = last;
       this.index = index;
-      this.afterClass = afterClass;
-      this.beforeClass = beforeClass;
+      this.after = after;
+      this.before = before;
    }
 
    /**
+    * Builds a custom interceptor configuration.
+    *
+    * @param interceptor interceptor instance, already initialized with all attributes specified in the configuration
+    * @param first       true if you wan this to be the first interceptor in the chain
+    * @param last        true if you wan this to be the last interceptor in the chain
+    * @param index       an absolute position within the interceptor chain
+    * @param after       if you want this interceptor immediately after the specified class in the chain
+    * @param before      immediately before the specified class in the chain
+    */
+   public CustomInterceptorConfig(CommandInterceptor interceptor, boolean first, boolean last, int index,
+                                  Class<? extends CommandInterceptor> after, Class<? extends CommandInterceptor> before) {
+      this.interceptor = interceptor;
+      isFirst = first;
+      isLast = last;
+      this.index = index;
+      this.after = after == null ? null : after.getName();
+      this.before = before == null ? null : before.getName();
+   }
+
+   /**
     * Constructs an interceptor config based on the supplied interceptor instance.
     *
     * @param interceptor
@@ -97,21 +117,37 @@
     * Adds the interceptor immediately after the first occurance of an interceptor having the given class. If the chain
     * does not contain such an interceptor then this interceptor definition is ignored.
     */
-   public void setAfterClass(String afterClass) {
-      testImmutability("afterClass");
-      this.afterClass = afterClass;
+   public void setAfterInterceptor(String afterClass) {
+      testImmutability("after");
+      this.after = afterClass;
    }
 
    /**
+    * Adds the interceptor immediately after the first occurance of an interceptor having the given class. If the chain
+    * does not contain such an interceptor then this interceptor definition is ignored.
+    */
+   public void setAfterInterceptor(Class<? extends CommandInterceptor> interceptorClass) {
+      setAfterInterceptor(interceptorClass.getName());
+   }
+
+   /**
     * Adds the interceptor immediately before the first occurance of an interceptor having the given class. If the chain
     * does not contain such an interceptor then this interceptor definition is ignored.
     */
-   public void setBeforeClass(String beforeClass) {
-      testImmutability("beforeClass");
-      this.beforeClass = beforeClass;
+   public void setBeforeInterceptor(String beforeClass) {
+      testImmutability("before");
+      this.before = beforeClass;
    }
 
    /**
+    * Adds the interceptor immediately before the first occurance of an interceptor having the given class. If the chain
+    * does not contain such an interceptor then this interceptor definition is ignored.
+    */
+   public void setBeforeInterceptor(Class<? extends CommandInterceptor> interceptorClass) {
+      setBeforeInterceptor(interceptorClass.getName());
+   }
+
+   /**
     * Returns a the interceptor that we want to add to the chain.
     */
    public CommandInterceptor getInterceptor() {
@@ -140,17 +176,17 @@
    }
 
    /**
-    * @see #getAfterClass()
+    * @see #getAfter()
     */
-   public String getAfterClass() {
-      return afterClass;
+   public String getAfter() {
+      return after;
    }
 
    /**
-    * @see #getBeforeClass()
+    * @see #getBefore()
     */
-   public String getBeforeClass() {
-      return beforeClass;
+   public String getBefore() {
+      return before;
    }
 
    public String toString() {
@@ -159,8 +195,8 @@
             ", isFirst=" + isFirst +
             ", isLast=" + isLast +
             ", index=" + index +
-            ", afterClass='" + afterClass + '\'' +
-            ", beforeClass='" + beforeClass + '\'' +
+            ", after='" + after + '\'' +
+            ", before='" + before + '\'' +
             '}';
    }
 
@@ -173,8 +209,8 @@
       if (index != that.index) return false;
       if (isFirst != that.isFirst) return false;
       if (isLast != that.isLast) return false;
-      if (afterClass != null ? !afterClass.equals(that.afterClass) : that.afterClass != null) return false;
-      if (beforeClass != null ? !beforeClass.equals(that.beforeClass) : that.beforeClass != null) return false;
+      if (after != null ? !after.equals(that.after) : that.after != null) return false;
+      if (before != null ? !before.equals(that.before) : that.before != null) return false;
       if (interceptor != null ? !interceptor.equals(that.interceptor) : that.interceptor != null)
          return false;
       return true;
@@ -186,8 +222,8 @@
       result = 31 * result + (isFirst ? 1 : 0);
       result = 31 * result + (isLast ? 1 : 0);
       result = 31 * result + index;
-      result = 31 * result + (afterClass != null ? afterClass.hashCode() : 0);
-      result = 31 * result + (beforeClass != null ? beforeClass.hashCode() : 0);
+      result = 31 * result + (after != null ? after.hashCode() : 0);
+      result = 31 * result + (before != null ? before.hashCode() : 0);
       return result;
    }
 
@@ -197,8 +233,8 @@
       dolly.interceptor = interceptor;
       dolly.isFirst = isFirst;
       dolly.isLast = isLast;
-      dolly.afterClass = afterClass;
-      dolly.beforeClass = beforeClass;
+      dolly.after = after;
+      dolly.before = before;
       return dolly;
    }
 }

Modified: core/branches/flat/src/main/java/org/horizon/factories/InterceptorChainFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/InterceptorChainFactory.java	2009-03-07 10:52:16 UTC (rev 7873)
+++ core/branches/flat/src/main/java/org/horizon/factories/InterceptorChainFactory.java	2009-03-07 12:27:52 UTC (rev 7874)
@@ -138,18 +138,18 @@
          }
          if (config.isLast()) interceptorChain.appendIntereceptor(config.getInterceptor());
          if (config.getIndex() >= 0) interceptorChain.addInterceptor(config.getInterceptor(), config.getIndex());
-         if (config.getAfterClass() != null) {
-            List<CommandInterceptor> withClassName = interceptorChain.getInterceptorsWithClassName(config.getAfterClass());
+         if (config.getAfter() != null) {
+            List<CommandInterceptor> withClassName = interceptorChain.getInterceptorsWithClassName(config.getAfter());
             if (withClassName.isEmpty()) {
-               throw new ConfigurationException("Cannot add after class: " + config.getAfterClass()
+               throw new ConfigurationException("Cannot add after class: " + config.getAfter()
                      + " as no such iterceptor exists in the default chain");
             }
             interceptorChain.addInterceptorAfter(config.getInterceptor(), withClassName.get(0).getClass());
          }
-         if (config.getBeforeClass() != null) {
-            List<CommandInterceptor> withClassName = interceptorChain.getInterceptorsWithClassName(config.getBeforeClass());
+         if (config.getBefore() != null) {
+            List<CommandInterceptor> withClassName = interceptorChain.getInterceptorsWithClassName(config.getBefore());
             if (withClassName.isEmpty()) {
-               throw new ConfigurationException("Cannot add before class: " + config.getAfterClass()
+               throw new ConfigurationException("Cannot add before class: " + config.getAfter()
                      + " as no such iterceptor exists in the default chain");
             }
             interceptorChain.addInterceptorBefore(config.getInterceptor(), withClassName.get(0).getClass());

Modified: core/branches/flat/src/main/java/org/horizon/interceptors/base/CommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/base/CommandInterceptor.java	2009-03-07 10:52:16 UTC (rev 7873)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/base/CommandInterceptor.java	2009-03-07 12:27:52 UTC (rev 7874)
@@ -58,7 +58,7 @@
  * @since 1.0
  */
 @Scope(Scopes.NAMED_CACHE)
-public class CommandInterceptor extends AbstractVisitor {
+public abstract class CommandInterceptor extends AbstractVisitor {
    private CommandInterceptor next;
 
    protected Log log;
@@ -81,14 +81,14 @@
     *
     * @return the next interceptor in the chain.
     */
-   public CommandInterceptor getNext() {
+   public final CommandInterceptor getNext() {
       return next;
    }
 
    /**
     * @return true if there is another interceptor in the chain after this; false otherwise.
     */
-   public boolean hasNext() {
+   public final boolean hasNext() {
       return getNext() != null;
    }
 
@@ -97,7 +97,7 @@
     *
     * @param next next interceptor in the chain.
     */
-   public void setNext(CommandInterceptor next) {
+   public final void setNext(CommandInterceptor next) {
       this.next = next;
    }
 
@@ -110,7 +110,7 @@
     * @return return value of the invocation
     * @throws Throwable in the event of problems
     */
-   public Object invokeNextInterceptor(InvocationContext ctx, VisitableCommand command) throws Throwable {
+   public final Object invokeNextInterceptor(InvocationContext ctx, VisitableCommand command) throws Throwable {
       return command.acceptVisitor(ctx, next);
    }
 

Modified: core/branches/flat/src/main/java/org/horizon/interceptors/base/JmxStatsCommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/base/JmxStatsCommandInterceptor.java	2009-03-07 10:52:16 UTC (rev 7873)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/base/JmxStatsCommandInterceptor.java	2009-03-07 12:27:52 UTC (rev 7874)
@@ -32,7 +32,7 @@
  * @author Mircea.Markus at jboss.com
  * @since 1.0
  */
-public class JmxStatsCommandInterceptor extends CommandInterceptor implements JmxStatisticsExposer {
+public abstract class JmxStatsCommandInterceptor extends CommandInterceptor implements JmxStatisticsExposer {
    private boolean statsEnabled = false;
 
    @Start




More information about the jbosscache-commits mailing list