本文整理汇总了Java中net.sf.cglib.proxy.Dispatcher类的典型用法代码示例。如果您正苦于以下问题:Java Dispatcher类的具体用法?Java Dispatcher怎么用?Java Dispatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Dispatcher类属于net.sf.cglib.proxy包,在下文中一共展示了Dispatcher类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createDynamicProxy
import net.sf.cglib.proxy.Dispatcher; //导入依赖的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
示例2: scope
import net.sf.cglib.proxy.Dispatcher; //导入依赖的package包/类
@Override
public Supplier<Object> scope(Supplier<Object> supplier, Binding binding, CoreDependencyKey<?> requestedKey) {
// create the proxy right away, such that it can be reused
// afterwards
Object proxy = Enhancer.create(requestedKey.getRawType(), new Dispatcher() {
@Override
public Object loadObject() throws Exception {
Map<Binding, Object> scopedObjects = tryGetValueMap().orElseThrow(
() -> new RuntimeException("Cannot access " + requestedKey + " outside of scope " + scopeName));
return scopedObjects.computeIfAbsent(binding, b -> supplier.get());
}
});
return () -> proxy;
}
开发者ID:ruediste,项目名称:salta,代码行数:18,代码来源:SimpleProxyScopeManager.java
示例3: createProxy
import net.sf.cglib.proxy.Dispatcher; //导入依赖的package包/类
private <T> T createProxy(final Class<T> clazz) {
if (invocationsMap == null) {
invocationsMap = new HashMap<>();
}
try {
final FeatureResolver resolver = FeatureResolver.newFeatureResolver(clazz).build();
final TestInvocation invocation = new TestInvocationImpl(clazz, resolver);
invocationsMap.put(clazz, invocation);
executor.processBeforeAll(invocation);
} catch (final Exception e) {
throw new JpaUnitException("Could not execute beforeAll hook", e);
}
final T bean = createBean(clazz);
final CallbackHelper helper = new CallbackHelper(clazz, new Class[0]) {
@Override
protected Object getCallback(final Method method) {
if (hasCucumberAnnotations(method)) {
return new CucumberInterceptor(executor, bean);
} else if (method.getName().equals("equals")) {
return new EqualsInterceptor(bean);
} else {
return (Dispatcher) () -> bean;
}
}
};
return clazz.cast(Enhancer.create(clazz, new Class[0], helper, helper.getCallbacks()));
}
开发者ID:dadrus,项目名称:jpa-unit,代码行数:33,代码来源:JpaUnitObjectFactory.java
示例4: scope
import net.sf.cglib.proxy.Dispatcher; //导入依赖的package包/类
@Override
public Supplier<Object> scope(Supplier<Object> supplier, Binding binding, CoreDependencyKey<?> requestedKey) {
// create the proxy right away, such that it can be reused
// afterwards
Object proxy = Enhancer.create(requestedKey.getRawType(), new Dispatcher() {
@Override
public Object loadObject() throws Exception {
State state = currentState.get();
Preconditions.checkState(state != null,
"Access to session scoped proxy without active session scope");
Map<Binding, Object> sessionDataMap = state.getSessionData().sessionDataMap;
synchronized (sessionDataMap) {
return sessionDataMap.computeIfAbsent(binding, b -> supplier.get());
}
}
});
return new Supplier<Object>() {
@Override
public Object get() {
return proxy;
}
@Override
public String toString() {
return "SessionScopeProxy[" + requestedKey + "]";
}
};
}
开发者ID:ruediste,项目名称:rise,代码行数:32,代码来源:HttpScopeManager.java
示例5: configure
import net.sf.cglib.proxy.Dispatcher; //导入依赖的package包/类
@Override
protected void configure() throws Exception {
// register DBLinks
DataBaseLinkRegistry registry = permanentInjector.getInstance(DataBaseLinkRegistry.class);
for (DataBaseLink link : registry.getLinks()) {
Class<? extends Annotation> requiredQualifier = link.getQualifier();
// bind data source
bind(DataSource.class).annotatedWith(requiredQualifier)
.toProvider(() -> link.getDataSourceManager().getDataSource()).in(Singleton.class);
// bind EMF to registry
{
bind(EntityManagerFactory.class).annotatedWith(link.getQualifier())
.toProvider(new Provider<EntityManagerFactory>() {
@Inject
PersisteUnitRegistry registry;
@Override
public EntityManagerFactory get() {
return registry.getUnit(requiredQualifier).orElseThrow(() -> new RuntimeException(
"no persistence unit registered for " + requiredQualifier));
}
});
}
// bind EM to proxy
bind(EntityManager.class).annotatedWith(requiredQualifier).toProvider(new Provider<EntityManager>() {
@Inject
EntityManagerHolder holder;
@Override
public EntityManager get() {
return (EntityManager) Enhancer.create(EntityManager.class, new Dispatcher() {
@Override
public Object loadObject() throws Exception {
return holder.getEntityManager(requiredQualifier);
}
});
}
}).in(Singleton.class);
}
registerOwnEntityManagersAdvice();
registerTransactionalAdvice();
}
开发者ID:ruediste,项目名称:rise,代码行数:50,代码来源:PersistenceRestartableModule.java
注:本文中的net.sf.cglib.proxy.Dispatcher类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论