sensorweaver:developer-guide
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
sensorweaver:developer-guide [2014-12-23 10:48] – [Integration testing] luigi.fortunati | sensorweaver:developer-guide [2015-11-10 16:46] (current) – [Testing your app] luigi.fortunati | ||
---|---|---|---|
Line 5: | Line 5: | ||
General requirements: | General requirements: | ||
* Knowledge of Java, OSGi, Maven. | * Knowledge of Java, OSGi, Maven. | ||
- | * Java Development Kit 7 | + | * Java Development Kit 8 |
* An IDE, preferably with Maven support | * An IDE, preferably with Maven support | ||
* For testing/ | * For testing/ | ||
Line 14: | Line 14: | ||
==== Development environment setup ==== | ==== Development environment setup ==== | ||
- | You'll need Java 7 JDK to compile and run your project. [[http:// | + | You'll need Java 8 JDK to compile and run your project. [[http:// |
SensorWeaver components are distributed using Maven [[http:// | SensorWeaver components are distributed using Maven [[http:// | ||
Line 27: | Line 27: | ||
< | < | ||
< | < | ||
- | <id>default</id> | + | <id>wnlab</id> |
< | < | ||
< | < | ||
Line 61: | Line 61: | ||
</ | </ | ||
</ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
</ | </ | ||
Line 74: | Line 77: | ||
The project must generate an OSGi bundle, so: | The project must generate an OSGi bundle, so: | ||
*Set packaging type to //bundle// | *Set packaging type to //bundle// | ||
- | *Set Java 7 compiler with [[http:// | + | *Set Java compiler with [[http:// |
*Include the [[http:// | *Include the [[http:// | ||
Line 89: | Line 92: | ||
< | < | ||
< | < | ||
- | < | + | < |
- | < | + | < |
</ | </ | ||
</ | </ | ||
Line 120: | Line 123: | ||
< | < | ||
< | < | ||
- | < | + | < |
</ | </ | ||
</ | </ | ||
Line 131: | Line 134: | ||
There are several ways to achieve this. Here we list two solutions: | There are several ways to achieve this. Here we list two solutions: | ||
* Querying the service registry programmatically using // | * Querying the service registry programmatically using // | ||
- | * Blueprint | + | * Blueprint |
- | === Bundle Activator === | ||
- | |||
- | You'll need OSGi dependencies in your pom: | ||
- | <file xml pom.xml> | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | </ | ||
- | </ | ||
- | |||
- | Then create a java class for your bundle activator: | ||
- | <file java MySensorPublisherActivator.java> | ||
- | package it.cnr.isti.sample; | ||
- | |||
- | import it.cnr.isti.sensorweaver.middleware.api.Middleware; | ||
- | |||
- | import org.osgi.framework.BundleActivator; | ||
- | import org.osgi.framework.BundleContext; | ||
- | import org.osgi.framework.ServiceReference; | ||
- | |||
- | public class MySensorPublisherActivator implements BundleActivator { | ||
- | |||
- | private ServiceReference< | ||
- | private MySensorPublisher publisher; | ||
- | |||
- | public void start(BundleContext context) throws Exception { | ||
- | middlewareReference = context.getServiceReference(Middleware.class); | ||
- | Middleware middleware = context.getService(middlewareReference); | ||
- | // | ||
- | publisher = new MySensorPublisher(middleware); | ||
- | publisher.start(); | ||
- | } | ||
- | |||
- | public void stop(BundleContext context) throws Exception { | ||
- | publisher.stop(); | ||
- | context.ungetService(middlewareReference); | ||
- | } | ||
- | |||
- | } | ||
- | </ | ||
- | |||
- | Declare your bundle activator in your Manifest by configuring the //maven bundle plugin//: | ||
- | <file xml pom.xml> | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | </ | ||
- | </ | ||
- | </ | ||
- | </ | ||
=== Blueprint === | === Blueprint === | ||
Line 224: | Line 170: | ||
</ | </ | ||
- | Assuming that you're following Maven conventions on project structure, create | + | Assuming that you're following Maven conventions on project structure, create |
Create a '' | Create a '' | ||
Line 234: | Line 180: | ||
xsi: | xsi: | ||
http:// | http:// | ||
- | http:// | + | http:// |
- | default-activation=" | + | |
< | < | ||
Line 289: | Line 234: | ||
import it.cnr.isti.sensorweaver.middleware.api.datafeed.descriptor.DataFeedDescriptor; | import it.cnr.isti.sensorweaver.middleware.api.datafeed.descriptor.DataFeedDescriptor; | ||
import it.cnr.isti.sensorweaver.middleware.api.datafeed.descriptor.DataFeedBuilder; | import it.cnr.isti.sensorweaver.middleware.api.datafeed.descriptor.DataFeedBuilder; | ||
+ | import it.cnr.isti.sensorweaver.middleware.api.common.descriptor.Property; | ||
/** ... **/ | /** ... **/ | ||
Line 297: | Line 243: | ||
builder.property(" | builder.property(" | ||
builder.parameter(" | builder.parameter(" | ||
- | builder.parameter(" | + | return |
- | DataFeedDescriptor descriptor = builder.build(); | + | |
- | return descriptor; | + | |
} | } | ||
</ | </ | ||
Line 325: | Line 269: | ||
MessageBuilder messageBuilder = dataFeedClient.buildMessage(); | MessageBuilder messageBuilder = dataFeedClient.buildMessage(); | ||
messageBuilder.entry(" | messageBuilder.entry(" | ||
- | messageBuilder.entry(" | + | messageBuilder.timestamp(Calendar.getInstance().getTimeInMillis()); |
messageBuilder.send(); | messageBuilder.send(); | ||
} | } | ||
Line 331: | Line 275: | ||
In order to publish a message for a given //data feed// you must produce values for all of the message elements defined previously in the //data feed descriptor// | In order to publish a message for a given //data feed// you must produce values for all of the message elements defined previously in the //data feed descriptor// | ||
+ | |||
+ | The datafeed client includes a method // | ||
=== Unregistering a Data Feed === | === Unregistering a Data Feed === | ||
Line 404: | Line 350: | ||
Applications can be easily tested in the [[http:// | Applications can be easily tested in the [[http:// | ||
- | SensorWeaver provides a preconfigured {{: | + | You can download your preferred Apache Karaf release |
- | Alternatively you can download your preferred Apache Karaf release and use the '' | + | |
- | Configuration coming with both solutions assume | + | Deafult feature configuration assumes |
Please refer to the [[sensorweaver: | Please refer to the [[sensorweaver: |
sensorweaver/developer-guide.1419331703.txt.gz · Last modified: 2014-12-23 10:48 by luigi.fortunati