Menu

#4 Need Help With Declarative Services

v1.0_(example)
closed
None
5
2014-09-11
2014-03-14
Quai Vat
No

Hi everyone,

I am not sure if this is the right place to ask this question. Please direct me the right place if this is not.

I am new to Declarative Services (DS) but not new to OSGi. I have been developing desktop applications using Knopflerfish 2 and Gravity Service Binder the last four years. We are looking into moving to the latest OSGi and continue to use Knopflerfish container. I spent the last couple of days creating simple bundles and tried out Knopflerfish 7.0.1 and DS, but I am facing problems that I can't seem to find the answer on Google. Hopefully you guys can help me figure out what I am missing. Do I need to place the description xml file in OSGI-INF or I can put anywhere as long as I reference it to the right location in the manifest file? Anyway, I have tried to put it in OSGI-INF but it doesn't work either.

Here is the problem. My bundles work just fine if I implement Activator class myself. But they don't work if I use DS. When I launch the program it doesn't give me any error. The "ps" command show both of my bundle are active. One of the bundle is supposed to print some text to the screen every second.

###########This is one of the manifest file looks like

Manifest-Version: 2.0
Bundle-Name: simple
Bundle-SymbolicName: Simple Bundle
Bundle-Version: 1.0.0
Bundle-Description: Simple Bundle component
Bundle-Vendor: Some Vendor
Bundle-Category: testing
Import-Package: org.osgi.framework
Service-Component: config/simple.xml

And below is the log:

############This is the beginning where program starts

Knopflerfish OSGi framework launcher, version 7.0.1
Copyright 2003-2013 Knopflerfish. All Rights Reserved.
See http://www.knopflerfish.org for more information.

1: Verbosity changed to 1

1: -Dorg.knopflerfish.gosg.jars=file:framework/jars/

1: -Dorg.knopflerfish.framework.debug.packages=false

1: -Dorg.knopflerfish.framework.debug.errors=true

1: -Dorg.knopflerfish.framework.debug.classloader=false

1: -Forg.knopflerfish.framework.debug.resolver=false

1: -Dorg.knopflerfish.framework.system.export.all_13=false

1: -Dorg.osgi.framework.bootdelegation=*

1: -Dorg.knopflerfish.startlevel.use=true

1: Created FrameworkFactory org.knopflerfish.framework.FrameworkFactoryImpl

1: framework prop org.knopflerfish.bundle.cm.store=cmdir

1: old jars=file:framework/jars/

1: Framework class org.knopflerfish.framework.SystemBundle

Created Framework: org.knopflerfish.framework, version=7.0.1.

