當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。