commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1531850 - in /commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy: BaseProxyHandler.java CglibProxyHandler.java CglibProxySource.java JdkProxyHandler.java
Date Mon, 14 Oct 2013 11:02:52 GMT
Author: markt
Date: Mon Oct 14 11:02:52 2013
New Revision: 1531850

URL: http://svn.apache.org/r1531850
Log:
Refactor to reduce duplication

Modified:
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/BaseProxyHandler.java
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxyHandler.java
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxySource.java
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/JdkProxyHandler.java

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/BaseProxyHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/BaseProxyHandler.java?rev=1531850&r1=1531849&r2=1531850&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/BaseProxyHandler.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/BaseProxyHandler.java
Mon Oct 14 11:02:52 2013
@@ -16,13 +16,19 @@
  */
 package org.apache.commons.pool2.proxy;
 
+import java.lang.reflect.Method;
+
+import org.apache.commons.pool2.UsageTracking;
+
 class BaseProxyHandler<T> {
 
     private T pooledObject;
+    private final UsageTracking<T> usageTracking;
 
 
-    BaseProxyHandler(T pooledObject) {
+    BaseProxyHandler(T pooledObject, UsageTracking<T> usageTracking) {
         this.pooledObject = pooledObject;
+        this.usageTracking = usageTracking;
     }
 
 
@@ -44,4 +50,14 @@ class BaseProxyHandler<T> {
             		"used as it has been returned to the Object Pool.");
         }
     }
+
+
+    Object doInvoke(Method method, Object[] args) throws Throwable {
+        validateProxiedObject();
+        T pooledObject = getPooledObject();
+        if (usageTracking != null) {
+            usageTracking.use(pooledObject);
+        }
+        return method.invoke(pooledObject, args);
+    }
 }

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxyHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxyHandler.java?rev=1531850&r1=1531849&r2=1531850&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxyHandler.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxyHandler.java
Mon Oct 14 11:02:52 2013
@@ -11,22 +11,14 @@ import net.sf.cglib.proxy.MethodProxy;
 public class CglibProxyHandler<T> extends BaseProxyHandler<T>
         implements MethodInterceptor {
 
-    private final UsageTracking<T> usageTracking;
 
     CglibProxyHandler(T pooledObject, UsageTracking<T> usageTracking) {
-        super(pooledObject);
-        this.usageTracking = usageTracking;
+        super(pooledObject, usageTracking);
     }
 
     @Override
     public Object intercept(Object object, Method method, Object[] args,
             MethodProxy methodProxy) throws Throwable {
-        validateProxiedObject();
-        T pooledObject = getPooledObject();
-        if (usageTracking != null) {
-            usageTracking.use(pooledObject);
-        }
-
-        return method.invoke(pooledObject, args);
+        return doInvoke(method, args);
     }
 }

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxySource.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxySource.java?rev=1531850&r1=1531849&r2=1531850&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxySource.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/CglibProxySource.java
Mon Oct 14 11:02:52 2013
@@ -49,9 +49,9 @@ public class CglibProxySource<T> impleme
     @Override
     public T resolveProxy(T proxy) {
         @SuppressWarnings("unchecked")
-        BaseProxyHandler<T> proxyInterceptor =
-                (BaseProxyHandler<T>) ((Factory) proxy).getCallback(0);
-        T pooledObject = proxyInterceptor.disableProxy();
+        CglibProxyHandler<T> cglibProxyHandler =
+                (CglibProxyHandler<T>) ((Factory) proxy).getCallback(0);
+        T pooledObject = cglibProxyHandler.disableProxy();
         return pooledObject;
     }
 }

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/JdkProxyHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/JdkProxyHandler.java?rev=1531850&r1=1531849&r2=1531850&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/JdkProxyHandler.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/proxy/JdkProxyHandler.java
Mon Oct 14 11:02:52 2013
@@ -24,24 +24,15 @@ import org.apache.commons.pool2.UsageTra
 class JdkProxyHandler<T> extends BaseProxyHandler<T>
         implements InvocationHandler {
 
-    private final UsageTracking<T> usageTracking;
-
-
     JdkProxyHandler(T pooledObject, UsageTracking<T> usageTracking) {
-        super(pooledObject);
-        this.usageTracking = usageTracking;
+        super(pooledObject, usageTracking);
     }
 
 
     @Override
     public Object invoke(Object proxy, Method method, Object[] args)
             throws Throwable {
-        validateProxiedObject();
-        T pooledObject = getPooledObject();
-        if (usageTracking != null) {
-            usageTracking.use(pooledObject);
-        }
-        return method.invoke(pooledObject, args);
+        return doInvoke(method, args);
     }
 }
 



Mime
View raw message