Return-Path: Delivered-To: apmail-felix-commits-archive@www.apache.org Received: (qmail 80846 invoked from network); 5 Aug 2009 22:46:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Aug 2009 22:46:59 -0000 Received: (qmail 30984 invoked by uid 500); 5 Aug 2009 22:47:06 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 30899 invoked by uid 500); 5 Aug 2009 22:47:05 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 30889 invoked by uid 99); 5 Aug 2009 22:47:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Aug 2009 22:47:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Aug 2009 22:47:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 54482238887A; Wed, 5 Aug 2009 22:46:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@felix.apache.org From: donsez@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090805224643.54482238887A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ + + + + demo for the Apache Felix Producer Query Service. + + + 4.0.0 + bundle + Apache Felix Producer Query Service Demo + org.apache.felix.sandbox.producerquery.demo + org.apache.felix.sandbox + 0.1.0 + ${description} + + + + org.apache.felix + org.osgi.core + 1.0.0 + + + + org.apache.felix + org.osgi.compendium + 1.0.0 + + + + org.apache.felix.sandbox.wireadminbinder + org.apache.felix.sandbox + 0.2.0 + + + + org.apache.felix.sandbox + org.apache.felix.sandbox.producerquery + 0.1.0 + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + + + org.apache.felix.sandbox.producerquery.demo.* + + + org.apache.felix.sandbox.producerquery.ProducerQueryService + + org.osgi.service.wireadmin.Consumer + + + + + OSGI-INF/component.xml + + + + + + + + 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 Felix Project Team + */ +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