You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by William la Forge <la...@gmail.com> on 2013/05/28 06:08:50 UTC

waiting for services, is there a better way?

I have a bundle that drives some tests. It implements a simple shell to
execute various commands, like config:edit. Unfortunately, the services
backing these commands are not always started when the command is invoked.

I am currently using Thread.sleep to delay the use of the shell. This seems
pretty crude. Is there a better way?

Perhaps I should just catch the appropriate exception and try, try again?

Please be very explicit in your response. I've been having lots of fun with
this but I am still pretty much a newbie. And though I am full time on this
project, much of my time is spent migrating my old code.

Thanks in advance!

Bill

Re: waiting for services, is there a better way?

Posted by William la Forge <la...@gmail.com>.
Ah, but I am not accessing the services directly. I'm using command
processor. And unfortunately the CommandProcessor service is available
before the other services which CommandProcessor accesses.

So is it a bug in CommandProcessor, that it does not use ServiceTracker? Or
is there some other way to ensure that the services invoked by
CommandProcessor are available?

    protected String executeCommands(final String ...commands) throws
Exception {
        final ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
        final PrintStream printStream = new
PrintStream(byteArrayOutputStream);
        final CommandSession commandSession =
commandProcessor.createSession(System.in, printStream, System.err);
        String cmds = "";
        try {
            for(String command:commands) {
                log.info(command);
                cmds = cmds + command + " || ";
                commandSession.execute(command);
            }
        } catch (Exception e) {
            log.error(cmds, e);
        }
        return byteArrayOutputStream.toString();
    }



On Tue, May 28, 2013 at 11:51 AM, Freeman Fang <fr...@gmail.com>wrote:

> Or let blueprint to manage the OSGi service injection, so that your bundle
> won't be started unless all backing services are fully up
> -------------
> Freeman(Yue) Fang
>
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Web: http://fusesource.com | http://www.redhat.com/
> Twitter: freemanfang
> Blog: http://freemanfang.blogspot.com
> http://blog.sina.com.cn/u/1473905042
> weibo: @Freeman小屋
>
> www.camelone.org : The open source integration conference:
>
> On 2013-5-28, at 下午2:09, Jean-Baptiste Onofré wrote:
>
> Hi Bill,
>
> if it relays on an OSGi service, you can implement a ServiceTracker or
> loop to check if the service is there.
>
> Regards
> JB
>
> On 05/28/2013 06:08 AM, William la Forge wrote:
>
> I have a bundle that drives some tests. It implements a simple shell to
>
> execute various commands, like config:edit. Unfortunately, the services
>
> backing these commands are not always started when the command is invoked.
>
>
> I am currently using Thread.sleep to delay the use of the shell. This
>
> seems pretty crude. Is there a better way?
>
>
> Perhaps I should just catch the appropriate exception and try, try again?
>
>
> Please be very explicit in your response. I've been having lots of fun
>
> with this but I am still pretty much a newbie. And though I am full time
>
> on this project, much of my time is spent migrating my old code.
>
>
> Thanks in advance!
>
>
> Bill
>
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
>
>

Re: waiting for services, is there a better way?

Posted by Freeman Fang <fr...@gmail.com>.
Or let blueprint to manage the OSGi service injection, so that your bundle won't be started unless all backing services are fully up
-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: @Freeman小屋

www.camelone.org : The open source integration conference: 

On 2013-5-28, at 下午2:09, Jean-Baptiste Onofré wrote:

> Hi Bill,
> 
> if it relays on an OSGi service, you can implement a ServiceTracker or loop to check if the service is there.
> 
> Regards
> JB
> 
> On 05/28/2013 06:08 AM, William la Forge wrote:
>> I have a bundle that drives some tests. It implements a simple shell to
>> execute various commands, like config:edit. Unfortunately, the services
>> backing these commands are not always started when the command is invoked.
>> 
>> I am currently using Thread.sleep to delay the use of the shell. This
>> seems pretty crude. Is there a better way?
>> 
>> Perhaps I should just catch the appropriate exception and try, try again?
>> 
>> Please be very explicit in your response. I've been having lots of fun
>> with this but I am still pretty much a newbie. And though I am full time
>> on this project, much of my time is spent migrating my old code.
>> 
>> Thanks in advance!
>> 
>> Bill
> 
> -- 
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com


Re: waiting for services, is there a better way?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Bill,

if it relays on an OSGi service, you can implement a ServiceTracker or 
loop to check if the service is there.

Regards
JB

On 05/28/2013 06:08 AM, William la Forge wrote:
> I have a bundle that drives some tests. It implements a simple shell to
> execute various commands, like config:edit. Unfortunately, the services
> backing these commands are not always started when the command is invoked.
>
> I am currently using Thread.sleep to delay the use of the shell. This
> seems pretty crude. Is there a better way?
>
> Perhaps I should just catch the appropriate exception and try, try again?
>
> Please be very explicit in your response. I've been having lots of fun
> with this but I am still pretty much a newbie. And though I am full time
> on this project, much of my time is spent migrating my old code.
>
> Thanks in advance!
>
> Bill

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com