You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by do...@apache.org on 2009/08/06 00:44:11 UTC
svn commit: r801448 - in /felix/sandbox/donsez/producerquery: ./ 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/sandbox/p...
Author: donsez
Date: Wed Aug 5 22:44:10 2009
New Revision: 801448
URL: http://svn.apache.org/viewvc?rev=801448&view=rev
Log:
creation of a project that provides a service to aggregate (aka query) several measurements streams for WireAdmin' producers.
Added:
felix/sandbox/donsez/producerquery/
felix/sandbox/donsez/producerquery/pom.xml (with props)
felix/sandbox/donsez/producerquery/src/
felix/sandbox/donsez/producerquery/src/main/
felix/sandbox/donsez/producerquery/src/main/java/
felix/sandbox/donsez/producerquery/src/main/java/org/
felix/sandbox/donsez/producerquery/src/main/java/org/apache/
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ConfigMBean.java (with props)
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQuery.java (with props)
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQueryService.java (with props)
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/Activator.java (with props)
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/HistoriesMap.java (with props)
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryImpl.java (with props)
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryServiceImpl.java (with props)
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/util/
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/util/config/
felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java (with props)
felix/sandbox/donsez/producerquery/src/main/resources/
felix/sandbox/donsez/producerquery/src/main/resources/initialstate.properties (with props)
felix/sandbox/donsez/producerquery/src/site/
felix/sandbox/donsez/producerquery/src/site/producerqueryservice.ppt (with props)
Added: felix/sandbox/donsez/producerquery/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/pom.xml?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/pom.xml (added)
+++ felix/sandbox/donsez/producerquery/pom.xml Wed Aug 5 22:44:10 2009
@@ -0,0 +1,85 @@
+<!--
+ 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>provides a service to aggregate (aka query) several measurements streams for WireAdmin'producers.</description>
+ </properties>
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>Apache Felix Producer Query Service</name>
+ <artifactId>org.apache.felix.sandbox.producerquery</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>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
+ <Export-Package>
+ org.apache.felix.sandbox.producerquery
+ </Export-Package>
+ <Private-Package>
+ org.apache.felix.sandbox.producerquery.impl, org.apache.felix.sandbox.util.*
+ </Private-Package>
+
+ <Bundle-Activator>org.apache.felix.sandbox.producerquery.impl.Activator</Bundle-Activator>
+
+ <Import-Service>org.osgi.service.wireadmin.WireAdmin</Import-Service>
+ <Export-Service>
+ org.apache.felix.sandbox.producerquery.ProducerQueryService,
+ org.osgi.service.wireadmin.Producer,
+ org.osgi.service.wireadmin.Consumer
+ </Export-Service>
+
+ <!-- TODO replace by CM metatype -->
+ <Config-Location>/initialstate.properties</Config-Location>
+
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: felix/sandbox/donsez/producerquery/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ConfigMBean.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ConfigMBean.java?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ConfigMBean.java (added)
+++ felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ConfigMBean.java Wed Aug 5 22:44:10 2009
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+/**
+ * The MBean interface provides a service for configuring the instance with a JMX bundle
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface ConfigMBean {
+
+ /**
+ * set the OW bus polling interval
+ */
+ public void setPollInterval(int interval);
+
+ /**
+ * get the current interval for the OW bus polling
+ */
+ public int getPollInterval();
+
+
+
+ /**
+ * set the trace
+ */
+ public void setTrace(boolean trace);
+
+ /**
+ * get the current trace
+ */
+ public boolean isTrace();
+
+ /**
+ * reset the configuration
+ */
+ public void reset();
+}
+
Propchange: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ConfigMBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQuery.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQuery.java?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQuery.java (added)
+++ felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQuery.java Wed Aug 5 22:44:10 2009
@@ -0,0 +1,154 @@
+/*
+ * 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;
+
+/**
+ * This class describes a query to be executed by a ProducerQueryService
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ProducerQuery {
+
+ /**
+ * Count on the window
+ */
+ public final static int COUNT=0;
+
+ /**
+ * Sliding Sum on the window
+ */
+ public final static int SUM=1;
+
+ /**
+ * Sliding Square Sum on the window
+ */
+ public final static int SQRSUM=2;
+
+ /**
+ * Sliding Average on the window
+ */
+ public final static int AVG=3;
+
+
+ /**
+ * Minimum value on the window
+ */
+ public final static int MIN=4;
+
+
+ /**
+ * Maximum value on the window
+ */
+ public final static int MAX=5;
+
+ /**
+ * aggregation functions
+ * <p>must contain at least one entry
+ */
+ private int[] agregateFunctions;
+
+ /**
+ * filter to select Producer
+ * <p>if null, agregate all available Producers
+ */
+ private String producerSelectionFilter;
+
+ /**
+ * filter to partition the agregate
+ * <p>if null, agregate all available Producers selected with producerSelectionFilter
+ */
+ private String groupByFilter;
+ /**
+ * number of times to produce an agregate value
+ * <p>must be strictly positive
+ * <p>java.lang.Integer.MAX_VALUE could be used for never-ending query
+ */
+ private int numberOfTime;
+
+ /**
+ * number of samples used to compute an agregate value
+ * <p>must be strictly positive
+ */
+ private int numberOfSample;
+
+ /**
+ * polling period (in millisecond) used for get values from selected Producers
+ * <p>must be strictly positive
+ */
+ private int pollingPeriod;
+
+ /**
+ * service.pid of the Event that start the computation of the query for one time.
+ * <p>if null, the computation is done every numberOfSample*pollingPeriod
+ * <p>if not null, the computation occurs numberOfSample*pollingPeriod milliseconds after the event
+ */
+ private String eventServiceFilter;
+
+ /**
+ *
+ */
+ public ProducerQuery(
+ int[] agregateFunctions,
+ String producerSelectionFilter,
+ String groupByFilter,
+ int numberOfTime,
+ int numberOfSample,
+ int pollingPeriod,
+ String eventServiceFilter
+ ) {
+ this.agregateFunctions=agregateFunctions;
+
+ this.producerSelectionFilter=(producerSelectionFilter==null)?"()":producerSelectionFilter;
+ this.groupByFilter=groupByFilter;
+ this.numberOfTime=numberOfTime;
+ this.numberOfSample=numberOfSample;
+ this.pollingPeriod=pollingPeriod;
+ this.eventServiceFilter=eventServiceFilter;
+ if(!isValid()) throw new IllegalArgumentException();
+ }
+
+ public boolean isValid(){
+ return agregateFunctions!=null
+ && agregateFunctions.length>0
+ && groupByFilter==null // since not implemented
+ && numberOfTime>0
+ && numberOfSample>0
+ && pollingPeriod>0
+ ;
+ }
+
+ public int[] getAgregateFunctions() {
+ return agregateFunctions;
+ }
+ public String getEventServiceFilter() {
+ return eventServiceFilter;
+ }
+ public int getNumberOfSample() {
+ return numberOfSample;
+ }
+ public int getNumberOfTime() {
+ return numberOfTime;
+ }
+ public int getPollingPeriod() {
+ return pollingPeriod;
+ }
+ public String getProducerSelectionFilter() {
+ return producerSelectionFilter;
+ }
+}
Propchange: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQuery.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQueryService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQueryService.java?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQueryService.java (added)
+++ felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQueryService.java Wed Aug 5 22:44:10 2009
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * This interface provides a service for create queries on Producers
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface ProducerQueryService {
+
+ /**
+ * create a query on producers
+ * <p>The returned value is the service.pid of the org.osgi.service.wireadmin.Producer associated to the query.
+ * <p>The "returned" producer starts the execution of the query when the wire is connected.
+ * @param producerQuery the query to execute
+ * @return the service.pid of the org.osgi.service.wireadmin.Producer associated to the query
+ * @throws Exception if the creation fails
+ */
+ public String createQuery(ProducerQuery producerQuery) throws Exception;
+
+ /**
+ *
+ * @param producerServicePid the service.pid of the org.osgi.service.wireadmin.Producer associated to the query
+ * @return true if the removal is successful, else false (the query could be already completed, ...).
+ */
+ public boolean remoteQuery(String producerServicePid);
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/ProducerQueryService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/Activator.java?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/Activator.java (added)
+++ felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/Activator.java Wed Aug 5 22:44:10 2009
@@ -0,0 +1,136 @@
+/*
+ * 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.impl;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.apache.felix.sandbox.producerquery.ProducerQueryService;
+import org.apache.felix.sandbox.util.config.Configuration;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+
+/**
+ * This activator read configuration properties from a file
+ * and initialize a GPSReader service with these properties
+ * and register it
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Activator implements BundleActivator {
+
+ private static final String CONFIGFILE = "/config.properties";
+
+ protected BundleContext bundleContext = null;
+ protected ServiceRegistration producerQueryServiceReg= null;
+ protected ProducerQueryServiceImpl producerQueryService= null;
+
+ private PrintStream traceout;
+
+ /**
+ * Called upon starting of the bundle. This method invokes initialize() which
+ * load the configuration file, creates the dependency managers and registers the
+ * eventual services.
+ *
+ * @param bundleContext The bundle bundleContext passed by the framework
+ * @exception Exception
+ */
+ public void start(BundleContext context) throws Exception {
+ this.bundleContext = context;
+ initialize();
+ }
+
+ /**
+ * Load the configuration properties and register e new service
+ */
+ private void initialize() throws Exception {
+
+ if (bundleContext == null)
+ return;
+
+ // Get the Config-Location value from the manifest
+
+ String configLocation = null;
+ Dictionary dict = bundleContext.getBundle().getHeaders();
+ Enumeration enume = dict.keys();
+ while (enume.hasMoreElements()) {
+ Object nextKey = enume.nextElement();
+ Object nextElem = dict.get(nextKey);
+ if (nextKey.equals("Config-Location")) {
+ configLocation = nextElem.toString();
+ break;
+ }
+ }
+ if (configLocation == null) {
+ configLocation = CONFIGFILE;
+ }
+
+ // Load properties from configLocation file
+ InputStream is = getClass().getResourceAsStream(configLocation);
+ Properties props = Configuration.loadProperties(is);
+
+ String ptraceout = props.getProperty("traceout");
+ PrintStream traceout = null;
+ if (ptraceout != null) {
+ if (ptraceout.equals("System.out")) {
+ traceout = System.out;
+ } else if (ptraceout.equals("System.err")) {
+ traceout = System.err;
+ } else {
+ // TODO instanciante the class with the name
+ System.err.println("custom trace is not implemented !");
+ }
+ } else {
+ traceout = null;
+ }
+
+ producerQueryService=new ProducerQueryServiceImpl(bundleContext);
+ producerQueryServiceReg=bundleContext.registerService(ProducerQueryService.class.getName(),producerQueryService,null);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ producerQueryService.stop();
+ producerQueryServiceReg.unregister();
+ }
+ /**
+ * print a trace
+ * @param message message to trace
+ */
+ private void traceln(String message) {
+ if (traceout != null) {
+ trace(message);
+ trace("\n");
+ }
+ }
+
+ /**
+ * print a trace
+ * @param message message to trace
+ */
+ private void trace(String message) {
+ if (traceout != null) {
+ traceout.print(message);
+ }
+ }
+}
Propchange: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/Activator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/HistoriesMap.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/HistoriesMap.java?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/HistoriesMap.java (added)
+++ felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/HistoriesMap.java Wed Aug 5 22:44:10 2009
@@ -0,0 +1,85 @@
+/*
+ * 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.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.osgi.service.wireadmin.Wire;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class HistoriesMap {
+
+ Map histories;
+ int maxSize;
+ /**
+ *
+ */
+ public HistoriesMap(int maxSize) {
+ this.maxSize=maxSize;
+ histories=new HashMap();
+ }
+
+ public void setMaxSize(int maxSize){
+ if(this.maxSize>maxSize) {
+ // delete the tail of the histories'lists
+ Iterator iter=histories.entrySet().iterator();
+ while(iter.hasNext()){
+ LinkedList list=(LinkedList)iter.next();
+ while(list.size()>maxSize){
+ list.removeLast();
+ }
+ }
+ }
+ this.maxSize=maxSize;
+ }
+
+ public void add(Wire wire, Object object){
+ LinkedList list=(LinkedList)histories.get(wire);
+ if(list==null) {
+ list=new LinkedList();
+ histories.put(wire,list);
+ }
+ list.addFirst(object);
+ while(list.size()>maxSize){
+ list.removeLast();
+ }
+ }
+
+ public List getHistory(Wire wire){
+ return (List)histories.get(wire);
+ }
+
+ public void remove(Wire wire){
+ histories.remove(wire);
+ }
+
+ public Iterator wires(){
+ return histories.keySet().iterator();
+ }
+
+ public Iterator histories(){
+ return histories.values().iterator();
+ }
+}
Propchange: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/HistoriesMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryImpl.java?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryImpl.java (added)
+++ felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryImpl.java Wed Aug 5 22:44:10 2009
@@ -0,0 +1,430 @@
+/*
+ * 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.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.felix.sandbox.producerquery.ProducerQuery;
+import org.apache.felix.sandbox.wireadminbinder.Property;
+import org.apache.felix.sandbox.wireadminbinder.WireSet;
+import org.apache.felix.sandbox.wireadminbinder.WireSetManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.wireadmin.Consumer;
+import org.osgi.service.wireadmin.Producer;
+import org.osgi.service.wireadmin.Wire;
+import org.osgi.service.wireadmin.WireAdmin;
+import org.osgi.service.wireadmin.WireConstants;
+import org.osgi.util.measurement.Measurement;
+import org.osgi.util.measurement.Unit;
+
+/**
+ * This implementation of ProducerQueryService supports only Double flavors since Measurement is not Comparable
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+class ProducerQueryImpl {
+
+ /*
+ * private static Class[] consumerSupportedFlavors = new Class[] {
+ * Position.class, Measurement.class, Long.class, Integer.class,
+ * Double.class, Float.class, State.class, Date.class, String.class };
+ */
+
+ /**
+ * only Double
+ */
+ private static Class[] consumerSupportedFlavors = new Class[] { Double.class };
+
+ /**
+ * only Double
+ */
+ private static Class[] producerSupportedFlavors = new Class[] {
+ Double.class, String.class };
+
+ private BundleContext bundleContext;
+
+ private WireAdmin wireAdmin;
+
+ private ProducerQuery producerQuery;
+
+ private String queryProducerServicePid;
+
+ private String fullProducerSelectionFilter;
+
+ private String eventFilter;
+
+ private ServiceRegistration myProducerReg;
+
+ private MyProducer myProducer;
+
+ private ServiceRegistration myConsumerReg;
+
+ private MyConsumer myConsumer;
+
+ private WireSetManager wireSetManager;
+
+ private HistoriesMap historiesMap;
+
+ ProducerQueryImpl(BundleContext bundleContext, WireAdmin wireAdmin,
+ ProducerQuery producerQuery, String queryProducerServicePid)
+ throws SecurityException, IllegalArgumentException,
+ ClassNotFoundException, NoSuchMethodException,
+ InstantiationException, IllegalAccessException,
+ InvocationTargetException, BundleException, InvalidSyntaxException {
+ this.bundleContext = bundleContext;
+ this.wireAdmin = wireAdmin;
+ this.producerQuery = producerQuery;
+ this.queryProducerServicePid = queryProducerServicePid;
+ this.historiesMap = new HistoriesMap(producerQuery.getNumberOfSample());
+
+ // register my consumer
+ Dictionary properties;
+ myConsumer = new MyConsumer(this, producerQuery.getPollingPeriod());
+ properties = new Hashtable();
+ properties
+ .put(
+ org.osgi.service.wireadmin.WireConstants.WIREADMIN_CONSUMER_FLAVORS,
+ consumerSupportedFlavors);
+ properties.put(org.osgi.framework.Constants.SERVICE_PID,
+ queryProducerServicePid + ".consumer");
+ properties.put(org.osgi.framework.Constants.SERVICE_DESCRIPTION,
+ "a consumer associated with a ProducerQuery");
+ myConsumerReg = bundleContext.registerService(Consumer.class.getName(),
+ myConsumer, properties);
+
+ // register my producer
+ myProducer = new MyProducer(this, producerQuery.getPollingPeriod()
+ * producerQuery.getNumberOfSample());
+ properties = new Hashtable();
+ properties
+ .put(
+ org.osgi.service.wireadmin.WireConstants.WIREADMIN_PRODUCER_FLAVORS,
+ producerSupportedFlavors);
+ properties.put(org.osgi.framework.Constants.SERVICE_PID,
+ queryProducerServicePid + ".producer");
+ properties.put(org.osgi.framework.Constants.SERVICE_DESCRIPTION,
+ "a producer associated with a ProducerQuery");
+ myProducerReg = bundleContext.registerService(Producer.class.getName(),
+ myProducer, properties);
+
+ // use a WAB wireset to listen Producers and to wire them to my consumer
+ WireSet wireSet = new WireSet();
+ wireSet
+ .setRemovepolicy(WireSet.REMOVE_POLICY_WHILEPRODUCER);
+ wireSet.setConsumersFilter("(" + Constants.SERVICE_PID + "="
+ + queryProducerServicePid + ".consumer)");
+ wireSet.setProducersFilter("(&(!(" + Constants.SERVICE_PID
+ + "=" + queryProducerServicePid + ".producer))"
+ + producerQuery.getProducerSelectionFilter() + ")");
+ Property propertyMetadata = new Property();
+ propertyMetadata.setName(WireConstants.WIREADMIN_FILTER);
+ propertyMetadata.setValue("(" + WireConstants.WIREVALUE_ELAPSED + ">="
+ + producerQuery.getPollingPeriod() + ")");
+ propertyMetadata.setType(String.class.getName());
+ wireSet.addProperty(propertyMetadata);
+ wireSetManager = new WireSetManager(bundleContext, wireAdmin, wireSet);
+ }
+
+ void stop() {
+ wireSetManager.stop();
+
+ if (myProducerReg != null)
+ myProducerReg.unregister();
+ myProducer.end();
+ if (myConsumerReg != null)
+ myConsumerReg.unregister();
+ myConsumer.end();
+
+ wireAdmin = null;
+ bundleContext = null;
+ }
+
+ public class MyProducer implements Producer, Runnable {
+
+ private ProducerQueryImpl producerQueryImpl;
+
+ private Wire wiresWithConsumers[];
+
+ private ServiceRegistration servreg;
+
+ private int pollInterval;
+
+ private boolean quit;
+
+ public MyProducer(ProducerQueryImpl producerQueryImpl, int pollInterval) {
+ this.producerQueryImpl = producerQueryImpl;
+ this.pollInterval = pollInterval;
+ quit = false;
+ new Thread(this).start();
+ }
+
+ public void run() {
+ if(consumerSupportedFlavors[0].isAssignableFrom(Double.class)){
+ runDouble();
+ } else if(consumerSupportedFlavors[0].isAssignableFrom(Measurement.class)){
+ runMeasurement();
+ }
+ }
+
+
+ synchronized void runMeasurement() {
+ int numberOfTime=0;
+ while (!quit && numberOfTime<producerQuery.getNumberOfTime()){
+ trace(this.getClass().getName()+":loop # "+ (numberOfTime)+" (every "+ pollInterval + " msec)");
+ try {
+ Thread.sleep(pollInterval);
+ } catch (InterruptedException ie) {
+ /* will recheck quit */
+ }
+ Measurement measurement = producerQueryImpl.computeMeasurementAverage();
+ for (int i = 0; wiresWithConsumers != null
+ && i < wiresWithConsumers.length; i++) {
+ Wire wire=wiresWithConsumers[i];
+ // check if wire is valid and connected ?
+ if (!wire.isConnected() || !wire.isValid())
+ continue;
+ Object obj=polled(wire,measurement);
+ // TODO : check if spec allows to update null objects ?
+ if(obj!=null) wire.update(obj);
+ }
+ }
+ }
+
+ synchronized void runDouble() {
+ int numberOfTime=0;
+ while (!quit && numberOfTime<producerQuery.getNumberOfTime()){
+ trace(this.getClass().getName()+":loop # "+ (numberOfTime)+" (every "+ pollInterval + " msec)");
+ try {
+ Thread.sleep(pollInterval);
+ } catch (InterruptedException ie) {
+ /* will recheck quit */
+ }
+ Double value = producerQueryImpl.computeDoubleAverage();
+ if(value==null) continue;
+ for (int i = 0; wiresWithConsumers != null
+ && i < wiresWithConsumers.length; i++) {
+ Wire wire=wiresWithConsumers[i];
+ // check if wire is valid and connected ?
+ if (!wire.isConnected() || !wire.isValid())
+ continue;
+ Object obj=polled(wire,value);
+ // TODO : check if spec allows to update null objects ?
+ if(obj!=null) wire.update(obj);
+ }
+ numberOfTime++;
+ }
+ }
+
+ public synchronized void consumersConnected(Wire wires[]) {
+ this.wiresWithConsumers = wires;
+ }
+
+ /**
+ * compute a new agregate
+ */
+ private Object polled(Wire wire, Double value) {
+ Class clazzes[] = wire.getFlavors();
+ for (int i = 0; i < clazzes.length; i++) {
+ Class clazz = clazzes[i];
+ if (clazz.isAssignableFrom(Double.class))
+ return value;
+ else if (clazz.isAssignableFrom(String.class))
+ return value.toString();
+ }
+ return null;
+ }
+
+ /**
+ * compute a new agregate
+ */
+ private Object polled(Wire wire, Measurement measurement) {
+ Class clazzes[] = wire.getFlavors();
+ for (int i = 0; i < clazzes.length; i++) {
+ Class clazz = clazzes[i];
+ if (clazz.isAssignableFrom(Measurement.class))
+ return measurement;
+ else if (clazz.isAssignableFrom(String.class))
+ return measurement.toString();
+ }
+ return null;
+ }
+
+ /**
+ * compute a new agregate
+ */
+ int numberOfTime=0;
+ public Object polled(Wire wire) {
+ trace(this.getClass().getName()+":polled "+ (++numberOfTime));
+// return polled(wire,producerQueryImpl.computeMeasurementAverage());
+ return polled(wire,producerQueryImpl.computeDoubleAverage());
+ }
+
+ public void end() {
+ this.quit = true;
+ }
+ }
+
+ public class MyConsumer implements Consumer, Runnable {
+
+ private ProducerQueryImpl producerQueryImpl;
+
+ private int pollPeriod;
+
+ private boolean quit = false;
+
+ private Thread thread;
+
+ private Wire[] wiresWithProducers = null;
+
+ public MyConsumer(ProducerQueryImpl producerQueryImpl, int pollPeriod) {
+ this.producerQueryImpl = producerQueryImpl;
+ this.pollPeriod = pollPeriod;
+ // thread = new Thread(this);
+ // thread.setName(producerQueryImpl.queryProducerServicePid+".consumerThread");
+ // thread.start();
+ }
+
+ int numberOfTime=0;
+ public void updated(Wire wire, Object o) {
+ trace(this.getClass().getName()+":update "+ (++numberOfTime));
+ // TODO if (o instanceof Measurement) {
+ if (o instanceof Double) {
+ synchronized (producerQueryImpl.historiesMap) {
+ producerQueryImpl.historiesMap.add(wire, o);
+ }
+ } else {
+ System.err.println("MyConsumer: unsupported object \""
+ + o.toString() + "\" on wire " + wire.toString());
+ }
+ }
+
+ public void producersConnected(Wire[] wires) {
+ this.wiresWithProducers = wires;
+ }
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ int numberOfTime=0;
+ while (!quit) {
+ trace(this.getClass().getName()+":loop "+ (++numberOfTime));
+ try {
+ Thread.sleep(pollPeriod);
+ } catch (InterruptedException ie) {
+ /* will recheck quit */
+ }
+ for (int i = 0; wiresWithProducers != null
+ && i < wiresWithProducers.length; i++) {
+ if (wiresWithProducers[i].isValid()
+ && wiresWithProducers[i].isConnected()) {
+ Object o = wiresWithProducers[i].poll();
+
+ trace(this.getClass().getName()+":Polled object on wire#"
+ + i
+ + ":"
+ + ((o != null) ? o : "Null"));
+ }
+ }
+ }
+ }
+
+ public void end() {
+ //this.quit = true;
+ //thread=null;
+ }
+ }
+
+ /**
+ * @return
+ */
+ public Measurement computeMeasurementAverage() {
+ double sumh = 0.0;
+ int counth = 0;
+ Unit unit = null;
+ synchronized (historiesMap) {
+ Iterator iter = historiesMap.histories();
+ for (; iter.hasNext(); counth++) {
+ List history = (List) iter.next();
+ Iterator l = history.iterator();
+ double sum = 0.0;
+ int count = 0;
+ for (; l.hasNext(); count++) {
+ Measurement measurement = (Measurement) l.next();
+ if (unit == null) {
+ unit = measurement.getUnit();
+ } else {
+ if (!unit.equals(measurement.getUnit()))
+ throw new ArithmeticException(
+ "try to sum measurement with different units");
+ }
+ sum += measurement.getValue();
+ }
+ if (count != 0)
+ sumh += (sum / count);
+ }
+ }
+
+ if (counth != 0)
+ return new Measurement(sumh / counth, 0.0, unit);
+ else
+ return null;
+ }
+
+ /**
+ * @return
+ */
+ public Double computeDoubleAverage() {
+ double sumh = 0.0;
+ int counth = 0;
+ Unit unit = null;
+ synchronized (historiesMap) {
+ Iterator iter = historiesMap.histories();
+ for (; iter.hasNext(); counth++) {
+ List history = (List)iter.next();
+ Iterator l = history.iterator();
+ double sum = 0.0;
+ int count = 0;
+ for (; l.hasNext(); count++) {
+ Double value = (Double) l.next();
+ sum += value.doubleValue();
+ }
+ if (count != 0)
+ sumh += (sum / count);
+ }
+ }
+
+ if (counth != 0)
+ return new Double(sumh / counth);
+ else
+ return null;
+ }
+
+ static void trace(String msg){
+ if(true) System.err.println(msg);
+ }
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryServiceImpl.java?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryServiceImpl.java (added)
+++ felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryServiceImpl.java Wed Aug 5 22:44:10 2009
@@ -0,0 +1,120 @@
+/*
+ * 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.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.felix.sandbox.producerquery.ProducerQuery;
+import org.apache.felix.sandbox.producerquery.ProducerQueryService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.wireadmin.WireAdmin;
+
+
+/**
+ * This class provides an implementation of the ProducerQueryService
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ProducerQueryServiceImpl implements ProducerQueryService, ServiceListener {
+
+ private BundleContext bundleContext;
+ private ServiceReference wireAdminServiceReference;
+ private WireAdmin wireAdmin;
+
+ private Map producerQueries;
+ private static long counter=0;
+
+ ProducerQueryServiceImpl(BundleContext bundleContext) throws BundleException{
+ this.bundleContext=bundleContext;
+
+ // find the WireAdmin service
+ ServiceReference wireAdminServiceReference=bundleContext.getServiceReference(WireAdmin.class.getName());
+ if(wireAdminServiceReference==null){
+ throw new BundleException("No WireAdmin service available");
+ }
+ wireAdmin = (WireAdmin)bundleContext.getService(wireAdminServiceReference);
+ if(wireAdmin==null){
+ throw new BundleException("No WireAdmin service available");
+ }
+ bundleContext.addServiceListener(this);
+
+ this.producerQueries=new HashMap();
+ }
+
+ public void serviceChanged(ServiceEvent e) {
+ ServiceReference serviceReference = e.getServiceReference();
+ if(e.getType()==ServiceEvent.UNREGISTERING && serviceReference.equals(wireAdminServiceReference)){
+ stop();
+ }
+ }
+
+ void stop(){
+ bundleContext.removeServiceListener(this);
+
+ Iterator iter=producerQueries.entrySet().iterator();
+ while(iter.hasNext()){
+ ((ProducerQueryImpl)iter.next()).stop();
+ }
+ bundleContext.ungetService(wireAdminServiceReference);
+ wireAdmin=null;
+ bundleContext=null;
+ }
+
+
+ private static String getNewQueryProducerServicePid(){
+ counter++;
+ return "org.apache.felix.sandbox.producerquery.query#"+counter;
+ }
+
+ /**
+ * create a query on producers
+ * <p>The returned value is the service.pid of the org.osgi.service.wireadmin.Producer associated to the query.
+ * <p>The "returned" producer starts the execution of the query when the wire is connected.
+ * @param producerQuery the query to execute
+ * @return the service.pid of the org.osgi.service.wireadmin.Producer associated to the query
+ */
+ public String createQuery(ProducerQuery producerQuery) throws Exception {
+ // check if the producerQuery is valid
+ // create a ProducerQueryImpl
+ String queryProducerServicePid=getNewQueryProducerServicePid();
+ ProducerQueryImpl producerQueryImpl=new ProducerQueryImpl(bundleContext,wireAdmin,producerQuery,queryProducerServicePid);
+ producerQueries.put(queryProducerServicePid+".producer",producerQuery);
+ return queryProducerServicePid+".producer";
+ }
+
+ /**
+ *
+ * @param producerServicePid the service.pid of the org.osgi.service.wireadmin.Producer associated to the query
+ * @return true if the
+ */
+ public boolean remoteQuery(String producerServicePid){
+ ProducerQueryImpl producerQueryImpl=(ProducerQueryImpl)producerQueries.remove(producerServicePid);
+ producerQueryImpl.stop();
+ if(producerQueryImpl!=null){
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/producerquery/impl/ProducerQueryServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java (added)
+++ felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java Wed Aug 5 22:44:10 2009
@@ -0,0 +1,203 @@
+/*
+ * 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.util.config;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * configuration utility
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Configuration {
+ static String DEFAULT_PROPERTIES_FILE = "config.properties";
+
+ /**
+ * loads properties from a file
+ *
+ *@param filename the properties file name
+ *@return the properties
+ */
+ public static Properties loadProperties(String filename) {
+ if (filename == null) {
+ filename =
+ System.getProperty(
+ "org.apache.felix.sandbox.util.config.file",
+ DEFAULT_PROPERTIES_FILE);
+ }
+ try {
+ return loadProperties(new FileInputStream(filename));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * loads properties from a input stream
+ *
+ *@param in the imput stream
+ *@return the properties
+ */
+ public static Properties loadProperties(InputStream in) {
+ Properties prop = new Properties();
+ try {
+ prop.load(in);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ return null;
+ }
+ return prop;
+ }
+
+ /**
+ * builds a map from properties. the key list is in the property keyListPropertyName
+ * <br>Example getMap(props,"keylist") returns a hashtable with 3 key-value entry
+ * <pre>
+ * keylist=bar;bubba;foo
+ * bar=BAR
+ * foo=1.5;float
+ * bubba=100;int
+ * </pre>
+ *
+ *@param props the properties
+ *@param keyListPropertyName the property name of the key list (separed by ;)
+ *@return The map
+ */
+ public static Map getMap(Properties props, String keyListPropertyName) {
+ return getHashtable(props, keyListPropertyName);
+ }
+
+ /**
+ * builds a hashtable from properties. the key list is in the property keyListPropertyName
+ * <br>Example getHashtable(props,"keylist") returns a hashtable with 3 key-value entry
+ * <pre>
+ * keylist=bar;bubba;foo
+ * bar=BAR
+ * foo=1.5;float
+ * bubba=100;int
+ * </pre>
+ *
+ *@param props the properties
+ *@param keyListPropertyName the property name of the key list (separed by ;)
+ *@return The hashtable
+ */
+ public static Hashtable getHashtable(
+ Properties props,
+ String keyListPropertyName) {
+
+ StringTokenizer st =
+ new StringTokenizer(props.getProperty(keyListPropertyName), ";");
+ Hashtable map = new Hashtable();
+
+ while (st.hasMoreTokens()) {
+ String key = st.nextToken();
+ StringTokenizer stvaluetype =
+ new StringTokenizer(props.getProperty(key), ";");
+ Object obj = null;
+ if (stvaluetype.hasMoreTokens()) {
+ String value = stvaluetype.nextToken();
+ if (stvaluetype.hasMoreTokens()) {
+ String type = stvaluetype.nextToken();
+ if (type.equals("int")) {
+ obj = new Integer(value);
+ } else if (type.equals("long")) {
+ obj = new Long(value);
+ } else if (type.equals("float")) {
+ obj = new Float(value);
+ } else if (type.equals("double")) {
+ obj = new Double(value);
+ } else if (type.equals("string")) {
+ obj = value;
+ } else {
+ // default : string
+ obj = value;
+ }
+ } else {
+ // no type means String
+ obj = value;
+ }
+
+ }
+ map.put(key, obj);
+ }
+ return map;
+ }
+
+ /**
+ * builds a (ordered) vector from properties. the index list is in the property keyListPropertyName
+ * <br>Example getVector(props,"tab") returns a 4 elements vector (tab.5 is ignored since tab.4 does not exist)
+ * <pre>
+ * tab.0=bar
+ * tab.1=foo
+ * tab.2=1.5;float
+ * tab.3=100;int
+ * tab.5=10000;long
+ * </pre>
+ *@param props the properties
+ *@param vectorPropertyName the property name of the key list (separed by ;)
+ *@return The vector
+ */
+ public static Vector getVector(
+ Properties props,
+ String vectorPropertyName) {
+
+ Vector vect = new Vector();
+
+ for (int i = 0; true; i++) {
+ String valuetype = props.getProperty(vectorPropertyName) + "." + i;
+ if (valuetype == null)
+ break;
+ StringTokenizer stvaluetype = new StringTokenizer(valuetype, ";");
+ Object obj = null;
+ if (stvaluetype.hasMoreTokens()) {
+ String value = stvaluetype.nextToken();
+ if (stvaluetype.hasMoreTokens()) {
+ String type = stvaluetype.nextToken();
+ if (type.equals("int")) {
+ obj = new Integer(value);
+ } else if (type.equals("long")) {
+ obj = new Long(value);
+ } else if (type.equals("float")) {
+ obj = new Float(value);
+ } else if (type.equals("double")) {
+ obj = new Double(value);
+ } else if (type.equals("string")) {
+ obj = value;
+ } else {
+ // default : string
+ obj = value;
+ }
+ } else {
+ // no type means String
+ obj = value;
+ }
+
+ }
+ vect.addElement(obj);
+ }
+ return vect;
+ }
+}
Propchange: felix/sandbox/donsez/producerquery/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/main/resources/initialstate.properties
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/main/resources/initialstate.properties?rev=801448&view=auto
==============================================================================
--- felix/sandbox/donsez/producerquery/src/main/resources/initialstate.properties (added)
+++ felix/sandbox/donsez/producerquery/src/main/resources/initialstate.properties Wed Aug 5 22:44:10 2009
@@ -0,0 +1,3 @@
+traceout=System.err
+
+pollInterval=5000
Propchange: felix/sandbox/donsez/producerquery/src/main/resources/initialstate.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/producerquery/src/site/producerqueryservice.ppt
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/producerquery/src/site/producerqueryservice.ppt?rev=801448&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/donsez/producerquery/src/site/producerqueryservice.ppt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream