Thanks Richard,

What you proposed do helps.
But I figured out that my problem was more than that,

It was the because the name of the references:
in the Upnp TV example, they registered the service like this:

  serviceRegistration = context.registerService(UPnPDevice.class
                .getName(), tvDev, dict);


However, while I was referring to the service, I used the
TvDevice.class.getName();
in which made me could not find the service.

                tvref = context.getServiceReference(
TvDevice.class.getName());                 TvDevice tvd =
(TvDevice)context.getService(tvref);

I changed my code to :

                tvref = context.getServiceReference(
*UPnPDevice*.class.getName());
                TvDevice tvd = (TvDevice)context.getService(tvref);

Then it works.

However, one more problem proposed was that because it looks like that there
might be more than one service references that with the name: *
PnPDevice.class.getName();
*
So, still I have the problem in identifying the class.
if I deploy two services with the same name, I can only get the first one.

Hope what I said make sense to you.

Thanks a lot

Leon.
On Thu, Mar 11, 2010 at 11:59 AM, Richard S. Hall <he...@ungoverned.org>wrote:

>
>
> On 3/11/10 13:05, Leon668 wrote:
>
>> Hi,
>>
>> I am trying to do some experiments of invoking another service in one
>> bundler by searching for their  references.
>> My code and my pom.xml are as follows, it can pass the compilation
>> however,
>> it cannot be started after I deployed the jar file into the felix runtime.
>>
>> However, the service my code invoked is correctly running at felix.
>>
>>
>
> It looks like the bundle is being started as part of framework startup
> since it is running on the Start Level thread. If so, there could be an
> ordering issue. Maybe your service provider bundle isn't started up yet. You
> should consider using a ServiceTracker or listening for service events.
> Never just assume the service is there.
>
> -> richard
>
>
>  Thanks a lot.
>>
>> The error message shows:
>>
>> ->  [INFO] Started bridged http service
>> [INFO] Started bridged http service
>> [INFO] Http service whiteboard started
>> [INFO] Detected extended HttpService. Filters enabled.
>> *INFO * org.apache.felix.webconsole.internal.compendium.ComponentsServlet
>> not enabled. Reason: Class org.apache.felix.scr.ScrService missing
>> [INFO] Started jetty 6.1.x at port 8080
>> ERROR: Error starting
>>
>> file:/home/user/Desktop/jar/felix-framework-2.0.3/bundle/org.apache.felix.upnp.sample.workflow-0.1.0-SNAPSHOT.jar
>> (org.osgi.framework.BundleException: Activator start error in bundle
>> org.apache.felix.upnp.sample.workflow [93].)
>> java.lang.NullPointerException: Specified service reference cannot be
>> null.
>>     at
>>
>> org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:320)
>>     at
>>
>> org.apache.felix.upnp.sample.workflow.Activator.doServiceRegistration(Activator.java:44)
>>     at
>> org.apache.felix.upnp.sample.workflow.Activator.start(Activator.java:54)
>>     at
>>
>> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:661)
>>     at org.apache.felix.framework.Felix.activateBundle(Felix.java:1756)
>>     at org.apache.felix.framework.Felix.startBundle(Felix.java:1678)
>>     at
>> org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1124)
>>     at
>> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
>>     at java.lang.Thread.run(Thread.java:619)
>>
>> ===============
>>
>> package org.apache.felix.upnp.sample.workflow;
>>
>> import java.util.Dictionary;
>>
>> import org.osgi.framework.BundleActivator;
>> import org.osgi.framework.BundleContext;
>> import org.osgi.framework.ServiceReference;
>> import org.apache.felix.upnp.sample.tv.*;
>>
>>
>> public class Activator implements BundleActivator {
>>
>>     static BundleContext context;
>>
>>     private ServiceReference tvref;
>>
>>
>>
>>     private void doServiceRegistration() {
>>
>>
>>                 tvref =
>> context.getServiceReference(TvDevice.class.getName());
>>                 TvDevice tvd = (TvDevice)context.getService(tvref);
>>                 tvd.setMessage("hello world!");
>>
>>     }
>>
>>     /**
>>      * @see
>> org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
>>      */
>>     public void start(BundleContext context) throws Exception {
>>         Activator.context = context;
>>         doServiceRegistration();
>>     }
>>
>>     /**
>>      * @see
>> org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
>>      */
>>     public void stop(BundleContext context) throws Exception {
>>
>>             context.ungetService(tvref);
>>     }
>> }
>>
>> ==================
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="
>> http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="
>> http://maven.apache.org/POM/4.0.0
>> http://maven.apache.org/maven-v4_0_0.xsd";>
>>   <parent>
>>     <artifactId>felix-parent</artifactId>
>>     <groupId>org.apache.felix</groupId>
>>     <version>1.2.0</version>
>>     <relativePath>../../../pom/pom.xml</relativePath>
>>   </parent>
>>   <modelVersion>4.0.0</modelVersion>
>>   <groupId>org.apache.felix</groupId>
>>   <artifactId>org.apache.felix.upnp.sample.workflow</artifactId>
>>   <packaging>bundle</packaging>
>>   <name>Apache Felix UPnP Sample workflow</name>
>>   <version>0.1.0-SNAPSHOT</version>
>>   <build>
>>     <plugins>
>>       <plugin>
>>         <groupId>org.apache.felix</groupId>
>>         <artifactId>maven-bundle-plugin</artifactId>
>>         <extensions>true</extensions>
>>         <configuration>
>>           <instructions>
>>             <Bundle-Name>${pom.name}</Bundle-Name>
>>             <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
>>             <Bundle-Author>  someone</Bundle-Author>
>>             <Bundle-Description>test workflow</Bundle-Description>
>>
>>
>> <Bundle-SymbolicName>org.apache.felix.upnp.sample.workflow</Bundle-SymbolicName>
>>
>>
>> <Bundle-Activator>org.apache.felix.upnp.sample.workflow.Activator</Bundle-Activator>
>>
>> <Private-Package>org.apache.felix.upnp.sample.workflow.*</Private-Package>
>>             <Import-Package>*</Import-Package>
>>           </instructions>
>>         </configuration>
>>       </plugin>
>>     </plugins>
>>   </build>
>>
>>   <dependencies>
>>     <dependency>
>>       <groupId>${pom.groupId}</groupId>
>>       <artifactId>org.osgi.core</artifactId>
>>       <version>1.0.1</version>
>>       <scope>provided</scope>
>>     </dependency>
>>     <dependency>
>>       <groupId>${pom.groupId}</groupId>
>>       <artifactId>org.osgi.compendium</artifactId>
>>       <version>1.0.0</version>
>>       <scope>provided</scope>
>>     </dependency>
>>     <dependency>
>>       <groupId>org.apache.felix</groupId>
>>       <artifactId>org.apache.felix.upnp.sample.tv</artifactId>
>>       <version>0.2.0-SNAPSHOT</version>
>>       <scope>provided</scope>
>>     </dependency>
>>   </dependencies>
>> </project>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
> For additional commands, e-mail: users-h...@felix.apache.org
>
>

Reply via email to