You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@aries.apache.org by Jeremy Hughes <hu...@apache.org> on 2010/05/14 11:33:13 UTC
Re: svn commit: r941776 - in /incubator/aries/trunk:
blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/
jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/
util/src/main/java/org/apache/aries/util/tracker/
Hi Lin, did you mean to delete the files:
incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java
incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java
incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java
at the moment they are 0 length files.
Cheers,
Jeremy
On 6 May 2010 16:22, <li...@apache.org> wrote:
> Author: linsun
> Date: Thu May 6 15:22:31 2010
> New Revision: 941776
>
> URL: http://svn.apache.org/viewvc?rev=941776&view=rev
> Log:
> ARIES-272 BundleTrackerCustomizers will not recurse on bundles added to a CompositeBundle before the composite bundle is started - patch from Holly Cummins
>
> Added:
> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java (with props)
> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java (with props)
> Modified:
> incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
> incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java
> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java
> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java
>
> Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java?rev=941776&r1=941775&r2=941776&view=diff
> ==============================================================================
> --- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java (original)
> +++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java Thu May 6 15:22:31 2010
> @@ -37,7 +37,7 @@ import org.apache.aries.blueprint.Parser
> import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl;
> import org.apache.aries.blueprint.utils.HeaderParser;
> import org.apache.aries.blueprint.utils.HeaderParser.PathElement;
> -import org.apache.aries.util.tracker.AriesBundleTrackerCustomizer;
> +import org.apache.aries.util.tracker.RecursiveBundleTracker;
> import org.osgi.framework.Bundle;
> import org.osgi.framework.BundleActivator;
> import org.osgi.framework.BundleContext;
> @@ -54,8 +54,7 @@ import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> /**
> - * This is the blueprint extender that listens to blueprint bundles. it implements the sync
> - * bundle listener but it doesn't register the listener and uses the bundle tracker instead.
> + * This is the blueprint extender that listens to blueprint bundles.
> *
> * @version $Rev$, $Date$
> */
> @@ -68,7 +67,7 @@ public class BlueprintExtender implement
> private Map<Bundle, BlueprintContainerImpl> containers;
> private BlueprintEventDispatcher eventDispatcher;
> private NamespaceHandlerRegistry handlers;
> - private BundleTracker bt;
> + private RecursiveBundleTracker bt;
> private ServiceRegistration parserServiceReg;
>
> public void start(BundleContext context) {
> @@ -80,13 +79,9 @@ public class BlueprintExtender implement
> eventDispatcher = new BlueprintEventDispatcher(context, executors);
> containers = new HashMap<Bundle, BlueprintContainerImpl>();
>
> - ServiceReference sr = this.context.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
> - if (sr == null) {
> - bt = new BundleTracker(context, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING, new BlueprintBundleTrackerCustomizer());
> - } else {
> - // composite bundle factory service is active, let's track blueprint bundles installed in the child frameworks too.
> - bt = new BundleTracker(context, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING, new BlueprintMutilBundleTrackerCustomizer());
> - }
> + int stateMask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE
> + | Bundle.STOPPING;
> + bt = new RecursiveBundleTracker(context, stateMask, new BlueprintBundleTrackerCustomizer());
> bt.open();
>
> // Create and publish a ParserService
> @@ -374,44 +369,4 @@ public class BlueprintExtender implement
> }
> }
>
> - // blueprint bundle tracker calls bundleChanged to minimize changes.
> - // this bundle tracker customizer handles bundles installed in the child framework as well
> - private class BlueprintMutilBundleTrackerCustomizer extends
> - AriesBundleTrackerCustomizer {
> -
> - public BlueprintMutilBundleTrackerCustomizer() {
> - }
> -
> - public Object addingBundle(Bundle b, BundleEvent event) {
> -
> - super.addingBundle(b, event);
> -
> - if (event == null) {
> - // existing bundles first added to the tracker with no event change
> - checkInitialBundle(b);
> - } else {
> - bundleChanged(event);
> - }
> -
> - return b;
> - }
> -
> - public void modifiedBundle(Bundle b, BundleEvent event, Object arg2) {
> -
> - super.modifiedBundle(b, event, arg2);
> -
> - if (event == null) {
> - // cannot think of why we would be interested in a modified bundle with no bundle event
> - return;
> - } else {
> - bundleChanged(event);
> - }
> -
> - }
> -
> - // don't think we would be interested in removedBundle, as that is
> - // called when bundle is removed from the tracker
> - public void removedBundle(Bundle b, BundleEvent event, Object arg2) {
> - }
> - }
> }
>
> Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java?rev=941776&r1=941775&r2=941776&view=diff
> ==============================================================================
> --- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java (original)
> +++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java Thu May 6 15:22:31 2010
> @@ -34,6 +34,7 @@ import java.util.Properties;
> import java.util.Set;
> import java.util.Map.Entry;
>
> +import org.apache.aries.util.VersionRange;
> import org.apache.aries.jpa.container.ManagedPersistenceUnitInfo;
> import org.apache.aries.jpa.container.ManagedPersistenceUnitInfoFactory;
> import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
> @@ -41,21 +42,21 @@ import org.apache.aries.jpa.container.pa
> import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParser;
> import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParserException;
> import org.apache.aries.jpa.container.unit.impl.ManagedPersistenceUnitInfoFactoryImpl;
> -import org.apache.aries.util.VersionRange;
> -import org.apache.aries.util.tracker.MultiBundleTracker;
> +import org.apache.aries.util.tracker.RecursiveBundleTracker;
> import org.osgi.framework.Bundle;
> import org.osgi.framework.BundleContext;
> import org.osgi.framework.BundleEvent;
> import org.osgi.framework.Constants;
> import org.osgi.framework.ServiceReference;
> import org.osgi.framework.Version;
> +import org.osgi.util.tracker.BundleTrackerCustomizer;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> /**
> * This class locates, parses and manages persistence units defined in OSGi bundles.
> */
> -public class PersistenceBundleManager extends MultiBundleTracker
> +public class PersistenceBundleManager implements BundleTrackerCustomizer
> {
> /** Logger */
> private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
> @@ -86,6 +87,7 @@ public class PersistenceBundleManager ex
> private PersistenceDescriptorParser parser;
> /** Configuration for this extender */
> private Properties config;
> + private final RecursiveBundleTracker tracker;
>
> /**
> * Create the extender. Note that it will not start tracking
> @@ -94,9 +96,9 @@ public class PersistenceBundleManager ex
> */
> public PersistenceBundleManager(BundleContext ctx)
> {
> - super(ctx, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING |
> - Bundle.ACTIVE | Bundle.STOPPING);
> this.ctx = ctx;
> + tracker = new RecursiveBundleTracker(ctx, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING |
> + Bundle.ACTIVE | Bundle.STOPPING, this);
> }
>
> /**
> @@ -109,7 +111,6 @@ public class PersistenceBundleManager ex
>
>
> @SuppressWarnings("unchecked")
> - @Override
> public void open() {
> //Create the pluggable ManagedPersistenceUnitInfoFactory
> String className = config.getProperty(ManagedPersistenceUnitInfoFactory.DEFAULT_PU_INFO_FACTORY_KEY);
> @@ -127,9 +128,15 @@ public class PersistenceBundleManager ex
> if(persistenceUnitFactory == null)
> persistenceUnitFactory = new ManagedPersistenceUnitInfoFactoryImpl();
>
> - super.open();
> + tracker.open();
> }
>
> + public void close()
> + {
> + if (tracker != null) {
> + tracker.close();
> + }
> + }
> public Object addingBundle(Bundle bundle, BundleEvent event)
> {
> EntityManagerFactoryManager mgr = setupManager(bundle, null, true);
>
> Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java?rev=941776&r1=941775&r2=941776&view=diff
> ==============================================================================
> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java (original)
> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java Thu May 6 15:22:31 2010
> @@ -1,83 +0,0 @@
> -/**
> - * 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.aries.util.tracker;
> -
> -import java.util.List;
> -
> -import org.osgi.framework.Bundle;
> -import org.osgi.framework.BundleContext;
> -import org.osgi.framework.BundleEvent;
> -import org.osgi.service.framework.CompositeBundle;
> -import org.osgi.util.tracker.BundleTracker;
> -import org.osgi.util.tracker.BundleTrackerCustomizer;
> -
> -/**
> - * This class provides code to track <code>CompositeBundle></code>s.
> - */
> -public abstract class AbstractBundleTrackerCustomizer implements BundleTrackerCustomizer {
> -
> - public AbstractBundleTrackerCustomizer() {
> - super();
> - }
> -
> - protected void customizedProcessBundle(BundleTrackerCustomizer btc, Bundle b, BundleEvent event, int stateMask) {
> - if (b instanceof CompositeBundle) {
> - // check if the compositeBundle is already tracked in the
> - // BundleTrackerFactory
> - String bundleScope = b.getSymbolicName() + "_"
> - + b.getVersion().toString();
> - List<BundleTracker> btList = BundleTrackerFactory
> - .getBundleTrackerList(bundleScope);
> -
> - // bundle is already active and there is no event associated
> - // this can happen when bundle is first time added to the tracker
> - if (event == null) {
> - if (b.getState() == Bundle.ACTIVE) {
> - openTracker(btc, b, bundleScope, stateMask);
> - }
> - } else {
> - if (event.getType() == BundleEvent.STOPPING) {
> - // if CompositeBundle is being stopped, let's remove the bundle
> - // tracker(s) associated with the composite bundle
> - if (btList != null) {
> - // unregister the bundlescope off the factory and close
> - // bundle trackers
> - BundleTrackerFactory
> - .unregisterAndCloseBundleTracker(bundleScope);
> - }
> - } else if (event.getType() == BundleEvent.STARTING) {
> - openTracker(btc, b, bundleScope, stateMask);
> - }
> - }
> - }
> - }
> -
> - private void openTracker(BundleTrackerCustomizer btc, Bundle b, String bundleScope, int stateMask) {
> - // let's process each of the bundle in the CompositeBundle
> - CompositeBundle cb = (CompositeBundle) b;
> - BundleContext compositeBundleContext = cb
> - .getCompositeFramework().getBundleContext();
> -
> - // let's track each of the bundle in the CompositeBundle
> - BundleTracker bt = new BundleTracker(compositeBundleContext, stateMask, btc);
> - bt.open();
> - BundleTrackerFactory.registerBundleTracker(bundleScope, bt);
> - }
> -
> -}
>
> Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java?rev=941776&r1=941775&r2=941776&view=diff
> ==============================================================================
> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java (original)
> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java Thu May 6 15:22:31 2010
> @@ -1,40 +0,0 @@
> -/**
> - * 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.aries.util.tracker;
> -
> -import org.osgi.framework.Bundle;
> -import org.osgi.framework.BundleEvent;
> -
> -public abstract class AriesBundleTrackerCustomizer extends AbstractBundleTrackerCustomizer {
> -
> - public AriesBundleTrackerCustomizer() {
> - }
> -
> - public Object addingBundle(Bundle b, BundleEvent event) {
> - customizedProcessBundle(this, b, event, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING);
> - return b;
> - }
> -
> - public void modifiedBundle(Bundle b, BundleEvent event, Object arg2) {
> - customizedProcessBundle(this, b, event, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING);
> - }
> -
> - public void removedBundle(Bundle b, BundleEvent event, Object arg2) {
> - }
> -}
>
> Added: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java?rev=941776&view=auto
> ==============================================================================
> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java (added)
> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java Thu May 6 15:22:31 2010
> @@ -0,0 +1,160 @@
> +/**
> + * 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.aries.util.tracker;
> +
> +import java.util.HashSet;
> +import java.util.List;
> +import java.util.Set;
> +
> +import org.osgi.framework.Bundle;
> +import org.osgi.framework.BundleContext;
> +import org.osgi.framework.BundleEvent;
> +import org.osgi.service.framework.CompositeBundle;
> +import org.osgi.util.tracker.BundleTracker;
> +import org.osgi.util.tracker.BundleTrackerCustomizer;
> +
> +/**
> + * A BundleTracker which will track bundles in the given context, and also
> + * bundles in any child contexts. This should be used instead of the
> + * normal non-recursive BundleTracker when registering bundle tracker
> + * customizers.
> + */
> +public class InternalRecursiveBundleTracker extends BundleTracker
> +{
> + private final int mask;
> +
> + private final Set<BundleContext> alreadyRecursedContexts = new HashSet<BundleContext>();
> +
> + private final BundleTrackerCustomizer customizer;
> +
> + public InternalRecursiveBundleTracker(BundleContext context, int stateMask,
> + BundleTrackerCustomizer customizer)
> + {
> + super(context, stateMask, null);
> + mask = stateMask;
> + this.customizer = customizer;
> + }
> +
> + /*
> + * (non-Javadoc)
> + * @see org.osgi.util.tracker.BundleTracker#addingBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent)
> + */
> + @Override
> + public Object addingBundle(Bundle b, BundleEvent event)
> + {
> + Object o = null;
> +
> + if (b instanceof CompositeBundle) {
> + customizedProcessBundle(this, b, event);
> + o = b;
> + } else {
> + // Delegate to our customizer for normal bundles
> + if (customizer != null) {
> + o = customizer.addingBundle(b, event);
> + }
> + }
> +
> + return o;
> + }
> +
> + /*
> + * (non-Javadoc)
> + * @see org.osgi.util.tracker.BundleTracker#modifiedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
> + */
> + @Override
> + public void modifiedBundle(Bundle b, BundleEvent event, Object object)
> + {
> + if (b instanceof CompositeBundle) {
> + customizedProcessBundle(this, b, event);
> + } else {
> + // Delegate to our customizer for normal bundles
> + if (customizer != null) {
> + customizer.modifiedBundle(b, event, object);
> + }
> + }
> + }
> +
> + /*
> + * (non-Javadoc)
> + * @see org.osgi.util.tracker.BundleTracker#removedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
> + */
> + @Override
> + public void removedBundle(Bundle b, BundleEvent event, Object object)
> + {
> + if (b instanceof CompositeBundle) {
> + // We should have already picked up the stopping event on the CBA itself
> + } else {
> + if (customizer != null) {
> + customizer.removedBundle(b, event, object);
> + }
> + }
> + }
> +
> + protected void customizedProcessBundle(BundleTrackerCustomizer btc, Bundle b, BundleEvent event)
> + {
> + if (b instanceof CompositeBundle) {
> + CompositeBundle cb = (CompositeBundle) b;
> + // check if the compositeBundle is already tracked in the
> + // BundleTrackerFactory
> + String bundleScope = cb.getSymbolicName() + "_" + cb.getVersion().toString();
> + List<BundleTracker> btList = BundleTrackerFactory.getBundleTrackerList(bundleScope);
> +
> + // bundle is already active and there is no event associated
> + // this can happen when bundle is first time added to the tracker
> + if (event == null) {
> + if (cb.getState() == Bundle.INSTALLED || cb.getState() == Bundle.RESOLVED || cb.getState() == Bundle.STARTING || cb.getState() == Bundle.ACTIVE) {
> + openTracker(btc, cb, bundleScope, mask);
> + }
> + } else {
> + if (event.getType() == BundleEvent.STOPPING) {
> + // if CompositeBundle is being stopped, let's remove the bundle
> + // tracker(s) associated with the composite bundle
> + BundleContext compositeBundleContext = ((CompositeBundle) b).getCompositeFramework()
> + .getBundleContext();
> + alreadyRecursedContexts.remove(compositeBundleContext);
> + if (btList != null) {
> + // unregister the bundlescope off the factory and close
> + // bundle trackers
> + BundleTrackerFactory.unregisterAndCloseBundleTracker(bundleScope);
> + }
> + } else if (event.getType() == BundleEvent.INSTALLED
> + || event.getType() == BundleEvent.STARTING) {
> + openTracker(btc, cb, bundleScope, mask);
> + }
> + }
> + }
> + }
> +
> + private synchronized void openTracker(BundleTrackerCustomizer btc, CompositeBundle cb,
> + String bundleScope, int stateMask)
> + {
> + // let's process each of the bundle in the CompositeBundle
> + BundleContext compositeBundleContext = cb.getCompositeFramework().getBundleContext();
> + if (!alreadyRecursedContexts.contains(compositeBundleContext)) {
> + alreadyRecursedContexts.add(compositeBundleContext);
> +
> + // let's track each of the bundle in the CompositeBundle
> + BundleTracker bt = new InternalRecursiveBundleTracker(compositeBundleContext, stateMask,
> + customizer);
> + bt.open();
> + BundleTrackerFactory.registerBundleTracker(bundleScope, bt);
> + }
> + }
> +}
>
> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
> ------------------------------------------------------------------------------
> svn:keywords = Date Revision
>
> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
> ------------------------------------------------------------------------------
> svn:mime-type = text/plain
>
> Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java?rev=941776&r1=941775&r2=941776&view=diff
> ==============================================================================
> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java (original)
> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java Thu May 6 15:22:31 2010
> @@ -1,136 +0,0 @@
> -/**
> - * 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.aries.util.tracker;
> -
> -import org.osgi.framework.Bundle;
> -import org.osgi.framework.BundleContext;
> -import org.osgi.framework.BundleEvent;
> -import org.osgi.framework.ServiceReference;
> -import org.osgi.service.framework.CompositeBundle;
> -import org.osgi.util.tracker.BundleTracker;
> -
> -/**
> - * <p>This class supports the tracking of composite bundles. It allows clients to ignore any
> - * events related to framework bundles, as it will automatically handle these events. In
> - * order to use this class clients must create a subclass and implement the methods of the
> - * <code>BundleTrackerCustomizer</code> interface. In spite of this, instances of this class
> - * MUST NOT be passed as a parameter to any <code>BundleTracker</code>.</p>
> - */
> -public abstract class MultiBundleTracker extends AbstractBundleTrackerCustomizer {
> - private static final int COMPOSITE_BUNDLE_MASK =
> - Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING;
> -
> - private final BundleTracker tracker;
> -
> - /**
> - * Constructor
> - *
> - * @param context - The <code>BundleContext</code> against which the tracking is done.
> - * @param stateMask - The bit mask of the ORing of the bundle states to be tracked. The
> - * mask must contain the flags <code>Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING</code>
> - * as a minimum.
> - * @throws IllegalArgumentException - If the provided bit mask does not contain required
> - * flags
> - */
> - public MultiBundleTracker(BundleContext context, int stateMask) {
> - if ((stateMask & COMPOSITE_BUNDLE_MASK) != COMPOSITE_BUNDLE_MASK)
> - throw new IllegalArgumentException();
> -
> - if (areMultipleFrameworksAvailable(context)) {
> - tracker = new InternalBundleTracker(context, stateMask);
> - } else {
> - tracker = new BundleTracker(context, stateMask, this);
> - }
> - }
> -
> - private static boolean areMultipleFrameworksAvailable(BundleContext context) {
> - ServiceReference sr = context.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
> - return sr != null;
> - }
> -
> - /**
> - * Start tracking bundles that match the bit mask provided at creation time.
> - *
> - * @see BundleTracker#open()
> - */
> - public void open() {
> - tracker.open();
> - }
> -
> - /**
> - * Stop the tracking of bundles
> - *
> - * @see BundleTracker#close()
> - */
> - public void close() {
> - tracker.close();
> - }
> -
> - //This implementation of a BundleTracker is based on the implementation
> - //in org.apache.aries.util.tracker.AriesBundleTrackerCustomizer
> - private class InternalBundleTracker extends BundleTracker {
> - private final int mask;
> -
> - public InternalBundleTracker(BundleContext context, int stateMask) {
> - super(context, stateMask, null);
> -
> - mask = stateMask;
> - }
> -
> - /*
> - * (non-Javadoc)
> - * @see org.osgi.util.tracker.BundleTracker#addingBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent)
> - */
> - public Object addingBundle(Bundle b, BundleEvent event) {
> - Object o = null;
> -
> - if (b instanceof CompositeBundle) {
> - customizedProcessBundle(this, b, event, mask);
> - o = b;
> - }
> - else {
> - o = MultiBundleTracker.this.addingBundle(b, event);
> - }
> -
> - return o;
> - }
> -
> - /*
> - * (non-Javadoc)
> - * @see org.osgi.util.tracker.BundleTracker#modifiedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
> - */
> - public void modifiedBundle(Bundle b, BundleEvent event, Object object) {
> - if (b instanceof CompositeBundle) {
> - customizedProcessBundle(this, b, event, mask);
> - }
> - else {
> - MultiBundleTracker.this.modifiedBundle(b, event, object);
> - }
> - }
> -
> - /*
> - * (non-Javadoc)
> - * @see org.osgi.util.tracker.BundleTracker#removedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
> - */
> - public void removedBundle(Bundle b, BundleEvent event, Object object) {
> - if (!(b instanceof CompositeBundle))
> - MultiBundleTracker.this.removedBundle(b, event, object);
> - }
> - }
> -}
>
> Added: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java?rev=941776&view=auto
> ==============================================================================
> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java (added)
> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java Thu May 6 15:22:31 2010
> @@ -0,0 +1,89 @@
> +/**
> + * 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.aries.util.tracker;
> +
> +import org.osgi.framework.Bundle;
> +import org.osgi.framework.BundleContext;
> +import org.osgi.framework.ServiceReference;
> +import org.osgi.util.tracker.BundleTracker;
> +import org.osgi.util.tracker.BundleTrackerCustomizer;
> +
> +/**
> + * <p>This class supports the tracking of composite bundles. It allows clients to ignore any
> + * events related to framework bundles, as it will automatically handle these events. In
> + * order to use this class clients must create a subclass and implement the methods of the
> + * <code>BundleTrackerCustomizer</code> interface. In spite of this, instances of this class
> + * MUST NOT be passed as a parameter to any <code>BundleTracker</code>.</p>
> + *
> + * The model for using this is that classes should instantiate it
> + * and pass it a 'vanilla' bundle tracker.
> + * @author pradine
> + *
> + */
> +public final class RecursiveBundleTracker {
> + private static final int COMPOSITE_BUNDLE_MASK =
> + Bundle.INSTALLED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING;
> +
> + private final BundleTracker tracker;
> +
> + /**
> + * Constructor
> + *
> + * @param context - The <code>BundleContext</code> against which the tracking is done.
> + * @param stateMask - The bit mask of the ORing of the bundle states to be tracked. The
> + * mask must contain the flags <code>Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING</code>
> + * as a minimum.
> + * @throws IllegalArgumentException - If the provided bit mask does not contain required
> + * flags
> + */
> + public RecursiveBundleTracker(BundleContext context, int stateMask, BundleTrackerCustomizer customizer) {
> + // We always need INSTALLED events so we can recursively listen to the frameworks
> + if ((stateMask & COMPOSITE_BUNDLE_MASK) != COMPOSITE_BUNDLE_MASK)
> + throw new IllegalArgumentException();
> + if (areMultipleFrameworksAvailable(context)) {
> + tracker = new InternalRecursiveBundleTracker(context, stateMask, customizer);
> + } else {
> + tracker = new BundleTracker(context, stateMask, customizer);
> + }
> + }
> +
> + private static boolean areMultipleFrameworksAvailable(BundleContext context) {
> + ServiceReference sr = context.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
> + return sr != null;
> + }
> +
> + /**
> + * Start tracking bundles that match the bit mask provided at creation time.
> + *
> + * @see BundleTracker#open()
> + */
> + public void open() {
> + tracker.open();
> + }
> +
> + /**
> + * Stop the tracking of bundles
> + *
> + * @see BundleTracker#close()
> + */
> + public void close() {
> + tracker.close();
> + }
> +
> +}
>
> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
> ------------------------------------------------------------------------------
> svn:keywords = Date Revision
>
> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
> ------------------------------------------------------------------------------
> svn:mime-type = text/plain
>
>
>
Re: svn commit: r941776 - in /incubator/aries/trunk:
blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/
jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/
util/src/main/java/org/apache/aries/util/tracker/
Posted by Jeremy Hughes <hu...@apache.org>.
Great thanks!
On 14 May 2010 14:25, Lin Sun <li...@gmail.com> wrote:
> Hi Jeremy, yes good catch! Corrected in rev 944251. Thanks
>
> Lin
>
> On Fri, May 14, 2010 at 5:33 AM, Jeremy Hughes <hu...@apache.org> wrote:
>> Hi Lin, did you mean to delete the files:
>>
>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java
>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java
>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java
>>
>> at the moment they are 0 length files.
>>
>> Cheers,
>> Jeremy
>>
>> On 6 May 2010 16:22, <li...@apache.org> wrote:
>>> Author: linsun
>>> Date: Thu May 6 15:22:31 2010
>>> New Revision: 941776
>>>
>>> URL: http://svn.apache.org/viewvc?rev=941776&view=rev
>>> Log:
>>> ARIES-272 BundleTrackerCustomizers will not recurse on bundles added to a CompositeBundle before the composite bundle is started - patch from Holly Cummins
>>>
>>> Added:
>>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java (with props)
>>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java (with props)
>>> Modified:
>>> incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
>>> incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
>>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java
>>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java
>>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java
>>>
>>> Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java?rev=941776&r1=941775&r2=941776&view=diff
>>> ==============================================================================
>>> --- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java (original)
>>> +++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java Thu May 6 15:22:31 2010
>>> @@ -37,7 +37,7 @@ import org.apache.aries.blueprint.Parser
>>> import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl;
>>> import org.apache.aries.blueprint.utils.HeaderParser;
>>> import org.apache.aries.blueprint.utils.HeaderParser.PathElement;
>>> -import org.apache.aries.util.tracker.AriesBundleTrackerCustomizer;
>>> +import org.apache.aries.util.tracker.RecursiveBundleTracker;
>>> import org.osgi.framework.Bundle;
>>> import org.osgi.framework.BundleActivator;
>>> import org.osgi.framework.BundleContext;
>>> @@ -54,8 +54,7 @@ import org.slf4j.Logger;
>>> import org.slf4j.LoggerFactory;
>>>
>>> /**
>>> - * This is the blueprint extender that listens to blueprint bundles. it implements the sync
>>> - * bundle listener but it doesn't register the listener and uses the bundle tracker instead.
>>> + * This is the blueprint extender that listens to blueprint bundles.
>>> *
>>> * @version $Rev$, $Date$
>>> */
>>> @@ -68,7 +67,7 @@ public class BlueprintExtender implement
>>> private Map<Bundle, BlueprintContainerImpl> containers;
>>> private BlueprintEventDispatcher eventDispatcher;
>>> private NamespaceHandlerRegistry handlers;
>>> - private BundleTracker bt;
>>> + private RecursiveBundleTracker bt;
>>> private ServiceRegistration parserServiceReg;
>>>
>>> public void start(BundleContext context) {
>>> @@ -80,13 +79,9 @@ public class BlueprintExtender implement
>>> eventDispatcher = new BlueprintEventDispatcher(context, executors);
>>> containers = new HashMap<Bundle, BlueprintContainerImpl>();
>>>
>>> - ServiceReference sr = this.context.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
>>> - if (sr == null) {
>>> - bt = new BundleTracker(context, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING, new BlueprintBundleTrackerCustomizer());
>>> - } else {
>>> - // composite bundle factory service is active, let's track blueprint bundles installed in the child frameworks too.
>>> - bt = new BundleTracker(context, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING, new BlueprintMutilBundleTrackerCustomizer());
>>> - }
>>> + int stateMask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE
>>> + | Bundle.STOPPING;
>>> + bt = new RecursiveBundleTracker(context, stateMask, new BlueprintBundleTrackerCustomizer());
>>> bt.open();
>>>
>>> // Create and publish a ParserService
>>> @@ -374,44 +369,4 @@ public class BlueprintExtender implement
>>> }
>>> }
>>>
>>> - // blueprint bundle tracker calls bundleChanged to minimize changes.
>>> - // this bundle tracker customizer handles bundles installed in the child framework as well
>>> - private class BlueprintMutilBundleTrackerCustomizer extends
>>> - AriesBundleTrackerCustomizer {
>>> -
>>> - public BlueprintMutilBundleTrackerCustomizer() {
>>> - }
>>> -
>>> - public Object addingBundle(Bundle b, BundleEvent event) {
>>> -
>>> - super.addingBundle(b, event);
>>> -
>>> - if (event == null) {
>>> - // existing bundles first added to the tracker with no event change
>>> - checkInitialBundle(b);
>>> - } else {
>>> - bundleChanged(event);
>>> - }
>>> -
>>> - return b;
>>> - }
>>> -
>>> - public void modifiedBundle(Bundle b, BundleEvent event, Object arg2) {
>>> -
>>> - super.modifiedBundle(b, event, arg2);
>>> -
>>> - if (event == null) {
>>> - // cannot think of why we would be interested in a modified bundle with no bundle event
>>> - return;
>>> - } else {
>>> - bundleChanged(event);
>>> - }
>>> -
>>> - }
>>> -
>>> - // don't think we would be interested in removedBundle, as that is
>>> - // called when bundle is removed from the tracker
>>> - public void removedBundle(Bundle b, BundleEvent event, Object arg2) {
>>> - }
>>> - }
>>> }
>>>
>>> Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java?rev=941776&r1=941775&r2=941776&view=diff
>>> ==============================================================================
>>> --- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java (original)
>>> +++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java Thu May 6 15:22:31 2010
>>> @@ -34,6 +34,7 @@ import java.util.Properties;
>>> import java.util.Set;
>>> import java.util.Map.Entry;
>>>
>>> +import org.apache.aries.util.VersionRange;
>>> import org.apache.aries.jpa.container.ManagedPersistenceUnitInfo;
>>> import org.apache.aries.jpa.container.ManagedPersistenceUnitInfoFactory;
>>> import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
>>> @@ -41,21 +42,21 @@ import org.apache.aries.jpa.container.pa
>>> import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParser;
>>> import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParserException;
>>> import org.apache.aries.jpa.container.unit.impl.ManagedPersistenceUnitInfoFactoryImpl;
>>> -import org.apache.aries.util.VersionRange;
>>> -import org.apache.aries.util.tracker.MultiBundleTracker;
>>> +import org.apache.aries.util.tracker.RecursiveBundleTracker;
>>> import org.osgi.framework.Bundle;
>>> import org.osgi.framework.BundleContext;
>>> import org.osgi.framework.BundleEvent;
>>> import org.osgi.framework.Constants;
>>> import org.osgi.framework.ServiceReference;
>>> import org.osgi.framework.Version;
>>> +import org.osgi.util.tracker.BundleTrackerCustomizer;
>>> import org.slf4j.Logger;
>>> import org.slf4j.LoggerFactory;
>>>
>>> /**
>>> * This class locates, parses and manages persistence units defined in OSGi bundles.
>>> */
>>> -public class PersistenceBundleManager extends MultiBundleTracker
>>> +public class PersistenceBundleManager implements BundleTrackerCustomizer
>>> {
>>> /** Logger */
>>> private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
>>> @@ -86,6 +87,7 @@ public class PersistenceBundleManager ex
>>> private PersistenceDescriptorParser parser;
>>> /** Configuration for this extender */
>>> private Properties config;
>>> + private final RecursiveBundleTracker tracker;
>>>
>>> /**
>>> * Create the extender. Note that it will not start tracking
>>> @@ -94,9 +96,9 @@ public class PersistenceBundleManager ex
>>> */
>>> public PersistenceBundleManager(BundleContext ctx)
>>> {
>>> - super(ctx, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING |
>>> - Bundle.ACTIVE | Bundle.STOPPING);
>>> this.ctx = ctx;
>>> + tracker = new RecursiveBundleTracker(ctx, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING |
>>> + Bundle.ACTIVE | Bundle.STOPPING, this);
>>> }
>>>
>>> /**
>>> @@ -109,7 +111,6 @@ public class PersistenceBundleManager ex
>>>
>>>
>>> @SuppressWarnings("unchecked")
>>> - @Override
>>> public void open() {
>>> //Create the pluggable ManagedPersistenceUnitInfoFactory
>>> String className = config.getProperty(ManagedPersistenceUnitInfoFactory.DEFAULT_PU_INFO_FACTORY_KEY);
>>> @@ -127,9 +128,15 @@ public class PersistenceBundleManager ex
>>> if(persistenceUnitFactory == null)
>>> persistenceUnitFactory = new ManagedPersistenceUnitInfoFactoryImpl();
>>>
>>> - super.open();
>>> + tracker.open();
>>> }
>>>
>>> + public void close()
>>> + {
>>> + if (tracker != null) {
>>> + tracker.close();
>>> + }
>>> + }
>>> public Object addingBundle(Bundle bundle, BundleEvent event)
>>> {
>>> EntityManagerFactoryManager mgr = setupManager(bundle, null, true);
>>>
>>> Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java?rev=941776&r1=941775&r2=941776&view=diff
>>> ==============================================================================
>>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java (original)
>>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java Thu May 6 15:22:31 2010
>>> @@ -1,83 +0,0 @@
>>> -/**
>>> - * 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.aries.util.tracker;
>>> -
>>> -import java.util.List;
>>> -
>>> -import org.osgi.framework.Bundle;
>>> -import org.osgi.framework.BundleContext;
>>> -import org.osgi.framework.BundleEvent;
>>> -import org.osgi.service.framework.CompositeBundle;
>>> -import org.osgi.util.tracker.BundleTracker;
>>> -import org.osgi.util.tracker.BundleTrackerCustomizer;
>>> -
>>> -/**
>>> - * This class provides code to track <code>CompositeBundle></code>s.
>>> - */
>>> -public abstract class AbstractBundleTrackerCustomizer implements BundleTrackerCustomizer {
>>> -
>>> - public AbstractBundleTrackerCustomizer() {
>>> - super();
>>> - }
>>> -
>>> - protected void customizedProcessBundle(BundleTrackerCustomizer btc, Bundle b, BundleEvent event, int stateMask) {
>>> - if (b instanceof CompositeBundle) {
>>> - // check if the compositeBundle is already tracked in the
>>> - // BundleTrackerFactory
>>> - String bundleScope = b.getSymbolicName() + "_"
>>> - + b.getVersion().toString();
>>> - List<BundleTracker> btList = BundleTrackerFactory
>>> - .getBundleTrackerList(bundleScope);
>>> -
>>> - // bundle is already active and there is no event associated
>>> - // this can happen when bundle is first time added to the tracker
>>> - if (event == null) {
>>> - if (b.getState() == Bundle.ACTIVE) {
>>> - openTracker(btc, b, bundleScope, stateMask);
>>> - }
>>> - } else {
>>> - if (event.getType() == BundleEvent.STOPPING) {
>>> - // if CompositeBundle is being stopped, let's remove the bundle
>>> - // tracker(s) associated with the composite bundle
>>> - if (btList != null) {
>>> - // unregister the bundlescope off the factory and close
>>> - // bundle trackers
>>> - BundleTrackerFactory
>>> - .unregisterAndCloseBundleTracker(bundleScope);
>>> - }
>>> - } else if (event.getType() == BundleEvent.STARTING) {
>>> - openTracker(btc, b, bundleScope, stateMask);
>>> - }
>>> - }
>>> - }
>>> - }
>>> -
>>> - private void openTracker(BundleTrackerCustomizer btc, Bundle b, String bundleScope, int stateMask) {
>>> - // let's process each of the bundle in the CompositeBundle
>>> - CompositeBundle cb = (CompositeBundle) b;
>>> - BundleContext compositeBundleContext = cb
>>> - .getCompositeFramework().getBundleContext();
>>> -
>>> - // let's track each of the bundle in the CompositeBundle
>>> - BundleTracker bt = new BundleTracker(compositeBundleContext, stateMask, btc);
>>> - bt.open();
>>> - BundleTrackerFactory.registerBundleTracker(bundleScope, bt);
>>> - }
>>> -
>>> -}
>>>
>>> Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java?rev=941776&r1=941775&r2=941776&view=diff
>>> ==============================================================================
>>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java (original)
>>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java Thu May 6 15:22:31 2010
>>> @@ -1,40 +0,0 @@
>>> -/**
>>> - * 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.aries.util.tracker;
>>> -
>>> -import org.osgi.framework.Bundle;
>>> -import org.osgi.framework.BundleEvent;
>>> -
>>> -public abstract class AriesBundleTrackerCustomizer extends AbstractBundleTrackerCustomizer {
>>> -
>>> - public AriesBundleTrackerCustomizer() {
>>> - }
>>> -
>>> - public Object addingBundle(Bundle b, BundleEvent event) {
>>> - customizedProcessBundle(this, b, event, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING);
>>> - return b;
>>> - }
>>> -
>>> - public void modifiedBundle(Bundle b, BundleEvent event, Object arg2) {
>>> - customizedProcessBundle(this, b, event, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING);
>>> - }
>>> -
>>> - public void removedBundle(Bundle b, BundleEvent event, Object arg2) {
>>> - }
>>> -}
>>>
>>> Added: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java?rev=941776&view=auto
>>> ==============================================================================
>>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java (added)
>>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java Thu May 6 15:22:31 2010
>>> @@ -0,0 +1,160 @@
>>> +/**
>>> + * 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.aries.util.tracker;
>>> +
>>> +import java.util.HashSet;
>>> +import java.util.List;
>>> +import java.util.Set;
>>> +
>>> +import org.osgi.framework.Bundle;
>>> +import org.osgi.framework.BundleContext;
>>> +import org.osgi.framework.BundleEvent;
>>> +import org.osgi.service.framework.CompositeBundle;
>>> +import org.osgi.util.tracker.BundleTracker;
>>> +import org.osgi.util.tracker.BundleTrackerCustomizer;
>>> +
>>> +/**
>>> + * A BundleTracker which will track bundles in the given context, and also
>>> + * bundles in any child contexts. This should be used instead of the
>>> + * normal non-recursive BundleTracker when registering bundle tracker
>>> + * customizers.
>>> + */
>>> +public class InternalRecursiveBundleTracker extends BundleTracker
>>> +{
>>> + private final int mask;
>>> +
>>> + private final Set<BundleContext> alreadyRecursedContexts = new HashSet<BundleContext>();
>>> +
>>> + private final BundleTrackerCustomizer customizer;
>>> +
>>> + public InternalRecursiveBundleTracker(BundleContext context, int stateMask,
>>> + BundleTrackerCustomizer customizer)
>>> + {
>>> + super(context, stateMask, null);
>>> + mask = stateMask;
>>> + this.customizer = customizer;
>>> + }
>>> +
>>> + /*
>>> + * (non-Javadoc)
>>> + * @see org.osgi.util.tracker.BundleTracker#addingBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent)
>>> + */
>>> + @Override
>>> + public Object addingBundle(Bundle b, BundleEvent event)
>>> + {
>>> + Object o = null;
>>> +
>>> + if (b instanceof CompositeBundle) {
>>> + customizedProcessBundle(this, b, event);
>>> + o = b;
>>> + } else {
>>> + // Delegate to our customizer for normal bundles
>>> + if (customizer != null) {
>>> + o = customizer.addingBundle(b, event);
>>> + }
>>> + }
>>> +
>>> + return o;
>>> + }
>>> +
>>> + /*
>>> + * (non-Javadoc)
>>> + * @see org.osgi.util.tracker.BundleTracker#modifiedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
>>> + */
>>> + @Override
>>> + public void modifiedBundle(Bundle b, BundleEvent event, Object object)
>>> + {
>>> + if (b instanceof CompositeBundle) {
>>> + customizedProcessBundle(this, b, event);
>>> + } else {
>>> + // Delegate to our customizer for normal bundles
>>> + if (customizer != null) {
>>> + customizer.modifiedBundle(b, event, object);
>>> + }
>>> + }
>>> + }
>>> +
>>> + /*
>>> + * (non-Javadoc)
>>> + * @see org.osgi.util.tracker.BundleTracker#removedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
>>> + */
>>> + @Override
>>> + public void removedBundle(Bundle b, BundleEvent event, Object object)
>>> + {
>>> + if (b instanceof CompositeBundle) {
>>> + // We should have already picked up the stopping event on the CBA itself
>>> + } else {
>>> + if (customizer != null) {
>>> + customizer.removedBundle(b, event, object);
>>> + }
>>> + }
>>> + }
>>> +
>>> + protected void customizedProcessBundle(BundleTrackerCustomizer btc, Bundle b, BundleEvent event)
>>> + {
>>> + if (b instanceof CompositeBundle) {
>>> + CompositeBundle cb = (CompositeBundle) b;
>>> + // check if the compositeBundle is already tracked in the
>>> + // BundleTrackerFactory
>>> + String bundleScope = cb.getSymbolicName() + "_" + cb.getVersion().toString();
>>> + List<BundleTracker> btList = BundleTrackerFactory.getBundleTrackerList(bundleScope);
>>> +
>>> + // bundle is already active and there is no event associated
>>> + // this can happen when bundle is first time added to the tracker
>>> + if (event == null) {
>>> + if (cb.getState() == Bundle.INSTALLED || cb.getState() == Bundle.RESOLVED || cb.getState() == Bundle.STARTING || cb.getState() == Bundle.ACTIVE) {
>>> + openTracker(btc, cb, bundleScope, mask);
>>> + }
>>> + } else {
>>> + if (event.getType() == BundleEvent.STOPPING) {
>>> + // if CompositeBundle is being stopped, let's remove the bundle
>>> + // tracker(s) associated with the composite bundle
>>> + BundleContext compositeBundleContext = ((CompositeBundle) b).getCompositeFramework()
>>> + .getBundleContext();
>>> + alreadyRecursedContexts.remove(compositeBundleContext);
>>> + if (btList != null) {
>>> + // unregister the bundlescope off the factory and close
>>> + // bundle trackers
>>> + BundleTrackerFactory.unregisterAndCloseBundleTracker(bundleScope);
>>> + }
>>> + } else if (event.getType() == BundleEvent.INSTALLED
>>> + || event.getType() == BundleEvent.STARTING) {
>>> + openTracker(btc, cb, bundleScope, mask);
>>> + }
>>> + }
>>> + }
>>> + }
>>> +
>>> + private synchronized void openTracker(BundleTrackerCustomizer btc, CompositeBundle cb,
>>> + String bundleScope, int stateMask)
>>> + {
>>> + // let's process each of the bundle in the CompositeBundle
>>> + BundleContext compositeBundleContext = cb.getCompositeFramework().getBundleContext();
>>> + if (!alreadyRecursedContexts.contains(compositeBundleContext)) {
>>> + alreadyRecursedContexts.add(compositeBundleContext);
>>> +
>>> + // let's track each of the bundle in the CompositeBundle
>>> + BundleTracker bt = new InternalRecursiveBundleTracker(compositeBundleContext, stateMask,
>>> + customizer);
>>> + bt.open();
>>> + BundleTrackerFactory.registerBundleTracker(bundleScope, bt);
>>> + }
>>> + }
>>> +}
>>>
>>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
>>> ------------------------------------------------------------------------------
>>> svn:eol-style = native
>>>
>>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
>>> ------------------------------------------------------------------------------
>>> svn:keywords = Date Revision
>>>
>>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
>>> ------------------------------------------------------------------------------
>>> svn:mime-type = text/plain
>>>
>>> Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java?rev=941776&r1=941775&r2=941776&view=diff
>>> ==============================================================================
>>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java (original)
>>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java Thu May 6 15:22:31 2010
>>> @@ -1,136 +0,0 @@
>>> -/**
>>> - * 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.aries.util.tracker;
>>> -
>>> -import org.osgi.framework.Bundle;
>>> -import org.osgi.framework.BundleContext;
>>> -import org.osgi.framework.BundleEvent;
>>> -import org.osgi.framework.ServiceReference;
>>> -import org.osgi.service.framework.CompositeBundle;
>>> -import org.osgi.util.tracker.BundleTracker;
>>> -
>>> -/**
>>> - * <p>This class supports the tracking of composite bundles. It allows clients to ignore any
>>> - * events related to framework bundles, as it will automatically handle these events. In
>>> - * order to use this class clients must create a subclass and implement the methods of the
>>> - * <code>BundleTrackerCustomizer</code> interface. In spite of this, instances of this class
>>> - * MUST NOT be passed as a parameter to any <code>BundleTracker</code>.</p>
>>> - */
>>> -public abstract class MultiBundleTracker extends AbstractBundleTrackerCustomizer {
>>> - private static final int COMPOSITE_BUNDLE_MASK =
>>> - Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING;
>>> -
>>> - private final BundleTracker tracker;
>>> -
>>> - /**
>>> - * Constructor
>>> - *
>>> - * @param context - The <code>BundleContext</code> against which the tracking is done.
>>> - * @param stateMask - The bit mask of the ORing of the bundle states to be tracked. The
>>> - * mask must contain the flags <code>Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING</code>
>>> - * as a minimum.
>>> - * @throws IllegalArgumentException - If the provided bit mask does not contain required
>>> - * flags
>>> - */
>>> - public MultiBundleTracker(BundleContext context, int stateMask) {
>>> - if ((stateMask & COMPOSITE_BUNDLE_MASK) != COMPOSITE_BUNDLE_MASK)
>>> - throw new IllegalArgumentException();
>>> -
>>> - if (areMultipleFrameworksAvailable(context)) {
>>> - tracker = new InternalBundleTracker(context, stateMask);
>>> - } else {
>>> - tracker = new BundleTracker(context, stateMask, this);
>>> - }
>>> - }
>>> -
>>> - private static boolean areMultipleFrameworksAvailable(BundleContext context) {
>>> - ServiceReference sr = context.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
>>> - return sr != null;
>>> - }
>>> -
>>> - /**
>>> - * Start tracking bundles that match the bit mask provided at creation time.
>>> - *
>>> - * @see BundleTracker#open()
>>> - */
>>> - public void open() {
>>> - tracker.open();
>>> - }
>>> -
>>> - /**
>>> - * Stop the tracking of bundles
>>> - *
>>> - * @see BundleTracker#close()
>>> - */
>>> - public void close() {
>>> - tracker.close();
>>> - }
>>> -
>>> - //This implementation of a BundleTracker is based on the implementation
>>> - //in org.apache.aries.util.tracker.AriesBundleTrackerCustomizer
>>> - private class InternalBundleTracker extends BundleTracker {
>>> - private final int mask;
>>> -
>>> - public InternalBundleTracker(BundleContext context, int stateMask) {
>>> - super(context, stateMask, null);
>>> -
>>> - mask = stateMask;
>>> - }
>>> -
>>> - /*
>>> - * (non-Javadoc)
>>> - * @see org.osgi.util.tracker.BundleTracker#addingBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent)
>>> - */
>>> - public Object addingBundle(Bundle b, BundleEvent event) {
>>> - Object o = null;
>>> -
>>> - if (b instanceof CompositeBundle) {
>>> - customizedProcessBundle(this, b, event, mask);
>>> - o = b;
>>> - }
>>> - else {
>>> - o = MultiBundleTracker.this.addingBundle(b, event);
>>> - }
>>> -
>>> - return o;
>>> - }
>>> -
>>> - /*
>>> - * (non-Javadoc)
>>> - * @see org.osgi.util.tracker.BundleTracker#modifiedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
>>> - */
>>> - public void modifiedBundle(Bundle b, BundleEvent event, Object object) {
>>> - if (b instanceof CompositeBundle) {
>>> - customizedProcessBundle(this, b, event, mask);
>>> - }
>>> - else {
>>> - MultiBundleTracker.this.modifiedBundle(b, event, object);
>>> - }
>>> - }
>>> -
>>> - /*
>>> - * (non-Javadoc)
>>> - * @see org.osgi.util.tracker.BundleTracker#removedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
>>> - */
>>> - public void removedBundle(Bundle b, BundleEvent event, Object object) {
>>> - if (!(b instanceof CompositeBundle))
>>> - MultiBundleTracker.this.removedBundle(b, event, object);
>>> - }
>>> - }
>>> -}
>>>
>>> Added: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java?rev=941776&view=auto
>>> ==============================================================================
>>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java (added)
>>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java Thu May 6 15:22:31 2010
>>> @@ -0,0 +1,89 @@
>>> +/**
>>> + * 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.aries.util.tracker;
>>> +
>>> +import org.osgi.framework.Bundle;
>>> +import org.osgi.framework.BundleContext;
>>> +import org.osgi.framework.ServiceReference;
>>> +import org.osgi.util.tracker.BundleTracker;
>>> +import org.osgi.util.tracker.BundleTrackerCustomizer;
>>> +
>>> +/**
>>> + * <p>This class supports the tracking of composite bundles. It allows clients to ignore any
>>> + * events related to framework bundles, as it will automatically handle these events. In
>>> + * order to use this class clients must create a subclass and implement the methods of the
>>> + * <code>BundleTrackerCustomizer</code> interface. In spite of this, instances of this class
>>> + * MUST NOT be passed as a parameter to any <code>BundleTracker</code>.</p>
>>> + *
>>> + * The model for using this is that classes should instantiate it
>>> + * and pass it a 'vanilla' bundle tracker.
>>> + * @author pradine
>>> + *
>>> + */
>>> +public final class RecursiveBundleTracker {
>>> + private static final int COMPOSITE_BUNDLE_MASK =
>>> + Bundle.INSTALLED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING;
>>> +
>>> + private final BundleTracker tracker;
>>> +
>>> + /**
>>> + * Constructor
>>> + *
>>> + * @param context - The <code>BundleContext</code> against which the tracking is done.
>>> + * @param stateMask - The bit mask of the ORing of the bundle states to be tracked. The
>>> + * mask must contain the flags <code>Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING</code>
>>> + * as a minimum.
>>> + * @throws IllegalArgumentException - If the provided bit mask does not contain required
>>> + * flags
>>> + */
>>> + public RecursiveBundleTracker(BundleContext context, int stateMask, BundleTrackerCustomizer customizer) {
>>> + // We always need INSTALLED events so we can recursively listen to the frameworks
>>> + if ((stateMask & COMPOSITE_BUNDLE_MASK) != COMPOSITE_BUNDLE_MASK)
>>> + throw new IllegalArgumentException();
>>> + if (areMultipleFrameworksAvailable(context)) {
>>> + tracker = new InternalRecursiveBundleTracker(context, stateMask, customizer);
>>> + } else {
>>> + tracker = new BundleTracker(context, stateMask, customizer);
>>> + }
>>> + }
>>> +
>>> + private static boolean areMultipleFrameworksAvailable(BundleContext context) {
>>> + ServiceReference sr = context.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
>>> + return sr != null;
>>> + }
>>> +
>>> + /**
>>> + * Start tracking bundles that match the bit mask provided at creation time.
>>> + *
>>> + * @see BundleTracker#open()
>>> + */
>>> + public void open() {
>>> + tracker.open();
>>> + }
>>> +
>>> + /**
>>> + * Stop the tracking of bundles
>>> + *
>>> + * @see BundleTracker#close()
>>> + */
>>> + public void close() {
>>> + tracker.close();
>>> + }
>>> +
>>> +}
>>>
>>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
>>> ------------------------------------------------------------------------------
>>> svn:eol-style = native
>>>
>>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
>>> ------------------------------------------------------------------------------
>>> svn:keywords = Date Revision
>>>
>>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
>>> ------------------------------------------------------------------------------
>>> svn:mime-type = text/plain
>>>
>>>
>>>
>>
>
Re: svn commit: r941776 - in /incubator/aries/trunk:
blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/
jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/
util/src/main/java/org/apache/aries/util/tracker/
Posted by Lin Sun <li...@gmail.com>.
Hi Jeremy, yes good catch! Corrected in rev 944251. Thanks
Lin
On Fri, May 14, 2010 at 5:33 AM, Jeremy Hughes <hu...@apache.org> wrote:
> Hi Lin, did you mean to delete the files:
>
> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java
> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java
> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java
>
> at the moment they are 0 length files.
>
> Cheers,
> Jeremy
>
> On 6 May 2010 16:22, <li...@apache.org> wrote:
>> Author: linsun
>> Date: Thu May 6 15:22:31 2010
>> New Revision: 941776
>>
>> URL: http://svn.apache.org/viewvc?rev=941776&view=rev
>> Log:
>> ARIES-272 BundleTrackerCustomizers will not recurse on bundles added to a CompositeBundle before the composite bundle is started - patch from Holly Cummins
>>
>> Added:
>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java (with props)
>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java (with props)
>> Modified:
>> incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
>> incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java
>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java
>> incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java
>>
>> Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java?rev=941776&r1=941775&r2=941776&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java (original)
>> +++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java Thu May 6 15:22:31 2010
>> @@ -37,7 +37,7 @@ import org.apache.aries.blueprint.Parser
>> import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl;
>> import org.apache.aries.blueprint.utils.HeaderParser;
>> import org.apache.aries.blueprint.utils.HeaderParser.PathElement;
>> -import org.apache.aries.util.tracker.AriesBundleTrackerCustomizer;
>> +import org.apache.aries.util.tracker.RecursiveBundleTracker;
>> import org.osgi.framework.Bundle;
>> import org.osgi.framework.BundleActivator;
>> import org.osgi.framework.BundleContext;
>> @@ -54,8 +54,7 @@ import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> /**
>> - * This is the blueprint extender that listens to blueprint bundles. it implements the sync
>> - * bundle listener but it doesn't register the listener and uses the bundle tracker instead.
>> + * This is the blueprint extender that listens to blueprint bundles.
>> *
>> * @version $Rev$, $Date$
>> */
>> @@ -68,7 +67,7 @@ public class BlueprintExtender implement
>> private Map<Bundle, BlueprintContainerImpl> containers;
>> private BlueprintEventDispatcher eventDispatcher;
>> private NamespaceHandlerRegistry handlers;
>> - private BundleTracker bt;
>> + private RecursiveBundleTracker bt;
>> private ServiceRegistration parserServiceReg;
>>
>> public void start(BundleContext context) {
>> @@ -80,13 +79,9 @@ public class BlueprintExtender implement
>> eventDispatcher = new BlueprintEventDispatcher(context, executors);
>> containers = new HashMap<Bundle, BlueprintContainerImpl>();
>>
>> - ServiceReference sr = this.context.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
>> - if (sr == null) {
>> - bt = new BundleTracker(context, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING, new BlueprintBundleTrackerCustomizer());
>> - } else {
>> - // composite bundle factory service is active, let's track blueprint bundles installed in the child frameworks too.
>> - bt = new BundleTracker(context, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING, new BlueprintMutilBundleTrackerCustomizer());
>> - }
>> + int stateMask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE
>> + | Bundle.STOPPING;
>> + bt = new RecursiveBundleTracker(context, stateMask, new BlueprintBundleTrackerCustomizer());
>> bt.open();
>>
>> // Create and publish a ParserService
>> @@ -374,44 +369,4 @@ public class BlueprintExtender implement
>> }
>> }
>>
>> - // blueprint bundle tracker calls bundleChanged to minimize changes.
>> - // this bundle tracker customizer handles bundles installed in the child framework as well
>> - private class BlueprintMutilBundleTrackerCustomizer extends
>> - AriesBundleTrackerCustomizer {
>> -
>> - public BlueprintMutilBundleTrackerCustomizer() {
>> - }
>> -
>> - public Object addingBundle(Bundle b, BundleEvent event) {
>> -
>> - super.addingBundle(b, event);
>> -
>> - if (event == null) {
>> - // existing bundles first added to the tracker with no event change
>> - checkInitialBundle(b);
>> - } else {
>> - bundleChanged(event);
>> - }
>> -
>> - return b;
>> - }
>> -
>> - public void modifiedBundle(Bundle b, BundleEvent event, Object arg2) {
>> -
>> - super.modifiedBundle(b, event, arg2);
>> -
>> - if (event == null) {
>> - // cannot think of why we would be interested in a modified bundle with no bundle event
>> - return;
>> - } else {
>> - bundleChanged(event);
>> - }
>> -
>> - }
>> -
>> - // don't think we would be interested in removedBundle, as that is
>> - // called when bundle is removed from the tracker
>> - public void removedBundle(Bundle b, BundleEvent event, Object arg2) {
>> - }
>> - }
>> }
>>
>> Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java?rev=941776&r1=941775&r2=941776&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java (original)
>> +++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java Thu May 6 15:22:31 2010
>> @@ -34,6 +34,7 @@ import java.util.Properties;
>> import java.util.Set;
>> import java.util.Map.Entry;
>>
>> +import org.apache.aries.util.VersionRange;
>> import org.apache.aries.jpa.container.ManagedPersistenceUnitInfo;
>> import org.apache.aries.jpa.container.ManagedPersistenceUnitInfoFactory;
>> import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
>> @@ -41,21 +42,21 @@ import org.apache.aries.jpa.container.pa
>> import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParser;
>> import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParserException;
>> import org.apache.aries.jpa.container.unit.impl.ManagedPersistenceUnitInfoFactoryImpl;
>> -import org.apache.aries.util.VersionRange;
>> -import org.apache.aries.util.tracker.MultiBundleTracker;
>> +import org.apache.aries.util.tracker.RecursiveBundleTracker;
>> import org.osgi.framework.Bundle;
>> import org.osgi.framework.BundleContext;
>> import org.osgi.framework.BundleEvent;
>> import org.osgi.framework.Constants;
>> import org.osgi.framework.ServiceReference;
>> import org.osgi.framework.Version;
>> +import org.osgi.util.tracker.BundleTrackerCustomizer;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> /**
>> * This class locates, parses and manages persistence units defined in OSGi bundles.
>> */
>> -public class PersistenceBundleManager extends MultiBundleTracker
>> +public class PersistenceBundleManager implements BundleTrackerCustomizer
>> {
>> /** Logger */
>> private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
>> @@ -86,6 +87,7 @@ public class PersistenceBundleManager ex
>> private PersistenceDescriptorParser parser;
>> /** Configuration for this extender */
>> private Properties config;
>> + private final RecursiveBundleTracker tracker;
>>
>> /**
>> * Create the extender. Note that it will not start tracking
>> @@ -94,9 +96,9 @@ public class PersistenceBundleManager ex
>> */
>> public PersistenceBundleManager(BundleContext ctx)
>> {
>> - super(ctx, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING |
>> - Bundle.ACTIVE | Bundle.STOPPING);
>> this.ctx = ctx;
>> + tracker = new RecursiveBundleTracker(ctx, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING |
>> + Bundle.ACTIVE | Bundle.STOPPING, this);
>> }
>>
>> /**
>> @@ -109,7 +111,6 @@ public class PersistenceBundleManager ex
>>
>>
>> @SuppressWarnings("unchecked")
>> - @Override
>> public void open() {
>> //Create the pluggable ManagedPersistenceUnitInfoFactory
>> String className = config.getProperty(ManagedPersistenceUnitInfoFactory.DEFAULT_PU_INFO_FACTORY_KEY);
>> @@ -127,9 +128,15 @@ public class PersistenceBundleManager ex
>> if(persistenceUnitFactory == null)
>> persistenceUnitFactory = new ManagedPersistenceUnitInfoFactoryImpl();
>>
>> - super.open();
>> + tracker.open();
>> }
>>
>> + public void close()
>> + {
>> + if (tracker != null) {
>> + tracker.close();
>> + }
>> + }
>> public Object addingBundle(Bundle bundle, BundleEvent event)
>> {
>> EntityManagerFactoryManager mgr = setupManager(bundle, null, true);
>>
>> Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java?rev=941776&r1=941775&r2=941776&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java (original)
>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AbstractBundleTrackerCustomizer.java Thu May 6 15:22:31 2010
>> @@ -1,83 +0,0 @@
>> -/**
>> - * 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.aries.util.tracker;
>> -
>> -import java.util.List;
>> -
>> -import org.osgi.framework.Bundle;
>> -import org.osgi.framework.BundleContext;
>> -import org.osgi.framework.BundleEvent;
>> -import org.osgi.service.framework.CompositeBundle;
>> -import org.osgi.util.tracker.BundleTracker;
>> -import org.osgi.util.tracker.BundleTrackerCustomizer;
>> -
>> -/**
>> - * This class provides code to track <code>CompositeBundle></code>s.
>> - */
>> -public abstract class AbstractBundleTrackerCustomizer implements BundleTrackerCustomizer {
>> -
>> - public AbstractBundleTrackerCustomizer() {
>> - super();
>> - }
>> -
>> - protected void customizedProcessBundle(BundleTrackerCustomizer btc, Bundle b, BundleEvent event, int stateMask) {
>> - if (b instanceof CompositeBundle) {
>> - // check if the compositeBundle is already tracked in the
>> - // BundleTrackerFactory
>> - String bundleScope = b.getSymbolicName() + "_"
>> - + b.getVersion().toString();
>> - List<BundleTracker> btList = BundleTrackerFactory
>> - .getBundleTrackerList(bundleScope);
>> -
>> - // bundle is already active and there is no event associated
>> - // this can happen when bundle is first time added to the tracker
>> - if (event == null) {
>> - if (b.getState() == Bundle.ACTIVE) {
>> - openTracker(btc, b, bundleScope, stateMask);
>> - }
>> - } else {
>> - if (event.getType() == BundleEvent.STOPPING) {
>> - // if CompositeBundle is being stopped, let's remove the bundle
>> - // tracker(s) associated with the composite bundle
>> - if (btList != null) {
>> - // unregister the bundlescope off the factory and close
>> - // bundle trackers
>> - BundleTrackerFactory
>> - .unregisterAndCloseBundleTracker(bundleScope);
>> - }
>> - } else if (event.getType() == BundleEvent.STARTING) {
>> - openTracker(btc, b, bundleScope, stateMask);
>> - }
>> - }
>> - }
>> - }
>> -
>> - private void openTracker(BundleTrackerCustomizer btc, Bundle b, String bundleScope, int stateMask) {
>> - // let's process each of the bundle in the CompositeBundle
>> - CompositeBundle cb = (CompositeBundle) b;
>> - BundleContext compositeBundleContext = cb
>> - .getCompositeFramework().getBundleContext();
>> -
>> - // let's track each of the bundle in the CompositeBundle
>> - BundleTracker bt = new BundleTracker(compositeBundleContext, stateMask, btc);
>> - bt.open();
>> - BundleTrackerFactory.registerBundleTracker(bundleScope, bt);
>> - }
>> -
>> -}
>>
>> Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java?rev=941776&r1=941775&r2=941776&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java (original)
>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/AriesBundleTrackerCustomizer.java Thu May 6 15:22:31 2010
>> @@ -1,40 +0,0 @@
>> -/**
>> - * 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.aries.util.tracker;
>> -
>> -import org.osgi.framework.Bundle;
>> -import org.osgi.framework.BundleEvent;
>> -
>> -public abstract class AriesBundleTrackerCustomizer extends AbstractBundleTrackerCustomizer {
>> -
>> - public AriesBundleTrackerCustomizer() {
>> - }
>> -
>> - public Object addingBundle(Bundle b, BundleEvent event) {
>> - customizedProcessBundle(this, b, event, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING);
>> - return b;
>> - }
>> -
>> - public void modifiedBundle(Bundle b, BundleEvent event, Object arg2) {
>> - customizedProcessBundle(this, b, event, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING);
>> - }
>> -
>> - public void removedBundle(Bundle b, BundleEvent event, Object arg2) {
>> - }
>> -}
>>
>> Added: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java?rev=941776&view=auto
>> ==============================================================================
>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java (added)
>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java Thu May 6 15:22:31 2010
>> @@ -0,0 +1,160 @@
>> +/**
>> + * 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.aries.util.tracker;
>> +
>> +import java.util.HashSet;
>> +import java.util.List;
>> +import java.util.Set;
>> +
>> +import org.osgi.framework.Bundle;
>> +import org.osgi.framework.BundleContext;
>> +import org.osgi.framework.BundleEvent;
>> +import org.osgi.service.framework.CompositeBundle;
>> +import org.osgi.util.tracker.BundleTracker;
>> +import org.osgi.util.tracker.BundleTrackerCustomizer;
>> +
>> +/**
>> + * A BundleTracker which will track bundles in the given context, and also
>> + * bundles in any child contexts. This should be used instead of the
>> + * normal non-recursive BundleTracker when registering bundle tracker
>> + * customizers.
>> + */
>> +public class InternalRecursiveBundleTracker extends BundleTracker
>> +{
>> + private final int mask;
>> +
>> + private final Set<BundleContext> alreadyRecursedContexts = new HashSet<BundleContext>();
>> +
>> + private final BundleTrackerCustomizer customizer;
>> +
>> + public InternalRecursiveBundleTracker(BundleContext context, int stateMask,
>> + BundleTrackerCustomizer customizer)
>> + {
>> + super(context, stateMask, null);
>> + mask = stateMask;
>> + this.customizer = customizer;
>> + }
>> +
>> + /*
>> + * (non-Javadoc)
>> + * @see org.osgi.util.tracker.BundleTracker#addingBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent)
>> + */
>> + @Override
>> + public Object addingBundle(Bundle b, BundleEvent event)
>> + {
>> + Object o = null;
>> +
>> + if (b instanceof CompositeBundle) {
>> + customizedProcessBundle(this, b, event);
>> + o = b;
>> + } else {
>> + // Delegate to our customizer for normal bundles
>> + if (customizer != null) {
>> + o = customizer.addingBundle(b, event);
>> + }
>> + }
>> +
>> + return o;
>> + }
>> +
>> + /*
>> + * (non-Javadoc)
>> + * @see org.osgi.util.tracker.BundleTracker#modifiedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
>> + */
>> + @Override
>> + public void modifiedBundle(Bundle b, BundleEvent event, Object object)
>> + {
>> + if (b instanceof CompositeBundle) {
>> + customizedProcessBundle(this, b, event);
>> + } else {
>> + // Delegate to our customizer for normal bundles
>> + if (customizer != null) {
>> + customizer.modifiedBundle(b, event, object);
>> + }
>> + }
>> + }
>> +
>> + /*
>> + * (non-Javadoc)
>> + * @see org.osgi.util.tracker.BundleTracker#removedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
>> + */
>> + @Override
>> + public void removedBundle(Bundle b, BundleEvent event, Object object)
>> + {
>> + if (b instanceof CompositeBundle) {
>> + // We should have already picked up the stopping event on the CBA itself
>> + } else {
>> + if (customizer != null) {
>> + customizer.removedBundle(b, event, object);
>> + }
>> + }
>> + }
>> +
>> + protected void customizedProcessBundle(BundleTrackerCustomizer btc, Bundle b, BundleEvent event)
>> + {
>> + if (b instanceof CompositeBundle) {
>> + CompositeBundle cb = (CompositeBundle) b;
>> + // check if the compositeBundle is already tracked in the
>> + // BundleTrackerFactory
>> + String bundleScope = cb.getSymbolicName() + "_" + cb.getVersion().toString();
>> + List<BundleTracker> btList = BundleTrackerFactory.getBundleTrackerList(bundleScope);
>> +
>> + // bundle is already active and there is no event associated
>> + // this can happen when bundle is first time added to the tracker
>> + if (event == null) {
>> + if (cb.getState() == Bundle.INSTALLED || cb.getState() == Bundle.RESOLVED || cb.getState() == Bundle.STARTING || cb.getState() == Bundle.ACTIVE) {
>> + openTracker(btc, cb, bundleScope, mask);
>> + }
>> + } else {
>> + if (event.getType() == BundleEvent.STOPPING) {
>> + // if CompositeBundle is being stopped, let's remove the bundle
>> + // tracker(s) associated with the composite bundle
>> + BundleContext compositeBundleContext = ((CompositeBundle) b).getCompositeFramework()
>> + .getBundleContext();
>> + alreadyRecursedContexts.remove(compositeBundleContext);
>> + if (btList != null) {
>> + // unregister the bundlescope off the factory and close
>> + // bundle trackers
>> + BundleTrackerFactory.unregisterAndCloseBundleTracker(bundleScope);
>> + }
>> + } else if (event.getType() == BundleEvent.INSTALLED
>> + || event.getType() == BundleEvent.STARTING) {
>> + openTracker(btc, cb, bundleScope, mask);
>> + }
>> + }
>> + }
>> + }
>> +
>> + private synchronized void openTracker(BundleTrackerCustomizer btc, CompositeBundle cb,
>> + String bundleScope, int stateMask)
>> + {
>> + // let's process each of the bundle in the CompositeBundle
>> + BundleContext compositeBundleContext = cb.getCompositeFramework().getBundleContext();
>> + if (!alreadyRecursedContexts.contains(compositeBundleContext)) {
>> + alreadyRecursedContexts.add(compositeBundleContext);
>> +
>> + // let's track each of the bundle in the CompositeBundle
>> + BundleTracker bt = new InternalRecursiveBundleTracker(compositeBundleContext, stateMask,
>> + customizer);
>> + bt.open();
>> + BundleTrackerFactory.registerBundleTracker(bundleScope, bt);
>> + }
>> + }
>> +}
>>
>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
>> ------------------------------------------------------------------------------
>> svn:eol-style = native
>>
>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
>> ------------------------------------------------------------------------------
>> svn:keywords = Date Revision
>>
>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
>> ------------------------------------------------------------------------------
>> svn:mime-type = text/plain
>>
>> Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java?rev=941776&r1=941775&r2=941776&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java (original)
>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/MultiBundleTracker.java Thu May 6 15:22:31 2010
>> @@ -1,136 +0,0 @@
>> -/**
>> - * 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.aries.util.tracker;
>> -
>> -import org.osgi.framework.Bundle;
>> -import org.osgi.framework.BundleContext;
>> -import org.osgi.framework.BundleEvent;
>> -import org.osgi.framework.ServiceReference;
>> -import org.osgi.service.framework.CompositeBundle;
>> -import org.osgi.util.tracker.BundleTracker;
>> -
>> -/**
>> - * <p>This class supports the tracking of composite bundles. It allows clients to ignore any
>> - * events related to framework bundles, as it will automatically handle these events. In
>> - * order to use this class clients must create a subclass and implement the methods of the
>> - * <code>BundleTrackerCustomizer</code> interface. In spite of this, instances of this class
>> - * MUST NOT be passed as a parameter to any <code>BundleTracker</code>.</p>
>> - */
>> -public abstract class MultiBundleTracker extends AbstractBundleTrackerCustomizer {
>> - private static final int COMPOSITE_BUNDLE_MASK =
>> - Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING;
>> -
>> - private final BundleTracker tracker;
>> -
>> - /**
>> - * Constructor
>> - *
>> - * @param context - The <code>BundleContext</code> against which the tracking is done.
>> - * @param stateMask - The bit mask of the ORing of the bundle states to be tracked. The
>> - * mask must contain the flags <code>Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING</code>
>> - * as a minimum.
>> - * @throws IllegalArgumentException - If the provided bit mask does not contain required
>> - * flags
>> - */
>> - public MultiBundleTracker(BundleContext context, int stateMask) {
>> - if ((stateMask & COMPOSITE_BUNDLE_MASK) != COMPOSITE_BUNDLE_MASK)
>> - throw new IllegalArgumentException();
>> -
>> - if (areMultipleFrameworksAvailable(context)) {
>> - tracker = new InternalBundleTracker(context, stateMask);
>> - } else {
>> - tracker = new BundleTracker(context, stateMask, this);
>> - }
>> - }
>> -
>> - private static boolean areMultipleFrameworksAvailable(BundleContext context) {
>> - ServiceReference sr = context.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
>> - return sr != null;
>> - }
>> -
>> - /**
>> - * Start tracking bundles that match the bit mask provided at creation time.
>> - *
>> - * @see BundleTracker#open()
>> - */
>> - public void open() {
>> - tracker.open();
>> - }
>> -
>> - /**
>> - * Stop the tracking of bundles
>> - *
>> - * @see BundleTracker#close()
>> - */
>> - public void close() {
>> - tracker.close();
>> - }
>> -
>> - //This implementation of a BundleTracker is based on the implementation
>> - //in org.apache.aries.util.tracker.AriesBundleTrackerCustomizer
>> - private class InternalBundleTracker extends BundleTracker {
>> - private final int mask;
>> -
>> - public InternalBundleTracker(BundleContext context, int stateMask) {
>> - super(context, stateMask, null);
>> -
>> - mask = stateMask;
>> - }
>> -
>> - /*
>> - * (non-Javadoc)
>> - * @see org.osgi.util.tracker.BundleTracker#addingBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent)
>> - */
>> - public Object addingBundle(Bundle b, BundleEvent event) {
>> - Object o = null;
>> -
>> - if (b instanceof CompositeBundle) {
>> - customizedProcessBundle(this, b, event, mask);
>> - o = b;
>> - }
>> - else {
>> - o = MultiBundleTracker.this.addingBundle(b, event);
>> - }
>> -
>> - return o;
>> - }
>> -
>> - /*
>> - * (non-Javadoc)
>> - * @see org.osgi.util.tracker.BundleTracker#modifiedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
>> - */
>> - public void modifiedBundle(Bundle b, BundleEvent event, Object object) {
>> - if (b instanceof CompositeBundle) {
>> - customizedProcessBundle(this, b, event, mask);
>> - }
>> - else {
>> - MultiBundleTracker.this.modifiedBundle(b, event, object);
>> - }
>> - }
>> -
>> - /*
>> - * (non-Javadoc)
>> - * @see org.osgi.util.tracker.BundleTracker#removedBundle(org.osgi.framework.Bundle, org.osgi.framework.BundleEvent, java.lang.Object)
>> - */
>> - public void removedBundle(Bundle b, BundleEvent event, Object object) {
>> - if (!(b instanceof CompositeBundle))
>> - MultiBundleTracker.this.removedBundle(b, event, object);
>> - }
>> - }
>> -}
>>
>> Added: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java?rev=941776&view=auto
>> ==============================================================================
>> --- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java (added)
>> +++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java Thu May 6 15:22:31 2010
>> @@ -0,0 +1,89 @@
>> +/**
>> + * 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.aries.util.tracker;
>> +
>> +import org.osgi.framework.Bundle;
>> +import org.osgi.framework.BundleContext;
>> +import org.osgi.framework.ServiceReference;
>> +import org.osgi.util.tracker.BundleTracker;
>> +import org.osgi.util.tracker.BundleTrackerCustomizer;
>> +
>> +/**
>> + * <p>This class supports the tracking of composite bundles. It allows clients to ignore any
>> + * events related to framework bundles, as it will automatically handle these events. In
>> + * order to use this class clients must create a subclass and implement the methods of the
>> + * <code>BundleTrackerCustomizer</code> interface. In spite of this, instances of this class
>> + * MUST NOT be passed as a parameter to any <code>BundleTracker</code>.</p>
>> + *
>> + * The model for using this is that classes should instantiate it
>> + * and pass it a 'vanilla' bundle tracker.
>> + * @author pradine
>> + *
>> + */
>> +public final class RecursiveBundleTracker {
>> + private static final int COMPOSITE_BUNDLE_MASK =
>> + Bundle.INSTALLED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING;
>> +
>> + private final BundleTracker tracker;
>> +
>> + /**
>> + * Constructor
>> + *
>> + * @param context - The <code>BundleContext</code> against which the tracking is done.
>> + * @param stateMask - The bit mask of the ORing of the bundle states to be tracked. The
>> + * mask must contain the flags <code>Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING</code>
>> + * as a minimum.
>> + * @throws IllegalArgumentException - If the provided bit mask does not contain required
>> + * flags
>> + */
>> + public RecursiveBundleTracker(BundleContext context, int stateMask, BundleTrackerCustomizer customizer) {
>> + // We always need INSTALLED events so we can recursively listen to the frameworks
>> + if ((stateMask & COMPOSITE_BUNDLE_MASK) != COMPOSITE_BUNDLE_MASK)
>> + throw new IllegalArgumentException();
>> + if (areMultipleFrameworksAvailable(context)) {
>> + tracker = new InternalRecursiveBundleTracker(context, stateMask, customizer);
>> + } else {
>> + tracker = new BundleTracker(context, stateMask, customizer);
>> + }
>> + }
>> +
>> + private static boolean areMultipleFrameworksAvailable(BundleContext context) {
>> + ServiceReference sr = context.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
>> + return sr != null;
>> + }
>> +
>> + /**
>> + * Start tracking bundles that match the bit mask provided at creation time.
>> + *
>> + * @see BundleTracker#open()
>> + */
>> + public void open() {
>> + tracker.open();
>> + }
>> +
>> + /**
>> + * Stop the tracking of bundles
>> + *
>> + * @see BundleTracker#close()
>> + */
>> + public void close() {
>> + tracker.close();
>> + }
>> +
>> +}
>>
>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
>> ------------------------------------------------------------------------------
>> svn:eol-style = native
>>
>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
>> ------------------------------------------------------------------------------
>> svn:keywords = Date Revision
>>
>> Propchange: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
>> ------------------------------------------------------------------------------
>> svn:mime-type = text/plain
>>
>>
>>
>