Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D6A16E33 for ; Wed, 22 Jun 2011 12:10:26 +0000 (UTC) Received: (qmail 42502 invoked by uid 500); 22 Jun 2011 12:10:26 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 42424 invoked by uid 500); 22 Jun 2011 12:10:25 -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 42414 invoked by uid 99); 22 Jun 2011 12:10:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Jun 2011 12:10:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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, 22 Jun 2011 12:10:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 681B8238890D; Wed, 22 Jun 2011 12:10:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1138421 - in /felix/trunk/dependencymanager: core/src/main/java/org/apache/felix/dm/DependencyManager.java test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java Date: Wed, 22 Jun 2011 12:10:01 -0000 To: commits@felix.apache.org From: marrs@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110622121001.681B8238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: marrs Date: Wed Jun 22 12:10:01 2011 New Revision: 1138421 URL: http://svn.apache.org/viewvc?rev=1138421&view=rev Log: FELIX-3008 Added test and fix for this issue. If the dependency manager bundle was not yet started when indices are defined and the first bundle starts to use them, that bundle will then attempt to start the dependency manager automatically. If that fails, no indices will be used. Added: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java (with props) Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java?rev=1138421&r1=1138420&r2=1138421&view=diff ============================================================================== --- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java (original) +++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java Wed Jun 22 12:10:01 2011 @@ -42,7 +42,9 @@ import org.apache.felix.dm.impl.index.As import org.apache.felix.dm.impl.index.MultiPropertyExactFilter; import org.apache.felix.dm.impl.index.ServiceRegistryCache; import org.apache.felix.dm.impl.metatype.PropertyMetaDataImpl; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; import org.osgi.framework.FrameworkUtil; /** @@ -89,18 +91,30 @@ public class DependencyManager { static { String index = System.getProperty(SERVICEREGISTRY_CACHE_INDICES); if (index != null) { - m_serviceRegistryCache = new ServiceRegistryCache(FrameworkUtil.getBundle(DependencyManager.class).getBundleContext()); - m_serviceRegistryCache.open(); // TODO close it somewhere - String[] props = index.split(";"); - for (int i = 0; i < props.length; i++) { - if (props[i].equals("*aspect*")) { - m_serviceRegistryCache.addFilterIndex(new AspectFilterIndex()); + Bundle bundle = FrameworkUtil.getBundle(DependencyManager.class); + try { + if (bundle.getState() != Bundle.ACTIVE) { + bundle.start(); } - else { - String[] propList = props[i].split(","); - m_serviceRegistryCache.addFilterIndex(new MultiPropertyExactFilter(propList)); + BundleContext bundleContext = bundle.getBundleContext(); + + m_serviceRegistryCache = new ServiceRegistryCache(bundleContext); + m_serviceRegistryCache.open(); // TODO close it somewhere + String[] props = index.split(";"); + for (int i = 0; i < props.length; i++) { + if (props[i].equals("*aspect*")) { + m_serviceRegistryCache.addFilterIndex(new AspectFilterIndex()); + } + else { + String[] propList = props[i].split(","); + m_serviceRegistryCache.addFilterIndex(new MultiPropertyExactFilter(propList)); + } } } + catch (BundleException e) { + // if we cannot start ourselves, we cannot use the indices + // TODO we might want to warn people about this + } } } Added: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java?rev=1138421&view=auto ============================================================================== --- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java (added) +++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java Wed Jun 22 12:10:01 2011 @@ -0,0 +1,108 @@ +/* + * 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.dm.test; +//import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartupFor; +//import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption; + +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.CoreOptions.provision; +import junit.framework.Assert; + +import org.apache.felix.dm.Component; +import org.apache.felix.dm.DependencyManager; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.Configuration; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; + + +@RunWith(JUnit4TestRunner.class) +public class FELIX3008_FilterIndexStartupTest extends Base { + @Configuration + public static Option[] configuration() { + return options( + //vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" ), + //waitForFrameworkStartupFor(Long.MAX_VALUE), + provision( + mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version(Base.OSGI_SPEC_VERSION), + mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject().noStart() + ) + ); + } + + @Test + public void testNormalStart(BundleContext context) throws Exception { + System.setProperty("org.apache.felix.dependencymanager.filterindex", "objectClass"); + DependencyManager m = new DependencyManager(context); + // helper class that ensures certain steps get executed in sequence + Ensure e = new Ensure(); + // create a provider + Provider provider = new Provider(); + // activate it + Component p = m.createComponent() + .setInterface(Service.class.getName(), null) + .setImplementation(provider); + + Consumer consumer = new Consumer(e); + Component c = m.createComponent() + .setImplementation(consumer) + .add(m.createServiceDependency() + .setService(Service.class) + .setRequired(true) + ); + + m.add(p); + m.add(c); + e.waitForStep(1, 5000); + m.remove(p); + e.waitForStep(2, 5000); + m.remove(c); + + Assert.assertEquals("Dependency manager bundle should be active.", Bundle.ACTIVE, context.getBundle().getState()); + } + + public static class Consumer { + volatile Service m_service; + private final Ensure m_ensure; + + public Consumer(Ensure e) { + m_ensure = e; + } + + public void start() { + System.out.println("start"); + m_ensure.step(1); + } + + public void stop() { + System.out.println("stop"); + m_ensure.step(2); + } + } + + public static interface Service { + } + + public static class Provider implements Service { + } +} Propchange: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain