Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » ClassCastException when using reference-list ServiceReference(ClassCastException when accessing reference-list ServiceReference)
ClassCastException when using reference-list ServiceReference [message #1029410] Fri, 29 March 2013 12:48
Kristian Marinkovic is currently offline Kristian Marinkovic
Messages: 2
Registered: February 2013
Junior Member
Hi all,

i'm getting a ClassCastException when using the ServiceReference to obtain the actual service. This happens if i declare a ServiceReference in the signature of the bind-method. Everything works fine when using the service type in the method signature. I even tried to set the member-type attribute of the reference-list to "service-reference" with no sucess.

is this a bug or am i missing something?

I need the ServiceReference because i want to update the service properties by re-registering the service. Maybe there is another way to achieve this using bluprint.

	<reference-list id="barrierAdapterList" interface="com.capricube.tmcs.device.api.adapters.BarrierAdapter" availability="optional" member-type="service-reference">
		<reference-listener bind-method="registerBarrierAdapter" unbind-method="unregisterBarrierAdapter" ref="barrierFacade" />
	</reference-list>	


    public void registerBarrierAdapter(ServiceReference barrierAdapterReference) {
        final Object idProperty = barrierAdapterReference.getProperty(DeviceMappingConstants.DEVICE_ID);

        final UUID id = UUID.fromString((String) idProperty);

        final BundleContext context = barrierAdapterReference.getBundle().getBundleContext();

        // throws exception
        final BarrierAdapter barrierFacadeService = (BarrierAdapter) context.getService(barrierAdapterReference);

        barrierAdapterMap.putIfAbsent(id, barrierFacadeService);
    }


Quote:

-03-29 17:11:34.805] WARN region-dm-9 o.e.g.b.c.internal.adapter.OsgiServiceLifecycleListenerAdapter custom method [public void com.capricube.tmcs.device.internal.barrier.BarrierFacade.registerBarrierAdapter(org.osgi.framework.ServiceReference)] threw exception when passing service [$Proxy156@65a04633] java.lang.ClassCastException: org.eclipse.gemini.blueprint.service.importer.support.internal.aop.StaticServiceReferenceProxy cannot be cast to org.eclipse.osgi.internal.serviceregistry.ServiceReferenceImpl
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.getService(BundleContextImpl.java:594)
at com.capricube.tmcs.device.internal.barrier.BarrierFacade.registerBarrierAdapter(BarrierFacade.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.gemini.blueprint.util.internal.ReflectionUtils.invokeMethod(ReflectionUtils.java:106)
at org.eclipse.gemini.blueprint.config.internal.adapter.OsgiServiceLifecycleListenerAdapter.invokeCustomServiceReferenceMethod(OsgiServiceLifecycleListenerAdapter.java:209)
at org.eclipse.gemini.blueprint.config.internal.adapter.OsgiServiceLifecycleListenerAdapter.bind(OsgiServiceLifecycleListenerAdapter.java:271)
at org.eclipse.gemini.blueprint.service.importer.support.internal.util.OsgiServiceBindingUtils.callListenersBind(OsgiServiceBindingUtils.java:46)
at org.eclipse.gemini.blueprint.service.importer.support.internal.collection.OsgiServiceCollection$BaseListener.serviceChanged(OsgiServiceCollection.java:93)
at org.eclipse.gemini.blueprint.util.OsgiListenerUtils.dispatchServiceRegistrationEvents(OsgiListenerUtils.java:111)
at org.eclipse.gemini.blueprint.util.OsgiListenerUtils.addServiceListener(OsgiListenerUtils.java:88)
at org.eclipse.gemini.blueprint.util.OsgiListenerUtils.addServiceListener(OsgiListenerUtils.java:60)
at org.eclipse.gemini.blueprint.service.importer.support.internal.collection.OsgiServiceCollection.afterPropertiesSet(OsgiServiceCollection.java:324)
at org.eclipse.gemini.blueprint.service.importer.support.OsgiServiceCollectionProxyFactoryBean$1.run(OsgiServiceCollectionProxyFactoryBean.java:211)
at org.eclipse.gemini.blueprint.service.importer.support.AbstractServiceImporterProxyFactoryBean.getObject(AbstractServiceImporterProxyFactoryBean.java:103)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1446)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:622)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:60)
at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:325)
at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:290)
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:137)
at org.eclipse.virgo.kernel.agent.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:95)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Previous Topic:Mapping class from another plug-in
Next Topic:ClassCastException when accessing reference-list ServiceReference
Goto Forum:
  


Current Time: Thu Aug 21 08:15:35 EDT 2014

Powered by FUDForum. Page generated in 0.01494 seconds