users@hk2.java.net

Re: RunLevelController issue

From: john wells <john.wells_at_oracle.com>
Date: Thu, 04 Feb 2016 08:04:40 -0500

Your ServiceLocator is separate, and hence it should (*should*) have no
interference from GlassFish or Jersey. I'm relatively sure that this is
some sort of GlassFish classloading issue, although in the stack below I
do not see any classloading issues popping up.

Can you try using ServiceLocatorUtilities.dumpAllDescriptors prior to
calling proceedTo and post the results so we can get a handle on what
services are actually in your locator?

Of course, the fact that it runs fine stand-alone points to some sort of
classloader pollution which is unfortunate...

On 2/3/2016 7:11 PM, Dan Armbrust wrote:
> Hi,
>
> I'm trying to debug an ugly issue I really don't understand - not sure
> if it is a bug or not.
>
> I have an application which works fine, using this pattern:
>
> ServiceLocator locator =
> ServiceLocatorFactory.getInstance().create(serviceLocatorName);
> ServiceLocatorUtilities.addClasses(locator, ac.getAnnotatedClasses())
>
> The annotated class list is coming from this utility:
> https://github.com/VA-CTT/HK2Utilities
>
> Which essentially finds all HK2 annotated classes on the classpath
> without relying on the inhabitant files.
>
> Then:
>
> locator.getService(RunLevelController.class).proceedTo(runLevel);
>
> All of this works fine in a stand-alone app.
>
> Now, I'm trying to deploy within GlassFish, while also using Jersey.
>
> In this environment, the deployment fails with a mess of exceptions
> along these lines:
>
>
> org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no
> object available for injection at
> SystemInjecteeImpl(requiredType=AsyncRunLevelContext,parent=RunLevelContext,qualifiers={},position=0,optional=false,self=false,unqualified=null,853404053)
> at
> org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:75)
> at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:211)
> at
> org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:228)
> at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:357)
> at
> org.jvnet.hk2.internal.AutoActiveDescriptor.create(AutoActiveDescriptor.java:150)
> at
> org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:463)
> at
> org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:83)
> at
> org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:71)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97)
> at java.util.concurrent.FutureTask.run(Unknown Source)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:154)
> at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:199)
> at
> org.jvnet.hk2.internal.SingletonContext.findOrCreate(SingletonContext.java:122)
> at
> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2072)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl._resolveContext(ServiceLocatorImpl.java:2088)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl.access$000(ServiceLocatorImpl.java:121)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl$3.compute(ServiceLocatorImpl.java:181)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl$3.compute(ServiceLocatorImpl.java:177)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97)
> at java.util.concurrent.FutureTask.run(Unknown Source)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:154)
> at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:199)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl.resolveContext(ServiceLocatorImpl.java:2107)
> at
> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2050)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1213)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1144)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$UpOneLevel.run(CurrentTaskFuture.java:762)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
> MultiException stack 2 of 5
> java.lang.IllegalArgumentException: While attempting to resolve the
> dependencies of org.glassfish.hk2.runlevel.RunLevelContext errors were
> found
> at
> org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:246)
> at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:357)
> at
> org.jvnet.hk2.internal.AutoActiveDescriptor.create(AutoActiveDescriptor.java:150)
> at
> org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:463)
> at
> org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:83)
> at
> org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:71)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97)
> at java.util.concurrent.FutureTask.run(Unknown Source)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:154)
> at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:199)
> at
> org.jvnet.hk2.internal.SingletonContext.findOrCreate(SingletonContext.java:122)
> at
> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2072)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl._resolveContext(ServiceLocatorImpl.java:2088)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl.access$000(ServiceLocatorImpl.java:121)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl$3.compute(ServiceLocatorImpl.java:181)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl$3.compute(ServiceLocatorImpl.java:177)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97)
> at java.util.concurrent.FutureTask.run(Unknown Source)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:154)
> at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:199)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl.resolveContext(ServiceLocatorImpl.java:2107)
> at
> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2050)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1213)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1144)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$UpOneLevel.run(CurrentTaskFuture.java:762)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
> MultiException stack 3 of 5
> java.lang.IllegalStateException: Unable to perform operation: resolve
> on org.glassfish.hk2.runlevel.RunLevelContext
> at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:386)
> at
> org.jvnet.hk2.internal.AutoActiveDescriptor.create(AutoActiveDescriptor.java:150)
> at
> org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:463)
> at
> org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:83)
> at
> org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:71)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97)
> at java.util.concurrent.FutureTask.run(Unknown Source)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:154)
> at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:199)
> at
> org.jvnet.hk2.internal.SingletonContext.findOrCreate(SingletonContext.java:122)
> at
> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2072)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl._resolveContext(ServiceLocatorImpl.java:2088)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl.access$000(ServiceLocatorImpl.java:121)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl$3.compute(ServiceLocatorImpl.java:181)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl$3.compute(ServiceLocatorImpl.java:177)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97)
> at java.util.concurrent.FutureTask.run(Unknown Source)
> at
> org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:154)
> at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:199)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl.resolveContext(ServiceLocatorImpl.java:2107)
> at
> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2050)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1213)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1144)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$UpOneLevel.run(CurrentTaskFuture.java:762)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
> MultiException stack 4 of 5
> java.lang.IllegalStateException: While attempting to create a service
> for SystemDescriptor(
> implementation=gov.vha.isaac.ochre.api.util.WorkExecutors
> contracts={gov.vha.isaac.ochre.api.util.WorkExecutors}
> scope=org.glassfish.hk2.runlevel.RunLevel
> qualifiers={}
> descriptorType=CLASS
> descriptorVisibility=NORMAL
> metadata=runLevelValue={-1},runLevelMode={1}
> rank=0
> loader=null
> proxiable=null
> proxyForSameScope=null
> analysisName=default
> id=62
> locatorId=8
> identityHashCode=1392457865
> reified=true) in scope org.glassfish.hk2.runlevel.RunLevel an
> error occured while locating the context
> at
> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2055)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1213)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1144)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
> MultiException stack 5 of 5
> java.lang.IllegalStateException: While attempting to create a service
> for SystemDescriptor(
> implementation=gov.vha.isaac.ochre.api.util.WorkExecutors
> contracts={gov.vha.isaac.ochre.api.util.WorkExecutors}
> scope=org.glassfish.hk2.runlevel.RunLevel
> qualifiers={}
> descriptorType=CLASS
> descriptorVisibility=NORMAL
> metadata=runLevelValue={-1},runLevelMode={1}
> rank=0
> loader=null
> proxiable=null
> proxyForSameScope=null
> analysisName=default
> id=11
> locatorId=8
> identityHashCode=1088961042
> reified=true) in scope org.glassfish.hk2.runlevel.RunLevel an
> error occured while locating the context
> at
> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2055)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
> at
> org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1213)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1144)
> at
> org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$UpOneLevel.run(CurrentTaskFuture.java:762)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
>
>
> I know that the AsyncRunLevelContext is in the system - I'm printing
> this out when I add it to my locator:
>
> [2016-02-03T18:35:21.786-0500] [glassfish 4.1] [INFO] [] [] [tid:
> _ThreadID=97 _ThreadName=Thread-8] [timeMillis: 1454542521786]
> [levelValue: 800] [[
> 2016-02-03 18:35:21,786 DEBUG [admin-listener(7)]
> HK2Utilities.HK2RuntimeInitializer (HK2RuntimeInitializer.java:113) -
> Added SystemDescriptor(
> implementation=org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext
> contracts={org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext}
> scope=javax.inject.Singleton
> qualifiers={}
> descriptorType=CLASS
> descriptorVisibility=LOCAL
> metadata=
> rank=0
> loader=null
> proxiable=null
> proxyForSameScope=null
> analysisName=default
> id=39
> locatorId=8
> identityHashCode=2097701558
> reified=true)]]
>
> So I can't understand why this isn't being found.
>
> I know that there is an issue with multiple ServiceLocator, because
> Jersey has already started one. I have also tried various
> permutations of setting the ServiceLocator from Jersey as my parent
> service locator, or calling the bridging methods to try to bridge my
> service locator to the jersey service locator (and the reverse) but
> that only seems to result in deeper error traces.
>
> I suppose another thing I haven't investigated is the interaction
> between glassfish providing HK2 libraries, and my war file also
> including libraries.
>
> Any ideas?
>
> Thanks,
>
> Dan