You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Craig Phillips <lc...@praxiseng.com> on 2008/07/28 18:35:05 UTC

shell service, command, and declarative services

Hi,

I have a feeling this is another "oh by the way" by incorporating
declarative services into the mix... I'm attempting to implement a
"command" (as in org.apache.felix.shell.Command), but the actual
execute() method is not being invoked...  I'll put some snippets and
some run time output in here so folks can see the pertinent pieces at
play:

public class Sender01 implements Command
{
   public String getUsage( { return "event-snd help"; }
   // and, of course... public String getName() and getDescription()

   public void execute(String line, PrintStream arg1, PrintStream arg2)
   {
      // printf() by any other name for short: "execute() trace; line{"
+ line + "};");
   }
}

My OSGI-INF/dot.xml has: <provide
interface='org.apache.felix.shell.Command'/>

In the ps, you see my bundle:
[   8] [Active     ] [    1] org.craig.event.sender01 - sample bundle

In the scr list, you see my command service:
-> scr info 1
ID: 1
Name: org.craig.event.sender.Sender01
Bundle: org.craig.event.sender01 (8)
State: active
Default State: enabled
Activation: delayed
Services: org.apache.felix.shell.Command
Service Type: service

But, when I type services, "Command" does not show up:
org.craig.event.sender01 - sample bundle
------------------------------------------------------------------------
-----------
org.osgi.service.cm.ManagedService
->

Interestingly, however, the help has my usage in there:
-> help
bundlelevel <level> <id> ... | <id> - set or get bundle start level.
install <URL> [<URL> ...]           - install bundle(s).
event-snd help                      - org.craig.event.sender01
description entry

But, if I attempt to execute some kind of event-snd command, nothing:
-> event-snd help
-> Command not found.
event-snd
Command not found.
->

So, I guess the question to all of you / anyone out there is:  what am I
missing?

Thanks, Craig Phillips, Praxis Engineering


RE: shell service, command, and declarative services

Posted by Craig Phillips <lc...@praxiseng.com>.
Richard,
 
Hmmm....  dang....   I guess I've got a bit more "checking" to do... somewhere... I really appreciate you taking the time to whip up something on your end that works... 
 
Ahh... I think I know what it is...   "getName()"...  I was returning a rather conversational string instead of a short command...  I'm not at my workspace to check this, but I'm almost dead certain that's the problem...  I'm sure it's a spec thing, using "getName()" for the command string... I just got confused on what it's meaning was (for example, in the manifest, you have name, description and symbolic name, but it's the symbolic name that counts)...
 
Whew... at least it is/was (tbd, but I should know soon enough) something simple...
 
Much appreciative and apologize for any inconvenience/trouble to your end / all you folk... I guess at least it'll be something to stick out in our collective heads should (likely) someone else out there have the same "mis-use" issue...
 
Have a good day, Craig Phillips, Praxis

________________________________

From: Richard S. Hall [mailto:heavy@ungoverned.org]
Sent: Mon 7/28/2008 2:15 PM
To: dev@felix.apache.org
Subject: Re: shell service, command, and declarative services



Yes, I guess you are doing something incorrectly, but I don't think you
are giving me enough information to figure out your mistake. I have
created a bundle with the following content:

heavy:~/tmp/craig$ jar tf craig.jar
META-INF/
META-INF/MANIFEST.MF
craig/
craig/Activator.class
craig/Command01.class

With the following manifest:

heavy:~/tmp/craig$ more manifest.mf
Bundle-Name: Test Command
Bundle-SymbolicName: test.command
Bundle-Activator: craig.Activator
Import-Package: org.osgi.framework,org.apache.felix.shell

And the following source code:

package craig;

import java.io.PrintStream;
import org.osgi.framework.*;
import org.apache.felix.shell.*;

public class Activator implements BundleActivator
{
   public void start(BundleContext arg0) throws Exception
   {
      arg0.registerService(org.apache.felix.shell.Command.class.getName(),
                            new Command01(), null);
   }

   public void stop(BundleContext arg0) throws Exception
   {
      System.out.println("command01Activator.stop() trace");
   }
}

class Command01 implements Command
{
   public String getName()
   {
      return "cmd01";
   }

   public String getUsage()
   {
      return "cmd01 help";
   }

   public String getShortDescription()
   {
      return "Simple test command";
   }
   public void execute(String line, PrintStream out, PrintStream err)
   {
      System.out.println("Command executed: " + getName());
   }
}

And it worked fine for me:

-> cmd01
Command executed: cmd01

So, double check what you are doing.

-> richard


Craig Phillips wrote:
> Hi,
>
> I removed declarative services from the mix, pretty much reducing my
> example to the straight sample as provided by the felix documentation,
> still to no avail (meaning, exact same results/symptoms as with the
> SCR/DS in the mix); As in original post, I am providing some sample
> snippets for your/our amusement... First, the run time stuff:
>
> -> help
> cmd01 help                          - Command01 description
> -> cmd01
> Command not found.
> -> cmd01 help
> Command not found.
>
> -> services  // doesn't produce anything registered for my "command01"
> even though I did the register:
>
> public class Command01Activator implements BundleActivator
> {
>    public void start(BundleContext arg0) throws Exception
>    {
>       arg0.registerService(
> org.apache.felix.shell.Command.class.getName(),
>                             new Command01(), null);
>    }
>
>    public void stop(BundleContext arg0) throws Exception
>    {
>       System.out.println("command01Activator.stop() trace");
>    }
> }
>
> public class Command01 implements Command
> {
>    public String getUsage()
>    {
>       return "cmd01 help";
>    }
> }
>
> This is about as "out of the box" as I can get it... I followed the
> documentation to a "T" to the best of my knowledge...
>
> Obviously, I'm missing some trick...  Thanks again, Craig
>
> -----Original Message-----
> From: Craig Phillips [mailto:lcphillips@praxiseng.com]
> Sent: Monday, July 28, 2008 12:35 PM
> To: dev@felix.apache.org
> Subject: shell service, command, and declarative services
>
> Hi,
>
> I have a feeling this is another "oh by the way" by incorporating
> declarative services into the mix... I'm attempting to implement a
> "command" (as in org.apache.felix.shell.Command), but the actual
> execute() method is not being invoked...  I'll put some snippets and
> some run time output in here so folks can see the pertinent pieces at
> play:
>
> public class Sender01 implements Command
> {
>    public String getUsage( { return "event-snd help"; }
>    // and, of course... public String getName() and getDescription()
>
>    public void execute(String line, PrintStream arg1, PrintStream arg2)
>    {
>       // printf() by any other name for short: "execute() trace; line{"
> + line + "};");
>    }
> }
>
> My OSGI-INF/dot.xml has: <provide
> interface='org.apache.felix.shell.Command'/>
>
> In the ps, you see my bundle:
> [   8] [Active     ] [    1] org.craig.event.sender01 - sample bundle
>
> In the scr list, you see my command service:
> -> scr info 1
> ID: 1
> Name: org.craig.event.sender.Sender01
> Bundle: org.craig.event.sender01 (8)
> State: active
> Default State: enabled
> Activation: delayed
> Services: org.apache.felix.shell.Command
> Service Type: service
>
> But, when I type services, "Command" does not show up:
> org.craig.event.sender01 - sample bundle
> ------------------------------------------------------------------------
> -----------
> org.osgi.service.cm.ManagedService
> ->
>
> Interestingly, however, the help has my usage in there:
> -> help
> bundlelevel <level> <id> ... | <id> - set or get bundle start level.
> install <URL> [<URL> ...]           - install bundle(s).
> event-snd help                      - org.craig.event.sender01
> description entry
>
> But, if I attempt to execute some kind of event-snd command, nothing:
> -> event-snd help
> -> Command not found.
> event-snd
> Command not found.
> ->
>
> So, I guess the question to all of you / anyone out there is:  what am I
> missing?
>
> Thanks, Craig Phillips, Praxis Engineering
>
>  



Re: shell service, command, and declarative services

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Yes, I guess you are doing something incorrectly, but I don't think you 
are giving me enough information to figure out your mistake. I have 
created a bundle with the following content:

heavy:~/tmp/craig$ jar tf craig.jar
META-INF/
META-INF/MANIFEST.MF
craig/
craig/Activator.class
craig/Command01.class

With the following manifest:

heavy:~/tmp/craig$ more manifest.mf
Bundle-Name: Test Command
Bundle-SymbolicName: test.command
Bundle-Activator: craig.Activator
Import-Package: org.osgi.framework,org.apache.felix.shell

And the following source code:

package craig;

import java.io.PrintStream;
import org.osgi.framework.*;
import org.apache.felix.shell.*;

public class Activator implements BundleActivator
{
   public void start(BundleContext arg0) throws Exception
   {
      arg0.registerService(org.apache.felix.shell.Command.class.getName(),
                            new Command01(), null);
   }

   public void stop(BundleContext arg0) throws Exception
   {
      System.out.println("command01Activator.stop() trace");
   }
}

class Command01 implements Command
{
   public String getName()
   {
      return "cmd01";
   }

   public String getUsage()
   {
      return "cmd01 help";
   }

   public String getShortDescription()
   {
      return "Simple test command";
   }
   public void execute(String line, PrintStream out, PrintStream err)
   {
      System.out.println("Command executed: " + getName());
   }
}

And it worked fine for me:

-> cmd01
Command executed: cmd01

So, double check what you are doing.

-> richard


Craig Phillips wrote:
> Hi,
>
> I removed declarative services from the mix, pretty much reducing my
> example to the straight sample as provided by the felix documentation,
> still to no avail (meaning, exact same results/symptoms as with the
> SCR/DS in the mix); As in original post, I am providing some sample
> snippets for your/our amusement... First, the run time stuff:
>
> -> help
> cmd01 help                          - Command01 description
> -> cmd01
> Command not found.
> -> cmd01 help
> Command not found.
>
> -> services  // doesn't produce anything registered for my "command01"
> even though I did the register:
>
> public class Command01Activator implements BundleActivator
> {
>    public void start(BundleContext arg0) throws Exception
>    {
>       arg0.registerService(
> org.apache.felix.shell.Command.class.getName(),
>                             new Command01(), null);
>    }
>
>    public void stop(BundleContext arg0) throws Exception
>    {
>       System.out.println("command01Activator.stop() trace");
>    }
> }
>
> public class Command01 implements Command
> {
>    public String getUsage()
>    {
>       return "cmd01 help";
>    }
> }
>
> This is about as "out of the box" as I can get it... I followed the
> documentation to a "T" to the best of my knowledge...
>
> Obviously, I'm missing some trick...  Thanks again, Craig
>
> -----Original Message-----
> From: Craig Phillips [mailto:lcphillips@praxiseng.com] 
> Sent: Monday, July 28, 2008 12:35 PM
> To: dev@felix.apache.org
> Subject: shell service, command, and declarative services
>
> Hi,
>
> I have a feeling this is another "oh by the way" by incorporating
> declarative services into the mix... I'm attempting to implement a
> "command" (as in org.apache.felix.shell.Command), but the actual
> execute() method is not being invoked...  I'll put some snippets and
> some run time output in here so folks can see the pertinent pieces at
> play:
>
> public class Sender01 implements Command
> {
>    public String getUsage( { return "event-snd help"; }
>    // and, of course... public String getName() and getDescription()
>
>    public void execute(String line, PrintStream arg1, PrintStream arg2)
>    {
>       // printf() by any other name for short: "execute() trace; line{"
> + line + "};");
>    }
> }
>
> My OSGI-INF/dot.xml has: <provide
> interface='org.apache.felix.shell.Command'/>
>
> In the ps, you see my bundle:
> [   8] [Active     ] [    1] org.craig.event.sender01 - sample bundle
>
> In the scr list, you see my command service:
> -> scr info 1
> ID: 1
> Name: org.craig.event.sender.Sender01
> Bundle: org.craig.event.sender01 (8)
> State: active
> Default State: enabled
> Activation: delayed
> Services: org.apache.felix.shell.Command
> Service Type: service
>
> But, when I type services, "Command" does not show up:
> org.craig.event.sender01 - sample bundle
> ------------------------------------------------------------------------
> -----------
> org.osgi.service.cm.ManagedService
> ->
>
> Interestingly, however, the help has my usage in there:
> -> help
> bundlelevel <level> <id> ... | <id> - set or get bundle start level.
> install <URL> [<URL> ...]           - install bundle(s).
> event-snd help                      - org.craig.event.sender01
> description entry
>
> But, if I attempt to execute some kind of event-snd command, nothing:
> -> event-snd help
> -> Command not found.
> event-snd
> Command not found.
> ->
>
> So, I guess the question to all of you / anyone out there is:  what am I
> missing?
>
> Thanks, Craig Phillips, Praxis Engineering
>
>   

RE: shell service, command, and declarative services

Posted by Craig Phillips <lc...@praxiseng.com>.
Hi,

I removed declarative services from the mix, pretty much reducing my
example to the straight sample as provided by the felix documentation,
still to no avail (meaning, exact same results/symptoms as with the
SCR/DS in the mix); As in original post, I am providing some sample
snippets for your/our amusement... First, the run time stuff:

-> help
cmd01 help                          - Command01 description
-> cmd01
Command not found.
-> cmd01 help
Command not found.

-> services  // doesn't produce anything registered for my "command01"
even though I did the register:

public class Command01Activator implements BundleActivator
{
   public void start(BundleContext arg0) throws Exception
   {
      arg0.registerService(
org.apache.felix.shell.Command.class.getName(),
                            new Command01(), null);
   }

   public void stop(BundleContext arg0) throws Exception
   {
      System.out.println("command01Activator.stop() trace");
   }
}

public class Command01 implements Command
{
   public String getUsage()
   {
      return "cmd01 help";
   }
}

This is about as "out of the box" as I can get it... I followed the
documentation to a "T" to the best of my knowledge...

Obviously, I'm missing some trick...  Thanks again, Craig

-----Original Message-----
From: Craig Phillips [mailto:lcphillips@praxiseng.com] 
Sent: Monday, July 28, 2008 12:35 PM
To: dev@felix.apache.org
Subject: shell service, command, and declarative services

Hi,

I have a feeling this is another "oh by the way" by incorporating
declarative services into the mix... I'm attempting to implement a
"command" (as in org.apache.felix.shell.Command), but the actual
execute() method is not being invoked...  I'll put some snippets and
some run time output in here so folks can see the pertinent pieces at
play:

public class Sender01 implements Command
{
   public String getUsage( { return "event-snd help"; }
   // and, of course... public String getName() and getDescription()

   public void execute(String line, PrintStream arg1, PrintStream arg2)
   {
      // printf() by any other name for short: "execute() trace; line{"
+ line + "};");
   }
}

My OSGI-INF/dot.xml has: <provide
interface='org.apache.felix.shell.Command'/>

In the ps, you see my bundle:
[   8] [Active     ] [    1] org.craig.event.sender01 - sample bundle

In the scr list, you see my command service:
-> scr info 1
ID: 1
Name: org.craig.event.sender.Sender01
Bundle: org.craig.event.sender01 (8)
State: active
Default State: enabled
Activation: delayed
Services: org.apache.felix.shell.Command
Service Type: service

But, when I type services, "Command" does not show up:
org.craig.event.sender01 - sample bundle
------------------------------------------------------------------------
-----------
org.osgi.service.cm.ManagedService
->

Interestingly, however, the help has my usage in there:
-> help
bundlelevel <level> <id> ... | <id> - set or get bundle start level.
install <URL> [<URL> ...]           - install bundle(s).
event-snd help                      - org.craig.event.sender01
description entry

But, if I attempt to execute some kind of event-snd command, nothing:
-> event-snd help
-> Command not found.
event-snd
Command not found.
->

So, I guess the question to all of you / anyone out there is:  what am I
missing?

Thanks, Craig Phillips, Praxis Engineering