當前位置: 首頁>>代碼示例>>Java>>正文


Java Enhancer.setCallbackFilter方法代碼示例

本文整理匯總了Java中net.sf.cglib.proxy.Enhancer.setCallbackFilter方法的典型用法代碼示例。如果您正苦於以下問題:Java Enhancer.setCallbackFilter方法的具體用法?Java Enhancer.setCallbackFilter怎麽用?Java Enhancer.setCallbackFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.sf.cglib.proxy.Enhancer的用法示例。


在下文中一共展示了Enhancer.setCallbackFilter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
public ConstructionProxy<T> create() throws ErrorsException {
  if (interceptors.isEmpty()) {
    return new DefaultConstructionProxyFactory<T>(injectionPoint).create();
  }

  @SuppressWarnings("unchecked")
  Class<? extends Callback>[] callbackTypes = new Class[callbacks.length];
  for (int i = 0; i < callbacks.length; i++) {
    if (callbacks[i] == net.sf.cglib.proxy.NoOp.INSTANCE) {
      callbackTypes[i] = net.sf.cglib.proxy.NoOp.class;
    } else {
      callbackTypes[i] = net.sf.cglib.proxy.MethodInterceptor.class;
    }
  }

  // Create the proxied class. We're careful to ensure that all enhancer state is not-specific
  // to this injector. Otherwise, the proxies for each injector will waste PermGen memory
  try {
  Enhancer enhancer = BytecodeGen.newEnhancer(declaringClass, visibility);
  enhancer.setCallbackFilter(new IndicesCallbackFilter(methods));
  enhancer.setCallbackTypes(callbackTypes);
  return new ProxyConstructor<T>(enhancer, injectionPoint, callbacks, interceptors);
  } catch (Throwable e) {
    throw new Errors().errorEnhancingClass(declaringClass, e).toException();
  }
}
 
開發者ID:maetrive,項目名稱:businessworks,代碼行數:27,代碼來源:ProxyFactory.java

示例2: postProcessBeforeInstantiation

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
@Override
public Object postProcessBeforeInstantiation(final Class<?> beanClass, final String beanName) throws BeansException {
    if (_interceptors != null && _interceptors.size() > 0) {
        if (ComponentMethodInterceptable.class.isAssignableFrom(beanClass)) {
            final Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(beanClass);
            enhancer.setCallbacks(getCallbacks());
            enhancer.setCallbackFilter(getCallbackFilter());
            enhancer.setNamingPolicy(ComponentNamingPolicy.INSTANCE);

            final Object bean = enhancer.create();
            return bean;
        }
    }
    return null;
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:17,代碼來源:ComponentInstantiationPostProcessor.java

示例3: createDynamicProxy

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
@Override
public <T> T createDynamicProxy(Class<T> type, Supplier<T> targetSupplier, String descriptionPattern, Object... descriptionParams) {
    final String description = String.format(descriptionPattern, descriptionParams);
    final Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(new DelegatingClassLoader(type.getClassLoader(), Enhancer.class.getClassLoader()));
    enhancer.setInterfaces(new Class[]{type});
    enhancer.setSuperclass(Object.class);
    enhancer.setCallbackFilter(FILTER);
    enhancer.setCallbacks(new Callback[]{
            (Dispatcher) targetSupplier::get,
            (MethodInterceptor) (proxy, method, params, methodProxy) -> proxy == params[0],
            (MethodInterceptor) (proxy, method, params, methodProxy) -> System.identityHashCode(proxy),
            (MethodInterceptor) (proxy, method, params, methodProxy) -> description
    });
    return type.cast(enhancer.create());
}
 
開發者ID:Microbule,項目名稱:microbule,代碼行數:17,代碼來源:CglibDynamicProxyStrategy.java

示例4: BasicProxyFactoryImpl

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces) {
	if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
		throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
	}

	Enhancer en = new Enhancer();
	en.setUseCache( false );
	en.setInterceptDuringConstruction( false );
	en.setUseFactory( true );
	en.setCallbackTypes( CALLBACK_TYPES );
	en.setCallbackFilter( FINALIZE_FILTER );
	if ( superClass != null ) {
		en.setSuperclass( superClass );
	}
	if ( interfaces != null && interfaces.length > 0 ) {
		en.setInterfaces( interfaces );
	}
	proxyClass = en.createClass();
	try {
		factory = ( Factory ) proxyClass.newInstance();
	}
	catch ( Throwable t ) {
		throw new HibernateException( "Unable to build CGLIB Factory instance" );
	}
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:26,代碼來源:ProxyFactoryFactoryImpl.java

