当前位置: 首页>>代码示例>>Java>>正文


Java Enhancer.setCallback方法代码示例

本文整理汇总了Java中net.sf.cglib.proxy.Enhancer.setCallback方法的典型用法代码示例。如果您正苦于以下问题:Java Enhancer.setCallback方法的具体用法?Java Enhancer.setCallback怎么用?Java Enhancer.setCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.cglib.proxy.Enhancer的用法示例。


在下文中一共展示了Enhancer.setCallback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static void main(String[] args) {
	while(true) {
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(ClassPermGenOOM.class);
		enhancer.setUseCache(Boolean.FALSE);
		
		enhancer.setCallback(new MethodInterceptor() {
			
			@Override
			public Object intercept(Object arg0, Method arg1, Object[] arg2,
					MethodProxy arg3) throws Throwable {
				return arg3.invokeSuper(arg0, arg2);
			}
		});
		enhancer.create();
	}
}
 
开发者ID:hdcuican,项目名称:java_learn,代码行数:18,代码来源:ClassPermGenOOM.java

示例2: getJedisProxy

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
 * 使用 cglib 库创建 JedisProxy 的代理对象
 *
 * @return JedisProxy 代理
 */
public JedisProxy getJedisProxy() {
    if (jedisProxy != null) {
        return jedisProxy;
    }
    synchronized (JedisMethodInterceptor.class) {
        if (jedisProxy != null) {
            return jedisProxy;
        }
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(JedisProxy.class);
        enhancer.setCallback(this);
        jedisProxy = (JedisProxy) enhancer.create();
    }
    return jedisProxy;
}
 
开发者ID:ganpengyu,项目名称:gedis,代码行数:21,代码来源:JedisMethodInterceptor.java

示例3: cglibcreate

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static <T> T cglibcreate(T o, OrientElement oe, Transaction transaction ) {
    // this is the main cglib api entry-point
    // this object will 'enhance' (in terms of CGLIB) with new capabilities
    // one can treat this class as a 'Builder' for the dynamic proxy
    Enhancer e = new Enhancer();

    // the class will extend from the real class
    e.setSuperclass(o.getClass());
    // we have to declare the interceptor  - the class whose 'intercept'
    // will be called when any method of the proxified object is called.
    ObjectProxy po = new ObjectProxy(o.getClass(),oe, transaction);
    e.setCallback(po);
    e.setInterfaces(new Class[]{IObjectProxy.class});

    // now the enhancer is configured and we'll create the proxified object
    T proxifiedObj = (T) e.create();
    
    po.___setProxyObject(proxifiedObj);
    
    // the object is ready to be used - return it
    return proxifiedObj;
}
 
开发者ID:mdre,项目名称:odbogm,代码行数:23,代码来源:ObjectProxyFactory.java

示例4: main

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static void main(String[] args) {
    Tmp tmp = new Tmp();
    while (!Thread.interrupted()) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(Tmp.class);
        enhancer.setUseCache(false);
        enhancer.setCallback(new MethodInterceptor() {
            @Override
            public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
                return arg3.invokeSuper(arg0, arg2);
            }
        });
        enhancer.create();
    }
    System.out.println(tmp.hashCode());
}
 
开发者ID:zjulzq,项目名称:hotspot-gc-scenarios,代码行数:17,代码来源:Scenario4.java

示例5: decode

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public T decode(final BitBuffer buffer, final Resolver resolver,
                final Builder builder) throws DecodingException {
    final int size = wrapped.getSize().eval(resolver);
    final long pos = buffer.getBitPos();
    ClassLoader loader = this.getClass().getClassLoader();
    Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(loader);
    enhancer.setSuperclass(type);
    enhancer.setCallback(new MethodInterceptor() {

        private Object actual;

        public Object intercept(Object target, Method method,
                                Object[] args, MethodProxy proxy) throws Throwable {
            if (actual == null) {
                buffer.setBitPos(pos);
                actual = wrapped.decode(buffer, resolver, builder);
            }
            return proxy.invoke(actual, args);
        }
    });
    buffer.setBitPos(pos + size);
    return (T) enhancer.create();
}
 
开发者ID:skaterkamp,项目名称:md380codeplug-tool,代码行数:26,代码来源:LazyLoadingCodecDecorator.java

示例6: NaviDataServiceProxy

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public NaviDataServiceProxy(IBaseDataService realService, Class<?> inter) {
    this.realService = realService;
    Class<?>[] inters = realService.getClass().getInterfaces();
    //直接实现目标的接口的情况下使用java原生动态代理,否则使用cglib
    if (find(inters, inter)) {
        this.proxyService = Proxy.newProxyInstance(
            realService.getClass().getClassLoader(), realService.getClass().getInterfaces(), this
        );
    } else {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(this.realService.getClass());
        // 回调方法
        enhancer.setCallback(this);
        // 创建代理对象
        this.proxyService = enhancer.create();
    }
}
 
开发者ID:sunguangran,项目名称:navi,代码行数:18,代码来源:NaviDataServiceProxy.java

示例7: wrapIfDirty

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
 * @return A proxy object whose getters will return null for unchanged entity's properties
 * (and new values for changed properties), or the entity itself if the entity was not
 * enhanced for dirty checking.
 * @throws com.currencycloud.client.CurrencyCloudClient.NoChangeException if the entity was dirty-checked
 * but there were no changes.
 */
static <E extends Entity> E wrapIfDirty(E entity, Class<E> entityClass) throws NoChangeException {
    if (entity != null) {
        Map<String, Object> values = getDirtyProperties(entity);
        if (values != null) {
            if (values.isEmpty()) {
                throw new NoChangeException();
            }
            values = new HashMap<>(values);
            values.put("id", entity.getId());
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(entityClass);
            enhancer.setCallback(new ModifiedValueProvider(values));
            return (E) enhancer.create();
        }
    }
    return entity;
}
 
开发者ID:CurrencyCloud,项目名称:currencycloud-java,代码行数:25,代码来源:CurrencyCloudClient.java

示例8: create

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T create(final Class<T> clazz) {
    checkNotNull(clazz, "clazz cannot be null");

    if (!isAbstract(clazz)) {
        return null;
    }

    checkIfSupported(clazz);

    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(clazz);
    enhancer.setCallback(handler);

    return (T) enhancer.create();
}
 
开发者ID:leakingtapan,项目名称:rof,代码行数:18,代码来源:AbstractClassProxyFactory.java

