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:[EMAIL PROTECTED]
Sent: Monday, July 28, 2008 12:35 PM
To: [email protected]
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