1: Installed: file:framework/jars/log/log_api-5.0.0.jar (id#1)

1: Installed: file:framework/jars/console/console_api-4.0.1.jar (id#2)

1: Installed and started (policy): file:framework/jars/cm/cm_api-5.0.0.jar (id#3)

1: Installed and started (policy): file:framework/jars/log/log-5.0.0.jar (id#4)

1: Installed and started (policy): file:framework/jars/console/console-4.0.1.jar (id#5)

1: Installed and started (policy): file:framework/jars/consoletty/consoletty-4.0.1.jar (id#6)

1: Installed and started (policy): file:framework/jars/consoletelnet/consoletelnet-4.0.1.jar (id#7)

1: Installed and started (policy): file:framework/jars/frameworkcommands/frameworkcommands-4.0.1.jar (id#8)

1: Installed and started (policy): file:framework/jars/logcommands/logcommands-5.0.0.jar (id#9)

1: Installed and started (policy): file:framework/jars/useradmin/useradmin_api-4.0.0.jar (id#10)

1: Installed and started (policy): file:framework/jars/kxml/kxml-2.3.0.kf4-001.jar (id#11)

1: Installed and started (policy): file:framework/jars/component/component_all-5.0.0.jar (id#12)

1: Installed and started (policy): file:bundles/gui.jar (id#13)

1: Installed and started (policy): file:bundles/simple.jar (id#14)

Framework launched

############This is what is printed when I issue command "ps"

ps
id level/state name


0  0/active    System Bundle            1  1/resolved  Log Service-API
2  1/resolved  Console-API              3  1/active    cm-API
4  1/active    Log Service-IMPL         5  1/active    Console-IMPL
6  1/active    TTY-Console-IMPL         7  1/active    Telnet-Console-IMPL
8  1/active    FW-Commands-IMPL         9  1/active    LogCommands-IMPL

10 1/active UserAdmin-API 11 1/active kXML 2-LIB
12 1/active SCR 13 1/active gui
14 1/active simple

#########This is what is printed when I issue command "services"

services
Bundle: Console-IMPL (#5)
registered: ConsoleService
Bundle: FW-Commands-IMPL (#8)
registered: CommandGroup
Bundle: Log Service-IMPL (#4)
registered: LogReaderService [ManagedService,LogConfig] [LogService,LogService]
Bundle: LogCommands-IMPL (#9)
registered: CommandGroup CommandGroup
Bundle: SCR (#12)
registered: ScrService ConfigurationListener
Bundle: System Bundle (#0)
registered: PackageAdmin StartLevel
Bundle: TTY-Console-IMPL (#6)
registered: ManagedService
Bundle: Telnet-Console-IMPL (#7)
registered: ManagedService

Discussion

  • Gunnar Ekolin

    Gunnar Ekolin - 2014-03-15

    The component description xml document can go anywhere in the bundle.
    You tell the SCR-bundle (called component on the Knopflerfish distribution) where to look for them in the Service-Component header.
    E.g. with

    Service-Component: config/simple.xml

    there should be a file in the bundles jar-archive with the path

    /config/simple.xml

    The recommendation is to place component descriptions in the OSGI-INF directory to keep meta-data separated form the actual code.

    To inspect the state of service components from the KF-console we provide a small bundle (that uses SCR) to publish a console command group. This bundle is available from

    http://www.knopflerfish.org/releases/current/osgi/jars/scrcommands/scrcommands-4.0.1.jar

    and you will also find it in your downloaded Knopflerfish distribution.

     
  • Gunnar Ekolin

    Gunnar Ekolin - 2014-03-15
    • assigned_to: Gunnar Ekolin
     
  • Quai Vat

    Quai Vat - 2014-03-15

    Hi Gunnar,

    Thanks for your suggestion about placing component descriptions in OSGI-INF directory. I will keep that in mind.

    With your hint I was able to figure out the problems and finally got my bundles to register with the framework using Declarative Services. I want to share my experience so if someone comes across the issue knows what to look for:

    1. Our Ant build.xml script does not include the component description file in the jar (this was done intentionally). From your hint, I looked in the jar and didn't see the xml file. I edit the jar to include the xml file and thing gets better.

    2. But then my simple and gui bundles still didn't do anything even though both showed active. So I issued "scr list" and "scr show" commands and saw UNSATISFIED status. This hint gave me a clue where to look: One of my bundle required other bundle (specified in the component description xml file) that has not yet started. Fixing that bundle resolved the issue.

    Do you know of any tools out there that help troubleshooting application issues related to OSGi framework?

    Again, thanks for your help.
    QV

     
  • Gunnar Ekolin

    Gunnar Ekolin - 2014-05-23
    • status: open --> pending-invalid
     
  • Gunnar Ekolin

    Gunnar Ekolin - 2014-05-23

    Closing since this was a usage question and not a bug in Knopflerfish.

     
  • Gunnar Ekolin

    Gunnar Ekolin - 2014-05-23

    Ticket moved from /p/gatespace/bugs/180/

     
  • Gunnar Ekolin

    Gunnar Ekolin - 2014-05-23
    • status: pending-invalid --> closed
    • Group: 5.0 --> v1.0_(example)