示例5: getProxy

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
public T getProxy() {
    Class proxyClass = getProxy(delegateClass.getName());
    if (proxyClass == null) {
        Enhancer enhancer = new Enhancer();
        if (delegateClass.isInterface()) { // 判斷是否為接口,優先進行接口代理可以解決service為final
            enhancer.setInterfaces(new Class[] { delegateClass });
        } else {
            enhancer.setSuperclass(delegateClass);
        }
        enhancer.setCallbackTypes(new Class[] { ProxyDirect.class, ProxyInterceptor.class });
        enhancer.setCallbackFilter(new ProxyRoute());
        proxyClass = enhancer.createClass();
        // 注冊proxyClass
        registerProxy(delegateClass.getName(), proxyClass);
    }

    Enhancer.registerCallbacks(proxyClass, new Callback[] { new ProxyDirect(), new ProxyInterceptor() });
    try {
        Object[] _constructorArgs = new Object[0];
        Constructor _constructor = proxyClass.getConstructor(new Class[] {});// 先嘗試默認的空構造函數
        return (T) _constructor.newInstance(_constructorArgs);
    } catch (Throwable e) {
        throw new OptimizerException(e);
    } finally {
        // clear thread callbacks to allow them to be gc'd
        Enhancer.registerStaticCallbacks(proxyClass, null);
    }
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:29,代碼來源:NodeDelegate.java

示例6: postProcessBeforeInstantiation

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
@Override
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
    if (_interceptors != null && _interceptors.size() > 0) {
        if (ComponentMethodInterceptable.class.isAssignableFrom(beanClass)) {
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(beanClass);
            enhancer.setCallbacks(getCallbacks());
            enhancer.setCallbackFilter(getCallbackFilter());
            enhancer.setNamingPolicy(ComponentNamingPolicy.INSTANCE);

            Object bean = enhancer.create();
            return bean;
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:cloudstack,代碼行數:17,代碼來源:ComponentInstantiationPostProcessor.java

示例7: benchmarkCglib

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
/**
 * Performs a benchmark of an interface implementation using cglib.
 *
 * @return The created instance, in order to avoid JIT removal.
 */
@Benchmark
public ExampleInterface benchmarkCglib() {
    Enhancer enhancer = new Enhancer();
    enhancer.setUseCache(false);
    enhancer.setClassLoader(newClassLoader());
    enhancer.setSuperclass(baseClass);
    CallbackHelper callbackHelper = new CallbackHelper(Object.class, new Class[]{baseClass}) {
        @Override
        protected Object getCallback(Method method) {
            if (method.getDeclaringClass() == baseClass) {
                return new FixedValue() {
                    @Override
                    public Object loadObject() throws Exception {
                        return null;
                    }
                };
            } else {
                return NoOp.INSTANCE;
            }
        }
    };
    enhancer.setCallbackFilter(callbackHelper);
    enhancer.setCallbacks(callbackHelper.getCallbacks());
    return (ExampleInterface) enhancer.create();
}
 
開發者ID:raphw,項目名稱:byte-buddy,代碼行數:31,代碼來源:ClassByImplementationBenchmark.java

示例8: createProxy

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
@Override
public Object createProxy(Interceptor interceptor, Class<?>[] types, MethodPointcut methodPointcut) {
    ProxyType proxyType = evalProxyType(types);
    Enhancer eh = new Enhancer();
    DefaultMethodInterceptor dmi = new DefaultMethodInterceptor(interceptor);
    DefaultDispatcher dispatcher = new DefaultDispatcher(interceptor.getTarget());
    Callback[] callbacks = new Callback[] {
        dmi, dispatcher
    };
    eh.setCallbacks(callbacks);
    CallbackFilter cf = new CallbackFilterAdapter(methodPointcut);
    eh.setCallbackFilter(cf);

    switch (proxyType) {
        case CLASS:
            Class<?> clazz = types[0];
            eh.setSuperclass(clazz);
            return eh.create();
        case INTERFACES:
            eh.setInterfaces(types);
            return eh.create();
    }

    throw new UnsupportedOperationException("Unsupported proxy types!");
}
 
開發者ID:avast,項目名稱:syringe,代碼行數:26,代碼來源:CglibProxyFactory.java

示例9: getProxyClass

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
public static Class<?> getProxyClass(Class<?> clazz) {
    Enhancer e = new Enhancer();
    if (clazz.isInterface()) {
     e.setSuperclass(clazz);
    } else {
     e.setSuperclass(clazz);
     e.setInterfaces(clazz.getInterfaces());
    }
    e.setCallbackTypes(new Class[]{
        InvocationHandler.class,
        NoOp.class,
    });
    e.setCallbackFilter(BAD_OBJECT_METHOD_FILTER);
    e.setUseFactory(true);
    e.setNamingPolicy(new LithiumTestProxyNamingPolicy());
    return e.createClass();
}
 
開發者ID:lithiumtech,項目名稱:multiverse-test,代碼行數:18,代碼來源:FunctionalTestClassLoader.java

示例10: newProxyByCglib

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
private static Object newProxyByCglib(Typing typing, Handler handler) {
  Enhancer enhancer = new Enhancer() {
    /** includes all constructors */
    protected void filterConstructors(Class sc, List constructors) {}
  };
  enhancer.setClassLoader(Thread.currentThread().getContextClassLoader());
  enhancer.setUseFactory(true);
  enhancer.setSuperclass(typing.superclass);
  enhancer.setInterfaces(typing.interfaces.toArray(new Class[0]));
  enhancer.setCallbackTypes(new Class[] { MethodInterceptor.class, NoOp.class });
  enhancer.setCallbackFilter(new CallbackFilter() {
    /** ignores bridge methods */
    public int accept(Method method) {
      return method.isBridge() ? 1 : 0;
    }
  });
  Class<?> proxyClass = enhancer.createClass();
  Factory proxy = (Factory) new ObjenesisStd().newInstance(proxyClass);
  proxy.setCallbacks(new Callback[] { asMethodInterceptor(handler), new SerializableNoOp() });
  return proxy;
}
 
開發者ID:maciejmikosik,項目名稱:testory,代碼行數:22,代碼來源:CglibProxer.java

示例11: enhance

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
public T enhance(Class<T> clz) {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(clz);
    enhancer.setCallbacks(new Callback[]{new PropertyInterceptor<>(this, schema), NoOp.INSTANCE});
    enhancer.setCallbackFilter(new SchemaFilter<>(clz));
    return (T) enhancer.create();
}
 
開發者ID:eclecticlogic,項目名稱:eclectic-orc,代碼行數:8,代碼來源:ProxyManager.java

示例12: proxySurround

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
/**
 * 代理某一個對象指定方法,並在這個方法執行前後加入新方法,可指定過濾掉非代理的方法
 * @author nan.li
 * @param t
 * @param before 執行目標方法前要執行的方法
 * @param after  執行目標方法後要執行的方法
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T proxySurround(T t, CustomMethod before, CustomMethod after, CallbackFilter callbackFilter)
{
    MethodInterceptor methodInterceptor = new MethodInterceptor()
    {
        @Override
        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
            throws Throwable
        {
            before.execute(obj, method, args);
            Object result = null;
            try
            {
                result = proxy.invokeSuper(obj, args);
            }
            finally
            {
                after.execute(obj, method, args);
            }
            return result;
        }
    };
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(t.getClass());
    // 回調方法
    //        enhancer.setCallback(methodInterceptor);
    enhancer.setCallbacks(new Callback[] {methodInterceptor, NoOp.INSTANCE});
    //NoOp回調把對方法的調用直接委派到這個方法在父類中的實現。
    //Methods using this Enhancer callback ( NoOp.INSTANCE ) will delegate directly to the default (super) implementation in the base class.
    //setCallbacks中定義了所使用的攔截器,其中NoOp.INSTANCE是CGlib所提供的實際是一個沒有任何操作的攔截器, 他們是有序的。一定要和CallbackFilter裏麵的順序一致。
    enhancer.setCallbackFilter(callbackFilter);
    // 創建代理對象
    return (T)enhancer.create();
}
 
開發者ID:lnwazg,項目名稱:kit,代碼行數:43,代碼來源:CglibProxyUtils.java

示例13: create

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T> T create(Class<T> targetClass) throws InstantiationException, IllegalAccessException {
	Enhancer enhancer = new Enhancer();
	enhancer.setSuperclass(targetClass);
	enhancer.setClassLoader(targetClass.getClassLoader());
	enhancer.setCallbackFilter(new TransactionalCallbackFilter());
	Callback[] callbacks = new Callback[]{new DalTransactionInterceptor(), NoOp.INSTANCE};
	enhancer.setCallbacks(callbacks);
	enhancer.setInterfaces(new Class[]{TransactionalIntercepted.class});
	return (T)enhancer.create();
}
 
開發者ID:ctripcorp,項目名稱:dal,代碼行數:12,代碼來源:DalTransactionManager.java

示例14: createFactory

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
private Factory createFactory(Class<?> classToProxify) throws IllegalAccessException, InstantiationException {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(classToProxify);
    enhancer.setCallbackFilter(new ImmutabilityCallbackFilter(this, classToProxify));
    enhancer.setCallbackTypes(new Class[]{
            EqualsMethodInterceptor.class,
            ExceptionMethodInterceptor.class,
            DelegatingMethodInterceptor.class,
            FreezingMethodInterceptor.class
    });
    Class proxyClass = enhancer.createClass();
    return (Factory) proxyClass.newInstance();
}
 
開發者ID:dtitov,項目名稱:CodeFreeze,代碼行數:14,代碼來源:CGLIBCodeFreeze.java

示例15: getProxyFactory

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
public static Class getProxyFactory(Class persistentClass, Class[] interfaces)
		throws HibernateException {
	Enhancer e = new Enhancer();
	e.setSuperclass( interfaces.length == 1 ? persistentClass : null );
	e.setInterfaces(interfaces);
	e.setCallbackTypes(new Class[]{
		InvocationHandler.class,
		NoOp.class,
  		});
 		e.setCallbackFilter(FINALIZE_FILTER);
 		e.setUseFactory(false);
	e.setInterceptDuringConstruction( false );
	return e.createClass();
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:15,代碼來源:CGLIBLazyInitializer.java


注:本文中的net.sf.cglib.proxy.Enhancer.setCallbackFilter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。