User Tools

Site Tools


sensorweaver:developer-guide

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
sensorweaver:developer-guide [2014-12-23 10:38] – [API and usage] luigi.fortunatisensorweaver: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/deployment   * For testing/deployment
Line 14: Line 14:
 ==== Development environment setup ==== ==== Development environment setup ====
  
-You'll need Java JDK to compile and run your project. [[http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html|Download]] and install one for your system.+You'll need Java JDK to compile and run your project. [[http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html|Download]] and install one for your system.
  
 SensorWeaver components are distributed using Maven [[http://ala.isti.cnr.it:8081/nexus/index.html#welcome|WNLab repositories]].  SensorWeaver components are distributed using Maven [[http://ala.isti.cnr.it:8081/nexus/index.html#welcome|WNLab repositories]]. 
Line 27: Line 27:
 <profiles> <profiles>
    <profile>    <profile>
-      <id>default</id>+      <id>wnlab</id>
       <repositories>       <repositories>
          <!-- WNlab Repos -->          <!-- WNlab Repos -->
Line 61: Line 61:
    </profile>    </profile>
 </profiles> </profiles>
 +<activeProfiles>
 +   <activeProfile>wnlab</activeProfile>
 +</activeProfiles>
 </file> </file>
  
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 compiler with [[http://maven.apache.org/plugins/maven-compiler-plugin/|maven compiler plugin]]+  *Set Java compiler with [[http://maven.apache.org/plugins/maven-compiler-plugin/|maven compiler plugin]]
   *Include the [[http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html|maven bundle plugin]] in order to produce a jar bundle with OSGi manifest.   *Include the [[http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html|maven bundle plugin]] in order to produce a jar bundle with OSGi manifest.
  
Line 89: Line 92:
          <version>3.1</version>          <version>3.1</version>
          <configuration>          <configuration>
-            <source>1.7</source> +            <source>1.8</source> 
-            <target>1.7</target>+            <target>1.8</target>
          </configuration>          </configuration>
       </plugin>       </plugin>
Line 120: Line 123:
       <groupId>it.cnr.isti.sensorweaver.middleware</groupId>       <groupId>it.cnr.isti.sensorweaver.middleware</groupId>
       <artifactId>middleware-api</artifactId>       <artifactId>middleware-api</artifactId>
-      <version>2.0.0</version>+      <version>2.1.0</version>
    </dependency>    </dependency>
 </dependencies> </dependencies>
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 //BundleActivator//     * Querying the service registry programmatically using //BundleActivator//
-    * Blueprint+    * Blueprint (strongly recommended)
  
-=== Bundle Activator === 
- 
-You'll need OSGi dependencies in your pom: 
-<file xml pom.xml> 
-<dependency> 
-   <groupId>org.osgi</groupId> 
-   <artifactId>core</artifactId> 
-   <version>4.3.0</version> 
-</dependency> 
-</file> 
- 
-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<Middleware> middlewareReference; 
- private MySensorPublisher publisher; 
- 
- public void start(BundleContext context) throws Exception { 
- middlewareReference = context.getServiceReference(Middleware.class); 
- Middleware middleware = context.getService(middlewareReference); 
-                //Middleware instance can be passed to other components at this point   
- publisher = new MySensorPublisher(middleware); 
- publisher.start(); 
- } 
- 
- public void stop(BundleContext context) throws Exception { 
- publisher.stop(); 
- context.ungetService(middlewareReference); 
- } 
- 
-} 
-</file> 
- 
-Declare your bundle activator in your Manifest by configuring the //maven bundle plugin//: 
-<file xml pom.xml> 
-<plugin> 
-   <groupId>org.apache.felix</groupId> 
-   <artifactId>maven-bundle-plugin</artifactId> 
-   <version>2.3.7</version> 
-   <extensions>true</extensions> 
-   <configuration> 
-      <instructions> 
-         <!-- ... Other manifest headers ... --> 
-         <Bundle-Activator>it.cnr.isti.sample.MySensorPublisherActivator</Bundle-Activator> 
-      </instructions> 
-   </configuration> 
-</plugin> 
-</file> 
  
 === Blueprint === === Blueprint ===
Line 224: Line 170:
 </file> </file>
  
-Assuming that you're following Maven conventions on project structure, create folder under ''src/main/resources'': ''OSGI-INF/blueprint''.+Assuming that you're following Maven conventions on project structure, create the folder ''src/main/resources/OSGI-INF/blueprint''.
  
 Create a ''services.xml'' file inside of this folder with this content: Create a ''services.xml'' file inside of this folder with this content:
Line 234: Line 180:
  xsi:schemaLocation="  xsi:schemaLocation="
  http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd   http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd 
- http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd+ http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
- default-activation="lazy">+
  
  <reference id="middleware"  <reference id="middleware"
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("sensorType", "temperatureSensor");  builder.property("sensorType", "temperatureSensor");
  builder.parameter("temperature", new Property("Unit of Measure","Celsius"));  builder.parameter("temperature", new Property("Unit of Measure","Celsius"));
- builder.parameter("timestamp", new Property("Format","ISO8601")); + return builder.build();
- DataFeedDescriptor descriptor = builder.build()+
- return descriptor;+
 } }
 </code> </code>
Line 325: Line 269:
  MessageBuilder messageBuilder = dataFeedClient.buildMessage();  MessageBuilder messageBuilder = dataFeedClient.buildMessage();
  messageBuilder.entry("temperature", Integer.toString(datasource.getValue()));  messageBuilder.entry("temperature", Integer.toString(datasource.getValue()));
- messageBuilder.entry("timestamp", DateTime.now().toString());+ 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 //timestamp// for setting the timestamp of the message. If not used, the middleware will set the timestamp at the time of the invocation of the send method.
  
 === Unregistering a Data Feed === === Unregistering a Data Feed ===
Line 400: Line 346:
 The same unregistration mechanisms of ''DataFeedDiscoverer'' applies to ''DataFeedListener''. The same unregistration mechanisms of ''DataFeedDiscoverer'' applies to ''DataFeedListener''.
  
-==== Integration testing ====+==== Testing your app ==== 
 + 
 +Applications can be easily tested in the [[http://karaf.apache.org/|Karaf]] OSGi environment, using provided logging and debugging tools. 
 + 
 +You can download your preferred Apache Karaf release (latest version is strongly recommended) and install the ''middleware'' feature from the latest [[http://ala.isti.cnr.it:8081/nexus/index.html#nexus-search;quick~sensorweaver-features|SensorWeaver karaf feature repository]] to start up your container.
  
-Applications can be directly tested in Karaf OSGi environment using the middleware-dev feature. please refer to the administrator guide in order to setup the test environment.+Deafult feature configuration assumes that you have an MQTT broker online on port 1883 on your local machine.
  
 +Please refer to the [[sensorweaver:admin-guide|Administrator Guide]] in order to setup and configure your OSGI environment.
sensorweaver/developer-guide.1419331133.txt.gz · Last modified: 2014-12-23 10:38 by luigi.fortunati

Donate Powered by PHP Valid HTML5 Valid CSS Run on Debian Driven by DokuWiki