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 [2015-11-10 16:29] – [SensorWeaver Developer Guide] luigi.fortunatisensorweaver:developer-guide [2015-11-10 16:46] (current) – [Testing your app] luigi.fortunati
Line 77: 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 92: 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 123: 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 134: 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>org.osgi.core</artifactId> 
-   <version>4.3.1</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 237: 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 301: 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 329: 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 335: 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 408: Line 350:
 Applications can be easily tested in the [[http://karaf.apache.org/|Karaf]] OSGi environment, using provided logging and debugging tools. Applications can be easily tested in the [[http://karaf.apache.org/|Karaf]] OSGi environment, using provided logging and debugging tools.
  
-SensorWeaver provides a preconfigured {{:sensorweaver:sensorweaver-karaf-bundle.tar.gz|Apache Karaf Bundle}} that you can use for development purposes. +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.
-Alternatively you can download your preferred Apache Karaf release and use the ''middleware-dev'' feature from the [[http://ala.isti.cnr.it:8081/nexus/service/local/repositories/wnlab-releases/content/it/cnr/isti/sensorweaver/sensorweaver-features/2.0.0/sensorweaver-features-2.0.0-features.xml|SensorWeaver karaf feature repository]] to start up your container.+
  
-Configuration coming with both solutions assume that you have an MQTT broker online on port 1883 on your local machine.+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. Please refer to the [[sensorweaver:admin-guide|Administrator Guide]] in order to setup and configure your OSGI environment.
sensorweaver/developer-guide.1447172959.txt.gz · Last modified: 2015-11-10 16:29 by luigi.fortunati

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