Hi Richard,
I am trying to do the way you mentioned last time: invoking another service
from one service by getting the reference, however, I got the following
errors after I deployed my bundle.
The service I invoked is from org.apache.felix.upnp.sample.tv
felix showed that before my errors happen, this service was already started.
Thanks a lot in advance.
-> [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)
The code I wrote it is:
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);
}
}
and the pom.xml I write is:
...
<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>
On Mon, Feb 22, 2010 at 4:40 AM, Richard S. Hall <[email protected]>wrote:
> On 2/22/10 7:35 PM, Leon668 wrote:
>
>> On Mon, Feb 22, 2010 at 4:21 AM, Richard S. Hall<[email protected]
>> >wrote:
>>
>>
>>
>>> On 2/22/10 5:21 PM, Mahammad Nasir wrote:
>>>
>>>
>>>
>>>> How can i call a method (in Activator class other than start,stop) in
>>>> container class of felix framework. Is service registration is the only
>>>> way??
>>>>
>>>>
>>>>
>>>>
>>> You can't even call the start()/stop() methods in the activator, only the
>>> framework can.
>>>
>>> If you want to interact with your bundle, then services are the only
>>> way...well, technically I guess you could use statics in its exported
>>> classes, but this probably isn't a good idea in general.
>>>
>>>
>>>
>> Sorry to interrupt. But can you elaborate this:
>>
>>
>>
>>> "If you want to interact with your bundle, then services are the only
>>>>
>>>>
>>> way."
>>
>> What is the service here mean?
>>
>>
>
> An OSGi service, published via BundleContext.registerService()...
>
>
> If I want to invoke a bundle inside the other bundle. Is that possible?
>>
>> What I am trying to build is a "bundle workflow", in which I'd try to
>> compose several bundle together and invoke them one by one.
>>
>>
>
> No, that is not possible. You would need to compose services provided by
> your bundles. You wouldn't want to compose bundles, because your composition
> would be tied to the specific implementations. Using services abstracts the
> implementation.
>
> -> richard
>
>
> Thanks.
>>
>> Leo.
>>
>>
>>
>>
>>> -> richard
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>>>
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>