List of usage examples for org.springframework.cglib.proxy Enhancer create
public static Object create(Class type, Callback callback)
From source file:org.reindeer.redis.jedis.JedisFactoryBean.java
@Override public Jedis getObject() throws Exception { if (jedis != null) { return jedis; }/*w w w . j a v a 2s. c o m*/ Enhancer en = new Enhancer(); en.setSuperclass(Jedis.class); en.setCallbackFilter(finalizeFilter); en.setCallbacks(new Callback[] { NoOp.INSTANCE, jedisCallback }); jedis = (Jedis) en.create(new Class[] { String.class }, new Object[] { "JedisProxy" }); return jedis; }
From source file:org.reindeer.redis.shard.ShardedJedisFactoryBean.java
@Override public ShardedJedis getObject() throws Exception { if (jedis != null) { return jedis; }// w w w . jav a 2 s.co m Enhancer en = new Enhancer(); en.setSuperclass(ShardedJedis.class); en.setCallbackFilter(finalizeFilter); en.setCallbacks(new Callback[] { NoOp.INSTANCE, jedisCallback }); jedis = (ShardedJedis) en.create(new Class[] { List.class }, new Object[] { Arrays.asList(new JedisShardInfo("shardedJedisProxy")) }); return jedis; }
From source file:com.mongodb.DBCollectionProxyFactory.java
protected static DBCursor getCursor(final DBCursor from) { Enhancer dbcursorEnhancer = new Enhancer(); dbcursorEnhancer.setSuperclass(com.mongodb.DBCursor.class); MethodInterceptor collectionMi = new MethodInterceptor() { boolean _top_level = true; @Override//from ww w. j a v a2s.c o m public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { if (_top_level) { try { _top_level = false; for (int count = 0;; count++) { //DEBUG //System.out.println("intercepted method: " + method.toString() + ", loop=" + count + "); try { Object o = methodProxy.invokeSuper(object, args); return o; } catch (com.mongodb.MongoException e) { if (count < 60) { continue; } throw e; } } } finally { _top_level = true; } } else { return methodProxy.invokeSuper(object, args); } } }; dbcursorEnhancer.setCallback(collectionMi); return (DBCursor) dbcursorEnhancer.create( new Class[] { DBCollection.class, DBObject.class, DBObject.class, ReadPreference.class }, new Object[] { from.getCollection(), from.getQuery(), from.getKeysWanted(), from.getReadPreference() }); }
From source file:com.mongodb.DBCollectionProxyFactory.java
/** Get the enhanced DB collection from the provided one * @param db db name//from w w w. ja v a2s . c o m * @param name collection name * @return the enhanced collection */ @SuppressWarnings("deprecation") public static DBCollection get(final DB db, final String name, final boolean is_mock) { Enhancer collectionEnhancer = new Enhancer(); collectionEnhancer .setSuperclass(is_mock ? com.mongodb.FongoDBCollection.class : com.mongodb.DBCollectionImpl.class); MethodInterceptor collectionMi = new MethodInterceptor() { boolean _top_level = true; @Override public Object intercept(final Object object, final Method method, final Object[] args, final MethodProxy methodProxy) throws Throwable { if (_top_level) { try { _top_level = false; for (int count = 0;; count++) { //DEBUG //System.out.println("intercepted method: " + method.toString() + ", loop=" + count + "); try { Object o = methodProxy.invokeSuper(object, args); if (o instanceof DBCursor) { o = getCursor((DBCursor) o); } return o; } catch (com.mongodb.MongoException e) { if (count < 60) { continue; } throw e; } } } finally { _top_level = true; } } else { return methodProxy.invokeSuper(object, args); } } }; collectionEnhancer.setCallback(collectionMi); return (DBCollection) collectionEnhancer .create(is_mock ? new Class[] { com.mongodb.FongoDB.class, String.class } : new Class[] { com.mongodb.DBApiLayer.class, String.class }, new Object[] { db, name }); }
From source file:org.springframework.aop.framework.CglibAopProxy.java
protected Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks) { enhancer.setInterceptDuringConstruction(false); enhancer.setCallbacks(callbacks);// w w w.jav a 2s.c o m return (this.constructorArgs != null && this.constructorArgTypes != null ? enhancer.create(this.constructorArgTypes, this.constructorArgs) : enhancer.create()); }