示例9: testSupportForClassBasedProxyWithAdditionalInterface

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportForClassBasedProxyWithAdditionalInterface()
    throws NullPointerException {
    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(HashMap.class);
    enhancer.setCallback(NoOp.INSTANCE);
    enhancer.setInterfaces(new Class[]{Runnable.class});
    final Map orig = (Map)enhancer.create();
    final String xml = ""
        + "<CGLIB-enhanced-proxy>\n"
        + "  <type>java.util.HashMap</type>\n"
        + "  <interfaces>\n"
        + "    <java-class>java.lang.Runnable</java-class>\n"
        + "  </interfaces>\n"
        + "  <hasFactory>true</hasFactory>\n"
        + "  <net.sf.cglib.proxy.NoOp_-1/>\n"
        + "</CGLIB-enhanced-proxy>";

    final Object serialized = assertBothWays(orig, xml);
    assertTrue(serialized instanceof HashMap);
    assertTrue(serialized instanceof Map);
    assertTrue(serialized instanceof Runnable);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:23,代码来源:CglibCompatibilityTest.java

示例10: testSupportsProxiesWithMultipleInterfaces

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportsProxiesWithMultipleInterfaces() throws NullPointerException {
    final Enhancer enhancer = new Enhancer();
    enhancer.setCallback(NoOp.INSTANCE);
    enhancer.setInterfaces(new Class[]{Map.class, Runnable.class});
    final Map orig = (Map)enhancer.create();
    final String xml = ""
        + "<CGLIB-enhanced-proxy>\n"
        + "  <type>java.lang.Object</type>\n"
        + "  <interfaces>\n"
        + "    <java-class>java.util.Map</java-class>\n"
        + "    <java-class>java.lang.Runnable</java-class>\n"
        + "  </interfaces>\n"
        + "  <hasFactory>true</hasFactory>\n"
        + "  <net.sf.cglib.proxy.NoOp_-1/>\n"
        + "</CGLIB-enhanced-proxy>";

    final Object serialized = assertBothWays(orig, xml);
    assertTrue(serialized instanceof Map);
    assertTrue(serialized instanceof Runnable);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:21,代码来源:CglibCompatibilityTest.java

示例11: testSupportProxiesWithMultipleCallbackSetToNull

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportProxiesWithMultipleCallbackSetToNull() throws NullPointerException {
    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(HashMap.class);
    enhancer.setCallback(NoOp.INSTANCE);
    final HashMap orig = (HashMap)enhancer.create();
    ((Factory)orig).setCallback(0, null);
    final String xml = ""
        + "<CGLIB-enhanced-proxy>\n"
        + "  <type>java.util.HashMap</type>\n"
        + "  <interfaces/>\n"
        + "  <hasFactory>true</hasFactory>\n"
        + "  <null/>\n"
        + "</CGLIB-enhanced-proxy>";

    assertBothWays(orig, xml);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:17,代码来源:CglibCompatibilityTest.java

示例12: testSupportsSerialVersionUID

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportsSerialVersionUID()
    throws NullPointerException, NoSuchFieldException, IllegalAccessException {
    final Enhancer enhancer = new Enhancer();
    enhancer.setCallback(NoOp.INSTANCE);
    enhancer.setInterfaces(new Class[]{Runnable.class});
    enhancer.setSerialVersionUID(new Long(20060804L));
    final Runnable orig = (Runnable)enhancer.create();
    final String xml = ""
        + "<CGLIB-enhanced-proxy>\n"
        + "  <type>java.lang.Object</type>\n"
        + "  <interfaces>\n"
        + "    <java-class>java.lang.Runnable</java-class>\n"
        + "  </interfaces>\n"
        + "  <hasFactory>true</hasFactory>\n"
        + "  <net.sf.cglib.proxy.NoOp_-1/>\n"
        + "  <serialVersionUID>20060804</serialVersionUID>\n"
        + "</CGLIB-enhanced-proxy>";

    final Object serialized = assertBothWays(orig, xml);
    final Field field = serialized.getClass().getDeclaredField("serialVersionUID");
    field.setAccessible(true);
    assertEquals(20060804L, field.getLong(null));
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:24,代码来源:CglibCompatibilityTest.java

示例13: testProxyTypeCanBeAliased

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testProxyTypeCanBeAliased() throws MalformedURLException {
    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(HashMap.class);
    enhancer.setCallback(new DelegatingHandler(new HashMap()));
    final Map orig = (Map)enhancer.create();
    orig.put("URL", new URL("http://xstream.codehaus.org"));
    xstream.aliasType("cglib", Map.class);
    final String expected = ""
        + "<cglib>\n"
        + "  <type>java.util.HashMap</type>\n"
        + "  <interfaces/>\n"
        + "  <hasFactory>true</hasFactory>\n"
        + "  <com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
        + "    <delegate class=\"map\">\n"
        + "      <entry>\n"
        + "        <string>URL</string>\n"
        + "        <url>http://xstream.codehaus.org</url>\n"
        + "      </entry>\n"
        + "    </delegate>\n"
        + "  </com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
        + "</cglib>";
    assertEquals(expected, xstream.toXML(orig));
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:24,代码来源:CglibCompatibilityTest.java

示例14: createAdapter

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
   * Create an adapter for the given {@code object} in a specific {@code type}.
   *
   * @param adaptableObject the object to adapt
   * @param adapterType     the class in which the object must be adapted
   *
   * @return an adapted object in the given {@code type}
   */
  private static Object createAdapter(Object adaptableObject, Class<?> adapterType) {
      /*
       * Compute the interfaces that the proxy has to implement
 * These are the current interfaces + PersistentEObject
 */
      List<Class<?>> interfaces = ClassUtils.getAllInterfaces(adaptableObject.getClass());
      interfaces.add(PersistentEObject.class);

      // Create the proxy
      Enhancer proxy = new Enhancer();

/*
       * Use the ClassLoader of the type, otherwise it will cause OSGi troubles (like project trying to
 * create an PersistentEObject while it does not have a dependency to NeoEMF core)
 */
      proxy.setClassLoader(adapterType.getClassLoader());
      proxy.setSuperclass(adaptableObject.getClass());
      proxy.setInterfaces(interfaces.toArray(new Class[interfaces.size()]));
      proxy.setCallback(new PersistentEObjectProxyHandler());

      return proxy.create();
  }
 
开发者ID:atlanmod,项目名称:NeoEMF,代码行数:31,代码来源:PersistentEObjectAdapter.java

示例15: createProxy

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
 * Creates a proxy object that will write-replace with a wrapper around the {@link EntityManager}.
 * @param factory a factory to generate EntityManagers.
 * @return the proxied instance.
 */
static EntityManager createProxy(final HibernateEntityManagerFactory factory) {
    final EntityManagerInterceptor handler = new EntityManagerInterceptor(factory);

    final Enhancer e = new Enhancer();

    // make sure we're Serializable and have a write replace method
    e.setInterfaces(new Class[] { EntityManager.class, Serializable.class, IWriteReplace.class });
    e.setSuperclass(Object.class);
    e.setCallback(handler);
    e.setNamingPolicy(new DefaultNamingPolicy() {
        @Override
        public String getClassName(final String prefix,
                                   final String source,
                                   final Object key,
                                   final Predicate names) {
            return super.getClassName("CROQUET_ENTITY_MANAGER_PROXY_" + prefix, source, key, names);
        }
    });

    LOG.trace("Created proxy for an EntityManager");

    return (EntityManager)e.create();
}
 
开发者ID:Metrink,项目名称:croquet,代码行数:29,代码来源:EntityManagerProxyFactory.java


注:本文中的net.sf.cglib.proxy.Enhancer.setCallback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。