Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Problem when using update from osgi console (equinox)

  1. #1
    Join Date
    Jul 2008
    Posts
    7

    Question Problem when using update from osgi console (equinox)

    I have a service registered in project A that is referenced in project B. All is done with spring osgi namespaces. When i start both projects the dependencies work fine.
    But if i update project A in osgi console, project B can't find and inject the service.. After some time spring dm throws a timeout exception..

    There is something i need to do so project B can find services updates??

    Thanx

  2. #2
    Join Date
    Jul 2008
    Posts
    7

    Post

    To ilustrate, i create this 2 test projects:

    Bundle 12 registers the service and bundle 5 has a reference to it.

    osgi> bundle 12
    Code:
    osgi.test1_1.0.0 [12]
      Id=12, Status=ACTIVE      Data Root=/media/files/development/eclipse-workspaces/osgi-workspace/.metadata/.plugins/org.eclipse.pde.core/Jata/org.eclipse.osgi/bundles/12/data
      Registered Services
        {osgi.test1.Printer}={org.springframework.osgi.bean.name=printer, Bundle-SymbolicName=osgi.test1, Bundle-Version=1.0.0, service.id=29}
        {org.springframework.osgi.context.DelegatedExecutionOsgiBundleApplicationContext, org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext, org.springframework.context.ConfigurableApplicationContext, org.springframework.context.ApplicationContext, org.springframework.context.Lifecycle, org.springframework.beans.factory.ListableBeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.context.MessageSource, org.springframework.context.ApplicationEventPublisher, org.springframework.core.io.support.ResourcePatternResolver, org.springframework.beans.factory.BeanFactory, org.springframework.core.io.ResourceLoader, org.springframework.beans.factory.DisposableBean}={org.springframework.context.service.name=osgi.test1, Bundle-SymbolicName=osgi.test1, Bundle-Version=1.0.0, service.id=30}
      Services in use:
        {org.xml.sax.EntityResolver}={service.id=28}
        {org.springframework.beans.factory.xml.NamespaceHandlerResolver}={service.id=27}
      Exported packages
        osgi.test1; version="1.0.0"[exported]
      Imported packages
        org.osgi.framework; version="1.5.0"<org.eclipse.osgi_3.5.0.v20090520 [0]>
      No fragment bundles
      Named class space
        osgi.test1; bundle-version="1.0.0"[provided]
      No required bundles
    osgi> bundle 5
    Code:
    osgi.test.2_1.0.0 [5]
      Id=5, Status=ACTIVE      Data Root=/media/files/development/eclipse-workspaces/osgi-workspace/.metadata/.plugins/org.eclipse.pde.core/Jata/org.eclipse.osgi/bundles/5/data
      Registered Services
        {org.springframework.osgi.context.DelegatedExecutionOsgiBundleApplicationContext, org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext, org.springframework.context.ConfigurableApplicationContext, org.springframework.context.ApplicationContext, org.springframework.context.Lifecycle, org.springframework.beans.factory.ListableBeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.context.MessageSource, org.springframework.context.ApplicationEventPublisher, org.springframework.core.io.support.ResourcePatternResolver, org.springframework.beans.factory.BeanFactory, org.springframework.core.io.ResourceLoader, org.springframework.beans.factory.DisposableBean}={org.springframework.context.service.name=osgi.test.2, Bundle-SymbolicName=osgi.test.2, Bundle-Version=1.0.0, service.id=31}
      Services in use:
        {org.xml.sax.EntityResolver}={service.id=28}
        {org.springframework.beans.factory.xml.NamespaceHandlerResolver}={service.id=27}
        {osgi.test1.Printer}={org.springframework.osgi.bean.name=printer, Bundle-SymbolicName=osgi.test1, Bundle-Version=1.0.0, service.id=29}
      No exported packages
      Imported packages
        osgi.test1; version="1.0.0"<osgi.test1_1.0.0 [12]>
      No fragment bundles
      Named class space
        osgi.test.2; bundle-version="1.0.0"[provided]
      No required bundles
    If i update bundle 12, the service Printer isn't referenced in bundle 5:

    osgi> update 12

    osgi> bundle 12
    Code:
    osgi.test1_1.0.0 [12]
      Id=12, Status=ACTIVE      Data Root=/media/files/development/eclipse-workspaces/osgi-workspace/.metadata/.plugins/org.eclipse.pde.core/Jata/org.eclipse.osgi/bundles/12/data
      Registered Services
        {osgi.test1.Printer}={org.springframework.osgi.bean.name=printer, Bundle-SymbolicName=osgi.test1, Bundle-Version=1.0.0, service.id=32}
        {org.springframework.osgi.context.DelegatedExecutionOsgiBundleApplicationContext, org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext, org.springframework.context.ConfigurableApplicationContext, org.springframework.context.ApplicationContext, org.springframework.context.Lifecycle, org.springframework.beans.factory.ListableBeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.context.MessageSource, org.springframework.context.ApplicationEventPublisher, org.springframework.core.io.support.ResourcePatternResolver, org.springframework.beans.factory.BeanFactory, org.springframework.core.io.ResourceLoader, org.springframework.beans.factory.DisposableBean}={org.springframework.context.service.name=osgi.test1, Bundle-SymbolicName=osgi.test1, Bundle-Version=1.0.0, service.id=33}
      Services in use:
        {org.xml.sax.EntityResolver}={service.id=28}
        {org.springframework.beans.factory.xml.NamespaceHandlerResolver}={service.id=27}
      Exported packages
        osgi.test1; version="1.0.0"[exported]
      Imported packages
        org.osgi.framework; version="1.5.0"<org.eclipse.osgi_3.5.0.v20090520 [0]>
      No fragment bundles
      Named class space
        osgi.test1; bundle-version="1.0.0"[provided]
      No required bundles
    osgi> bundle 5
    Code:
    osgi.test.2_1.0.0 [5]
      Id=5, Status=ACTIVE      Data Root=/media/files/development/eclipse-workspaces/osgi-workspace/.metadata/.plugins/org.eclipse.pde.core/Jata/org.eclipse.osgi/bundles/5/data
      Registered Services
        {org.springframework.osgi.context.DelegatedExecutionOsgiBundleApplicationContext, org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext, org.springframework.context.ConfigurableApplicationContext, org.springframework.context.ApplicationContext, org.springframework.context.Lifecycle, org.springframework.beans.factory.ListableBeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.context.MessageSource, org.springframework.context.ApplicationEventPublisher, org.springframework.core.io.support.ResourcePatternResolver, org.springframework.beans.factory.BeanFactory, org.springframework.core.io.ResourceLoader, org.springframework.beans.factory.DisposableBean}={org.springframework.context.service.name=osgi.test.2, Bundle-SymbolicName=osgi.test.2, Bundle-Version=1.0.0, service.id=31}
      Services in use:
        {org.xml.sax.EntityResolver}={service.id=28}
        {org.springframework.beans.factory.xml.NamespaceHandlerResolver}={service.id=27}
      No exported packages
      Imported packages
        osgi.test1; version="1.0.0"<osgi.test1_1.0.0 [12]>
      No fragment bundles
      Named class space
        osgi.test.2; bundle-version="1.0.0"[provided]
      No required bundles
    My environment is:
    spring-osgi 1.2.0
    spring-framework 2.5.6.SEC01
    org.eclipse.osgi 3.5.0.v20090520

  3. #3
    Join Date
    Jul 2008
    Posts
    7

    Question

    Another thing.. When i stop bundle 5, which has a reference for service Printer, throws a error. Maybe because it's waiting for the service. And after if i try to start the bundle again, throw a exception.

    Is this may be a classloader problem??

    osgi> stop 5
    Code:
    25/06/09 01:27:53 DEBUG [Timer-1] org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor - Closing appCtx for OsgiBundleXmlApplicationContext(bundle=osgi.test.2, config=osgibundle:/META-INF/spring/*.xml)
    25/06/09 01:27:53 DEBUG [Timer-1] org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor - Shutting down normally appCtx OsgiBundleXmlApplicationContext(bundle=osgi.test.2, config=osgibundle:/META-INF/spring/*.xml)
    25/06/09 01:27:53 INFO  [Timer-1] org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext - Application Context service already unpublished
    25/06/09 01:27:53 INFO  [Timer-1] org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext - Closing org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@40bb2bc3: display name [OsgiBundleXmlApplicationContext(bundle=osgi.test.2, config=osgibundle:/META-INF/spring/*.xml)]; startup date [Thu Jun 25 01:27:37 BRT 2009]; root of context hierarchy
    25/06/09 01:28:03 ERROR [OSGi Console] org.springframework.osgi.extender.internal.util.concurrent.RunnableTimedExecution - Closing runnable for context OsgiBundleXmlApplicationContext(bundle=osgi.test.2, config=osgibundle:/META-INF/spring/*.xml) did not finish in 10000ms; consider taking a snapshot and then shutdown the VM in case the thread still hangs
    25/06/09 01:28:03 DEBUG [OSGi Console] org.springframework.osgi.extender.internal.support.NamespacePlugins - Removing handler Osgi_test_2 (osgi.test.2)
    osgi> start 5
    Code:
    ...
    25/06/09 01:30:18 DEBUG [SpringOsgiExtenderThread-10] org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean - Service reference [{osgi.test1.Printer}={org.springframework.osgi.bean.name=printer, Bundle-SymbolicName=osgi.test1, Bundle-Version=1.0.0, service.id=29}] was unregistered and unbound from the service proxy
    25/06/09 01:30:18 DEBUG [SpringOsgiExtenderThread-10] org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext - Post refresh error
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'osgi.test2.TestPrinter#0' defined in URL [bundleentry://16/META-INF/spring/osgi-test2-context.xml]: Invocation of init method failed; nested exception is org.springframework.aop.AopInvocationException: AOP configuration seems to be invalid: tried calling method [public abstract void osgi.test1.Printer.print()] on target [osgi.test1.PrinterImpl@21bbd3e2]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
    	at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
    	at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:136)
    	at java.lang.Thread.run(Thread.java:619)
    Caused by: org.springframework.aop.AopInvocationException: AOP configuration seems to be invalid: tried calling method [public abstract void osgi.test1.Printer.print()] on target [osgi.test1.PrinterImpl@21bbd3e2]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:315)
    	at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
    	at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:56)
    	at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:39)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy7.print(Unknown Source)
    	at osgi.test2.TestPrinter.start(TestPrinter.java:15)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
    	... 17 more
    Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    	... 41 more

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    You need to separate the static parts of your setup from the dynamic one. From your setup it sounds like bundle A provides some classes and services which are used by bundle B. When you update bundle A, then you load a new set of classes and services - bundle B still refers to the old ones.
    You have to either refresh B (to pick up the new versions) or extract the interfaces into a separate bundle C.
    This way B can import the classes in C and look for the services deployed by A. When you refresh A, the new services will still use the classes in C which B sees so they will be picked up.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5
    Join Date
    Jul 2008
    Posts
    7

    Default

    Hi Costin, thanks for your answer.

    I managed to solve this problem today. Import what you export :P

    Reference:
    http://www.osgi.org/blog/2007/04/imp...importing.html

    Thanks again.
    Lucas

  6. #6
    Join Date
    Jan 2007
    Location
    Poland
    Posts
    17

    Default

    I've got the same problem. Bundle B uses bundle A via some service. Jar file of bundle A is the same - no changes made. After updating A in console, B stops seeing services in A. Bundle A binary-wise is the same all the time though. Only after refreshing bundle B (in console) services are visible again.
    Interesting thing, when I just stop A and then start it again services coming back to B nicely.
    Last edited by mccat; Jun 25th, 2009 at 03:32 PM.

  7. #7
    Join Date
    Jul 2008
    Posts
    7

    Default

    Exactly what i had.

    I solved with something like this:

    Bundle A (register service)

    Export-Package: org.example;version="1.0.0"
    Import-Package: org.example;version="1.0.0"

    Bundle B (reference service)

    Import-Package: org.example;version="1.0.0"

  8. #8
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Right - you can also do it like this. The key point is that you need a static (non changing bundle). It's something easy to forget that despite the class definition, just refreshing a bundle means creating a new version of the class.
    The VM defines a class by its byte code definition and loading class loader not by the class hash. Unfortunately, classes do not provide a 'version' attribute so it's not always clear what's the case until you start looking at the defining classloaders.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  9. #9
    Join Date
    Jan 2007
    Location
    Poland
    Posts
    17

    Default

    Hello again, "importing what exporting" paradigm not working - I've got exception:
    Code:
    Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) previously initiat
    ed loading for a different type with name "x/xx/MyBean"
    Probably, cause is the same - mixing dynamic and static part.

    Costins' suggestion with external static bundle with interfaces is working great.

    Maybe , this is a good tip to place it in documentation?
    Last edited by mccat; Jun 29th, 2009 at 01:48 AM.

  10. #10
    Join Date
    Jul 2009
    Posts
    3

    Default It seems like it still should work...

    Quote Originally Posted by Costin Leau View Post
    You need to separate the static parts of your setup from the dynamic one. From your setup it sounds like bundle A provides some classes and services which are used by bundle B. When you update bundle A, then you load a new set of classes and services - bundle B still refers to the old ones.
    You have to either refresh B (to pick up the new versions) or extract the interfaces into a separate bundle C.
    This way B can import the classes in C and look for the services deployed by A. When you refresh A, the new services will still use the classes in C which B sees so they will be picked up.
    So, I understand what you're saying and agree that it is a good idea to separate, but I don't understand why it is necessary. Why can't a bundle A (containing both interface and implementation classes) be updated and bound to a dependent bundle dynamically?

    When you update, you said above that a new set of classes and services are created while the dependent bundle still refers to the old one; why can't these references be broken (using a proxy or something else) and updated to the new ones when the bundle is started?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •