ServiceBus JAVA SDK advanced reloading errors, ServiceLoader (not subtype)

血红的双手。 提交于 2019-12-24 02:59:20

问题


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:


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.



来源:https://stackoverflow.com/questions/19249008/servicebus-java-sdk-advanced-reloading-errors-serviceloader-not-subtype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!