dev@glassfish.java.net

Re: [Ask]about RunLevelControllerThread

From: Tang Yong <tangyong_at_cn.fujitsu.com>
Date: Wed, 18 Dec 2013 22:26:27 +0900

JWells,

Another question is related to RunLevelControllerThread as following:

According to https://hk2.java.net/2.2.0-b26/runlevel.html, using
controller.proceedTo(level) will block host thread. However,

1) after I have seen the RunLevelControllerImpl class, it seems that
proceedToAsync(int runLevel)'s handling logic is the same as
proceedTo(int runLevel). And they all can not block host thread.

2) a fact maybe is: in Glassfish's
com.sun.enterprise.v3.server.AppServerStartup class, the following

...
 if (!proceedTo(StartupRunLevel.VAL)) {
            ...
 }

 if (!postStartupJob()) {
        ...
}
...

While executing proceedTo(StartupRunLevel.VAL), RunLevelControllerThread
can not block Glassfish Main thread, instead, Main thread will continue
to execute postStartupJob().

I want to know whether I am right?

Thanks
Tang

Tang Yong wrote:
> Surly, thanks, JWells.
>
> The question comes from(*maybe*) an issue:
>
> https://java.net/jira/browse/GLASSFISH-20934
>
> Here, there are two threads which all influence some module's state.
>
> If I want to fix the issue, one way is that in
> org.jvnet.hk2.osgiadapter.OSGiModuleImpl.start method, I catch the felix
> exception and then, by some way, I get RunLevelControllerThread's
> running result to see the bundle's status changing and re-start the
> bundle(if needing).
>
> "by some way" should be using listener, however, in reality, while GF
> kernel is starting, it has registered an
> listerner(com.sun.enterprise.v3.server.AppServerStartup.MasterRunLevelListener)
> , and this listener is only limited in gf kernel scope. So, I am a
> litter puzzled how to handle from osgiadapter module.
>
> I am sorry for suddenly bringing the GF issue, if you have more time, I
> want to listen your advice.
>
> Thanks
> Tang
>
> John Wells wrote:
>> I don't think that will work because inside the onProgress the
>> levelAchieved will always equal the current run level.
>>
>> On 12/17/2013 8:26 AM, Tang Yong wrote:
>>> Thanks JWells's reply!
>>>
>>> Whether the following is also another way:
>>>
>>> @Inject
>>> private Provider<RunLevelController> controllerProvider;
>>>
>>> if (controllerProvider.get().getCurrentRunLevel() == levelAchieved) {
>>> ...
>>> }
>>>
>>> Thanks
>>> Tang
>>>
>>> John Wells wrote:
>>>> I guess I'd like to understand your use case, since I think you can
>>>> use the RunLevelListener to determine if the job is complete.
>>>>
>>>> Basically, if you were to do something like this:
>>>>
>>>> public void onProgress(ChangeableRunLevelFuture <https://hk2.java.net/2.2.0-b26/apidocs/org/glassfish/hk2/runlevel/ChangeableRunLevelFuture.html> currentJob,
>>>> int levelAchieved){
>>>> if (currentJob.getProposedLevel() == levelAchieved) {
>>>> // The job is finished
>>>> }
>>>> else {
>>>> // The job is not finished yet
>>>> }
>>>> }
>>>>
>>>> I think you would have what you wanted, right?
>>>>
>>>>
>>>> On 12/17/2013 4:46 AM, Tang Yong wrote:
>>>>> About the question, I also searched the source and [1],
>>>>>
>>>>> The best way should use RunLevelListener, however, RunLevelListener does
>>>>> not off an api for task completed.
>>>>>
>>>>> [1]:https://hk2.java.net/2.2.0-b26/runlevel.html
>>>>>
>>>>> Thanks
>>>>> Tang
>>>>>
>>>>> Tang Yong wrote:
>>>>>> Hi JWells, Mason,
>>>>>>
>>>>>> I have an urgent question about RunLevelControllerThread,
>>>>>>
>>>>>> While using the following way to move to the given run level,
>>>>>>
>>>>>> RunLevelController.proceedTo(runLevel)
>>>>>>
>>>>>> I want to know whether having any way to know when the
>>>>>> RunLevelControllerThread has been ended?
>>>>>>
>>>>>> Thanks
>>>>>> Tang
>>>>>>
>>
>>
>

-- 
−−−−−−−−−−−−−−−−−−−−−−
Tang Yong
Senior Engineer
GlassFish Committer (OSGi & OSGi-JavaEE)
OSGi Alliance Supporter
Blog: http://osgizone.typepad.com/tangyong/
Nanjing Fujitsu NanDa Software Tec CO.,LTD
http://www.fujitsu.com/cn/fnst
Tel: +86-25-86630566-8310
Fax: +86-25-83317685              
−−−−−−−−−−−−−−−−−−−−−−