21.5.13

How Spring DM (1.2.1) Create Beans for OSGi Services

AbstractServiceProxyCreator

  • createServiceProxy(ServiceReference)
OsgiServiceProxyFactoryBean
  • createProxy()
Object createProxy() {
if (log.isDebugEnabled())
log.debug("Creating a single service proxy ...");

// first create the TCCL interceptor to register its listener with the
// dynamic interceptor
final ServiceProviderTCCLInterceptor tcclAdvice = new ServiceProviderTCCLInterceptor();
final OsgiServiceLifecycleListener tcclListener = tcclAdvice.new ServiceProviderTCCLListener();

final ServiceDynamicInterceptor lookupAdvice = new ServiceDynamicInterceptor(getBundleContext(),
ClassUtils.getParticularClass(getInterfaces()).getName(), getUnifiedFilter(), getAopClassLoader());

lookupAdvice.setRequiredAtStartup(getCardinality().isMandatory());

OsgiServiceLifecycleListener[] listeners = addListener(getListeners(), tcclListener);

lookupAdvice.setListeners(listeners);
synchronized (monitor) {
lookupAdvice.setRetryTimeout(retryTimeout);
retryTemplate = lookupAdvice.getRetryTemplate();
}
lookupAdvice.setApplicationEventPublisher(applicationEventPublisher);

// add the listeners as a list since it might be updated after the proxy
// has been created
lookupAdvice.setStateListeners(stateListeners);
lookupAdvice.setServiceImporter(this);
lookupAdvice.setServiceImporterName(getBeanName());

// create a proxy creator using the existing context
ServiceProxyCreator creator = new AbstractServiceProxyCreator(getInterfaces(), getAopClassLoader(),
getBeanClassLoader(), getBundleContext(), getContextClassLoader()) {

ServiceInvoker createDispatcherInterceptor(ServiceReference reference) {
return lookupAdvice;
}

Advice createServiceProviderTCCLAdvice(ServiceReference reference) {
return tcclAdvice;
}
};

ProxyPlusCallback proxyPlusCallback = creator.createServiceProxy(lookupAdvice.getServiceReference());

synchronized (monitor) {
proxy = proxyPlusCallback.proxy;
destructionCallback = new DisposableBeanRunnableAdapter(proxyPlusCallback.destructionCallback);
}

lookupAdvice.setProxy(proxy);
// start the lookup only after the proxy has been assembled
lookupAdvice.afterPropertiesSet();

return proxy;
}

No comments: