ServiceBus JAVA SDK advanced reloading errors, Ser

2019-07-17 19:53发布

I have an OSGi environment running some bundles, one of them uses Service Bus API (Azure Java SDK v 0.4.4) and there are some errors after I reload my OSGi environment. The workflow is this:

  • Initialize the JVM and the OSGi framework
  • Bundles are loaded and started
  • Service Bus bundle creates a Configuration using "ServiceBusConfiguration.configureWithWrapAuthentication(v,w,x,y,z)" call and everything runs smoothly

  • I programmatically restart the OSGi framework and then all bundles are loaded and started again

  • Service Bus bundle tries to create a Configuration using "ServiceBusConfiguration.configureWithWrapAuthentication(v,w,x,y,z)" but this time I get the following error:

Exception in thread "Thread-7" java.util.ServiceConfigurationError: com.microsoft.windowsazure.services.core.Builder$Exports: Provider com.microsoft.windowsazure.services.blob.Exports not a subtype at java.util.ServiceLoader.fail(ServiceLoader.java:231) at java.util.ServiceLoader.access$300(ServiceLoader.java:181) at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:369) at java.util.ServiceLoader$1.next(ServiceLoader.java:445) at com.microsoft.windowsazure.services.core.DefaultBuilder.create(DefaultBuilder.java:43) at com.microsoft.windowsazure.services.core.Configuration.<init>(Configuration.java:52) at com.microsoft.windowsazure.services.core.Configuration.load(Configuration.java:78) at com.microsoft.windowsazure.services.core.Configuration.getInstance(Configuration.java:63) at com.microsoft.windowsazure.services.serviceBus.ServiceBusConfiguration.configureWithWrapAuthentication(ServiceBusConfiguration.java:88)

After some debugging I see that it could be an issue with the ServiceLoader, more exactly when it checks if the com.microsoft.windowsazure.services.blob.Exports is a subclass or implements com.microsoft.windowsazure.services.core.Builder$Exports which is also being checked after during the first run.

So in my opinion there must be something that prevents the proper reload of the Services but I've not been able to figure out what's exactly happening.

Hope any of you has a clue about that!

1条回答
成全新的幸福
2楼-- · 2019-07-17 20:41

ServiceLoader is part of the JRE class libs and it unware of OSGi class loading. When you restart an OSGi framework, all the bundles get new class loaders and thus the loaded classes from bundles are different class objects than before. If the ServiceLoader instance survives the framework restart, it will still be referencing the original class object.

查看更多
登录 后发表回答