Skip to content

Commit

Permalink
Remove Proxies cache entirely, for now
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Feb 21, 2014
1 parent dfd28b1 commit 906f27f
Showing 1 changed file with 47 additions and 74 deletions.
121 changes: 47 additions & 74 deletions proxy/src/main/java/org/jboss/forge/furnace/proxy/Proxies.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
*/
package org.jboss.forge.furnace.proxy;

import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.jboss.forge.furnace.proxy.javassist.util.proxy.MethodFilter;
import org.jboss.forge.furnace.proxy.javassist.util.proxy.Proxy;
Expand All @@ -22,8 +19,6 @@
*/
public class Proxies
{
private static Map<String, WeakReference<Class<?>>> cache = new ConcurrentHashMap<>();

private static MethodFilter filter = new MethodFilter()
{
@Override
Expand Down Expand Up @@ -53,57 +48,46 @@ public static <T> T enhance(final ClassLoader loader, Object instance, ForgeProx
Object result = null;
Class<?> proxyType = null;

WeakReference<Class<?>> ref = cache.get(type.getName());
if (ref != null)
Class<?>[] hierarchy = null;
Class<?> superclass = null;

hierarchy = ProxyTypeInspector.getCompatibleClassHierarchy(loader, type);
if (hierarchy == null || hierarchy.length == 0)
throw new IllegalArgumentException("Must specify at least one non-final type to enhance for Object: "
+ instance + " of type " + instance.getClass());

Class<?> first = hierarchy[0];
if (!first.isInterface() && !isProxyType(first))
{
proxyType = ref.get();
superclass = Proxies.unwrapProxyTypes(first, loader);
hierarchy = Arrays.shiftLeft(hierarchy, new Class<?>[hierarchy.length - 1]);
}
else if (isProxyType(first))
hierarchy = Arrays.shiftLeft(hierarchy, new Class<?>[hierarchy.length - 1]);

if (proxyType == null)
int index = Arrays.indexOf(hierarchy, ProxyObject.class);
if (index >= 0)
{
Class<?>[] hierarchy = null;
Class<?> superclass = null;

hierarchy = ProxyTypeInspector.getCompatibleClassHierarchy(loader, type);
if (hierarchy == null || hierarchy.length == 0)
throw new IllegalArgumentException("Must specify at least one non-final type to enhance for Object: "
+ instance + " of type " + instance.getClass());
hierarchy = Arrays.removeElementAtIndex(hierarchy, index);
}

Class<?> first = hierarchy[0];
if (!first.isInterface() && !isProxyType(first))
{
superclass = Proxies.unwrapProxyTypes(first, loader);
hierarchy = Arrays.shiftLeft(hierarchy, new Class<?>[hierarchy.length - 1]);
}
else if (isProxyType(first))
hierarchy = Arrays.shiftLeft(hierarchy, new Class<?>[hierarchy.length - 1]);
if (!Proxies.isProxyType(first) && !Arrays.contains(hierarchy, ForgeProxy.class))
hierarchy = Arrays.append(hierarchy, ForgeProxy.class);

int index = Arrays.indexOf(hierarchy, ProxyObject.class);
if (index >= 0)
ProxyFactory f = new ProxyFactory()
{
@Override
protected ClassLoader getClassLoader()
{
hierarchy = Arrays.removeElementAtIndex(hierarchy, index);
return loader;
}
};

if (!Proxies.isProxyType(first) && !Arrays.contains(hierarchy, ForgeProxy.class))
hierarchy = Arrays.append(hierarchy, ForgeProxy.class);

ProxyFactory f = new ProxyFactory()
{
@Override
protected ClassLoader getClassLoader()
{
return loader;
}
};

f.setInterfaces(hierarchy);
f.setSuperclass(superclass);
f.setFilter(filter);
f.setInterfaces(hierarchy);
f.setSuperclass(superclass);
f.setFilter(filter);

proxyType = f.createClass();

cache.put(type.getName(), new WeakReference<Class<?>>(proxyType));
}
proxyType = f.createClass();

try
{
Expand Down Expand Up @@ -141,42 +125,31 @@ public static <T> T enhance(Class<T> type, ForgeProxy handler)
Object result = null;
Class<?> proxyType = null;

WeakReference<Class<?>> ref = cache.get(type.getName());
if (ref != null)
{
proxyType = ref.get();
}
Class<?>[] hierarchy = null;
Class<?> superclass = null;

if (proxyType == null)
if (type.isInterface() && !ForgeProxy.class.isAssignableFrom(type))
hierarchy = new Class<?>[] { type, ForgeProxy.class };
else if (type.isInterface())
hierarchy = new Class<?>[] { type };
else
{
Class<?>[] hierarchy = null;
Class<?> superclass = null;

if (type.isInterface() && !ForgeProxy.class.isAssignableFrom(type))
hierarchy = new Class<?>[] { type, ForgeProxy.class };
else if (type.isInterface())
hierarchy = new Class<?>[] { type };
if (Proxies.isProxyType(type))
superclass = unwrapProxyTypes(type);
else
{
if (Proxies.isProxyType(type))
superclass = unwrapProxyTypes(type);
else
{
superclass = type;
hierarchy = new Class<?>[] { ForgeProxy.class };
}
superclass = type;
hierarchy = new Class<?>[] { ForgeProxy.class };
}
}

ProxyFactory f = new ProxyFactory();

f.setFilter(filter);
f.setInterfaces(hierarchy);
f.setSuperclass(superclass);
ProxyFactory f = new ProxyFactory();

proxyType = f.createClass();
f.setFilter(filter);
f.setInterfaces(hierarchy);
f.setSuperclass(superclass);

cache.put(type.getName(), new WeakReference<Class<?>>(proxyType));
}
proxyType = f.createClass();

try
{
Expand Down

0 comments on commit 906f27f

Please sign in to comment.