felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From don...@apache.org
Subject svn commit: r801450 - in /felix/sandbox/donsez/producerquery.demo: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/sandbox/ src/main/java/org/apache/felix/sand...
Date Wed, 05 Aug 2009 22:46:43 GMT
Author: donsez
Date: Wed Aug  5 22:46:42 2009
New Revision: 801450

URL: http://svn.apache.org/viewvc?rev=801450&view=rev
Log:
creation of a demo for the ProducerQueryService

Added:
    felix/sandbox/donsez/producerquery.demo/
    felix/sandbox/donsez/producerquery.demo/pom.xml   (with props)
    felix/sandbox/donsez/producerquery.demo/src/
    felix/sandbox/donsez/producerquery.demo/src/main/
    felix/sandbox/donsez/producerquery.demo/src/main/java/
    felix/sandbox/donsez/producerquery.demo/src/main/java/org/
    felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/
    felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/
    felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/
    felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/producerquery/
    felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/producerquery/demo/
    felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/producerquery/demo/impl/
    felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/producerquery/demo/impl/ProducerQueryServiceDemo.java
  (with props)
    felix/sandbox/donsez/producerquery.demo/src/main/resources/

Added: felix/sandbox/donsez/producerquery.demo/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery.demo/pom.xml?rev=801450&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery.demo/pom.xml (added)
+++ felix/sandbox/donsez/producerquery.demo/pom.xml Wed Aug  5 22:46:42 2009
@@ -0,0 +1,87 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+	<properties>
+		<description>demo for the Apache Felix Producer Query Service.</description>
+	</properties>  
+
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Apache Felix Producer Query Service Demo</name>
+  <artifactId>org.apache.felix.sandbox.producerquery.demo</artifactId>
+  <groupId>org.apache.felix.sandbox</groupId>
+  <version>0.1.0</version>
+  <description>${description}</description>
+
+  <dependencies>
+	<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.core</artifactId>
+	  		<version>1.0.0</version>
+	</dependency>
+
+	<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+	  		<version>1.0.0</version>
+	</dependency>
+
+	<dependency>
+		  <artifactId>org.apache.felix.sandbox.wireadminbinder</artifactId>
+		  <groupId>org.apache.felix.sandbox</groupId>
+		  <version>0.2.0</version>
+	</dependency>
+	
+	<dependency>
+		  <groupId>org.apache.felix.sandbox</groupId>
+		  <artifactId>org.apache.felix.sandbox.producerquery</artifactId>
+		  <version>0.1.0</version>
+	</dependency>
+	
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+
+            <Private-Package>
+            		org.apache.felix.sandbox.producerquery.demo.*
+            </Private-Package>
+
+			<Import-Service>org.apache.felix.sandbox.producerquery.ProducerQueryService</Import-Service>
+			<Export-Service>
+				org.osgi.service.wireadmin.Consumer
+			</Export-Service>
+
+
+			<!-- TODO migrate to iPOJO -->
+			<Service-Component>OSGI-INF/component.xml</Service-Component>
+			
+
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: felix/sandbox/donsez/producerquery.demo/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/producerquery/demo/impl/ProducerQueryServiceDemo.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/producerquery/demo/impl/ProducerQueryServiceDemo.java?rev=801450&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/producerquery/demo/impl/ProducerQueryServiceDemo.java
(added)
+++ felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/producerquery/demo/impl/ProducerQueryServiceDemo.java
Wed Aug  5 22:46:42 2009
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.producerquery.demo.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.wireadmin.Consumer;
+import org.osgi.service.wireadmin.Wire;
+import org.osgi.service.wireadmin.WireAdmin;
+import org.osgi.service.wireadmin.WireConstants;
+import org.osgi.util.measurement.Unit;
+
+import org.apache.felix.sandbox.wireadminbinder.WireSetManager;
+import org.apache.felix.sandbox.wireadminbinder.WireSet;
+import org.apache.felix.sandbox.producerquery.ProducerQuery;
+import org.apache.felix.sandbox.producerquery.ProducerQueryService;
+
+/**
+ * provides a demo for the Producer Query Service
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ProducerQueryServiceDemo implements Consumer {
+
+    private static final String pqsDemoConsumerPid="org.apache.felix.sandbox.ProducerQueryServiceDemo.consumer";
+    
+    // private Wire[] wires = null;
+
+    private ProducerQueryService producerQueryService;
+
+    private WireAdmin wireAdmin;
+
+    private WireSetManager wireSetManager;
+
+    private ServiceRegistration consumerSerReg;
+
+    private BundleContext bundleContext;
+
+
+    public void bindProducerQueryService(ProducerQueryService producerQueryService) {
+        this.producerQueryService = producerQueryService;
+    }
+
+    public void unbindProducerQueryService(ProducerQueryService producerQueryService) {
+        this.producerQueryService = null;
+    }
+
+    public void bindWireAdmin(WireAdmin wireAdmin) {
+        this.wireAdmin = wireAdmin;
+    }
+
+    public void unbindWireAdmin(WireAdmin wireAdmin){
+        this.wireAdmin = null;
+    }
+
+    public void activate(ComponentContext componentContext) {
+    	bundleContext=componentContext.getBundleContext();
+        // TODO could be parameterized in a configuration file
+        ProducerQuery producerQuery = new ProducerQuery(
+                new int[] { ProducerQuery.AVG }, // 
+                //"("+WireConstants.WIREADMIN_PRODUCER_FLAVORS + "=*" + Measurement.class.getName()
+ ")", // producerSelectionFilter,
+                "(&("+WireConstants.WIREADMIN_PRODUCER_FLAVORS + "=*" + Double.class.getName()
+ ")"
+                +"("+Unit.class.getName()+"=K))", // producerSelectionFilter,
+                null, // String groupByFilter,
+                10, // Integer.MAX_VALUE for never ending, // int numberOfTime,
+                10, // int numberOfSample,
+                2000, // int pollingPeriod,
+                null //String eventServiceFilter
+        );
+
+        // register a consumer
+        try {
+            String queryId = producerQueryService.createQuery(producerQuery);
+            Dictionary properties = new Hashtable();
+            properties.put(Constants.SERVICE_PID,pqsDemoConsumerPid);
+            properties.put(WireConstants.WIREADMIN_CONSUMER_FLAVORS, new Class[] { String.class
});
+            consumerSerReg = bundleContext.registerService(Consumer.class.getName(), this,
properties);
+
+            // create a wire between the consumer and the producer
+            WireSet wireSet = new WireSet();
+            wireSet.setId(queryId+"-->"+pqsDemoConsumerPid);
+            wireSet.setConsumersFilter("("+Constants.SERVICE_PID+"="+pqsDemoConsumerPid+")");
+            wireSet.setProducersFilter("("+Constants.SERVICE_PID+"="+queryId+")");
+            wireSet.setRemovepolicy(WireSet.REMOVE_POLICY_WHILECONSUMER);
+            //System.err.println(wireSet.toString());
+            wireSetManager=new WireSetManager(bundleContext, wireAdmin, wireSet);
+          
+        } catch (Exception e) {
+            e.printStackTrace();
+            deactivate(componentContext);
+        }
+
+    }
+
+    public void deactivate(ComponentContext componentContext) {
+        if(wireSetManager==null) wireSetManager.stop();
+        if(consumerSerReg!=null) consumerSerReg.unregister();
+    }
+
+    // Consumer section
+    public void updated(Wire wire, Object o) {
+        if (o instanceof String) {
+            System.out.println("ProducerQueryServiceDemo: updated object \""
+                    + (String) o + "\" on wire " + wire.toString());
+        } else {
+            System.out.println("ProducerQueryServiceDemo: updated object \""
+                    + o.toString() + "\" on wire " + wire.toString());
+        }
+
+    }
+
+    public void producersConnected(Wire[] wires) {
+        this.wires = wires;
+    }
+}
\ No newline at end of file

Propchange: felix/sandbox/donsez/producerquery.demo/src/main/java/org/apache/felix/sandbox/producerquery/demo/impl/ProducerQueryServiceDemo.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message