You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/09/24 06:41:05 UTC
svn commit: r818366 - in /camel/branches/camel-1.x: ./
components/camel-osgi/src/main/java/org/apache/camel/osgi/
components/camel-osgi/src/main/java/org/apache/camel/osgi/tracker/
Author: ningjiang
Date: Thu Sep 24 04:41:04 2009
New Revision: 818366
URL: http://svn.apache.org/viewvc?rev=818366&view=rev
Log:
Merged revisions 818182,818354 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r818182 | gnodet | 2009-09-24 02:07:38 +0800 (Thu, 24 Sep 2009) | 1 line
The current activator use excessive synchronization which leads to deadlocks in osgi
........
r818354 | ningjiang | 2009-09-24 11:22:21 +0800 (Thu, 24 Sep 2009) | 1 line
Fixed the CS errors of camel-osgi
........
Added:
camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/tracker/
- copied from r818354, camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/tracker/
camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/tracker/AbstractTracked.java
- copied unchanged from r818354, camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/tracker/AbstractTracked.java
camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/tracker/BundleTracker.java
- copied unchanged from r818354, camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/tracker/BundleTracker.java
camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/tracker/BundleTrackerCustomizer.java
- copied unchanged from r818354, camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/tracker/BundleTrackerCustomizer.java
Modified:
camel/branches/camel-1.x/ (props changed)
camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Sep 24 04:41:04 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143,779489,781314-781349,781775,781
923,781974,781993,782557,782594,782681,782886,782918-782923,783204,783248,783363,783639,783704,785564,785584,785599,787206,787581,787598,787605,787928,788393,789121,789703,790560,790936,791379,791476,791767,792038,792381,792398,792899,793359,793518,793547-793555,793862,793935,794237,794368,794550,794967,795790,798027,798052,798063,798489,798864,799252,800340,800785,800797,801960,802307,802478,803559,807476,810751,812937,814493,816105,817654,818063
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143,779489,781314-781349,781775,781
923,781974,781993,782557,782594,782681,782886,782918-782923,783204,783248,783363,783639,783704,785564,785584,785599,787206,787581,787598,787605,787928,788393,789121,789703,790560,790936,791379,791476,791767,792038,792381,792398,792899,793359,793518,793547-793555,793862,793935,794237,794368,794550,794967,795790,798027,798052,798063,798489,798864,799252,800340,800785,800797,801960,802307,802478,803559,807476,810751,812937,814493,816105,817654,818063,818182-818354
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java?rev=818366&r1=818365&r2=818366&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java (original)
+++ camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java Thu Sep 24 04:41:04 2009
@@ -23,15 +23,17 @@
import java.net.URL;
import java.util.Collection;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.camel.Component;
import org.apache.camel.TypeConverter;
+import org.apache.camel.osgi.tracker.BundleTracker;
+import org.apache.camel.osgi.tracker.BundleTrackerCustomizer;
import org.apache.camel.spi.Language;
import org.apache.camel.spi.LanguageResolver;
import org.apache.camel.util.ObjectHelper;
@@ -44,19 +46,21 @@
import org.osgi.framework.SynchronousBundleListener;
import org.springframework.osgi.util.BundleDelegatingClassLoader;
-public class Activator implements BundleActivator, SynchronousBundleListener {
+public class Activator implements BundleActivator, BundleTrackerCustomizer {
public static final String META_INF_TYPE_CONVERTER = "META-INF/services/org/apache/camel/TypeConverter";
public static final String META_INF_COMPONENT = "META-INF/services/org/apache/camel/component/";
public static final String META_INF_LANGUAGE = "META-INF/services/org/apache/camel/language/";
public static final String META_INF_LANGUAGE_RESOLVER = "META-INF/services/org/apache/camel/language/resolver/";
private static final transient Log LOG = LogFactory.getLog(Activator.class);
- private static final Map<String, ComponentEntry> COMPONENTS = new HashMap<String, ComponentEntry>();
- private static final Map<URL, TypeConverterEntry> TYPE_CONVERTERS = new HashMap<URL, TypeConverterEntry>();
- private static final Map<String, ComponentEntry> LANGUAGES = new HashMap<String, ComponentEntry>();
- private static final Map<String, ComponentEntry> LANGUAGE_RESOLVERS = new HashMap<String, ComponentEntry>();
+ private static final Map<String, ComponentEntry> COMPONENTS = new ConcurrentHashMap<String, ComponentEntry>();
+ private static final Map<URL, TypeConverterEntry> TYPE_CONVERTERS = new ConcurrentHashMap<URL, TypeConverterEntry>();
+ private static final Map<String, ComponentEntry> LANGUAGES = new ConcurrentHashMap<String, ComponentEntry>();
+ private static final Map<String, ComponentEntry> LANGUAGE_RESOLVERS = new ConcurrentHashMap<String, ComponentEntry>();
private static Bundle bundle;
+ private BundleTracker tracker;
+
private class ComponentEntry {
Bundle bundle;
String path;
@@ -70,32 +74,28 @@
Set<String> converterPackages;
}
- public void bundleChanged(BundleEvent event) {
- if (LOG.isTraceEnabled()) {
- LOG.trace("Bundle changed: " + event);
+ public Object addingBundle(Bundle bundle, BundleEvent event) {
+ modifiedBundle(bundle, event, null);
+ return bundle;
+ }
+
+ public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Bundle started: " + bundle.getSymbolicName());
}
+ mayBeAddComponentAndLanguageFor(bundle);
+ mayBeAddTypeConverterFor(bundle);
+ }
- try {
- Bundle bundle = event.getBundle();
- if (event.getType() == BundleEvent.RESOLVED) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Bundle resolved: " + bundle.getSymbolicName());
- }
- mayBeAddComponentAndLanguageFor(bundle);
- mayBeAddTypeConverterFor(bundle);
- } else if (event.getType() == BundleEvent.UNRESOLVED) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Bundle unresolved: " + bundle.getSymbolicName());
- }
- mayBeRemoveComponentAndLanguageFor(bundle);
- mayBeRemoveTypeConverterFor(bundle);
- }
- } catch (Throwable e) {
- LOG.fatal("Exception occured during bundleChanged for event: " + event, e);
+ public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Bundle stopped: " + bundle.getSymbolicName());
}
+ mayBeRemoveComponentAndLanguageFor(bundle);
+ mayBeRemoveTypeConverterFor(bundle);
}
- protected synchronized void addComponentEntry(String entryPath, Bundle bundle, Map<String, ComponentEntry> entries, Class clazz) {
+ protected void addComponentEntry(String entryPath, Bundle bundle, Map<String, ComponentEntry> entries, Class clazz) {
// Check bundle compatibility
try {
if (bundle.loadClass(clazz.getName()) != clazz) {
@@ -127,7 +127,7 @@
addComponentEntry(META_INF_LANGUAGE_RESOLVER, bundle, LANGUAGE_RESOLVERS, LanguageResolver.class);
}
- protected synchronized void mayBeAddTypeConverterFor(Bundle bundle) {
+ protected void mayBeAddTypeConverterFor(Bundle bundle) {
// Check bundle compatibility
try {
Class clazz = TypeConverter.class;
@@ -175,7 +175,7 @@
}
}
- protected synchronized void mayBeRemoveTypeConverterFor(Bundle bundle) {
+ protected void mayBeRemoveTypeConverterFor(Bundle bundle) {
TypeConverterEntry[] entriesArray = TYPE_CONVERTERS.values().toArray(new TypeConverterEntry[0]);
for (TypeConverterEntry entry : entriesArray) {
if (entry.bundle == bundle) {
@@ -194,19 +194,9 @@
if (LOG.isDebugEnabled()) {
LOG.debug("Using bundle: " + bundle);
}
- context.addBundleListener(this);
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("Checking existing bundles for Camel components, languages and type converters");
- }
- for (Bundle bundle : context.getBundles()) {
- if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING
- || bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) {
- mayBeAddComponentAndLanguageFor(bundle);
- mayBeAddTypeConverterFor(bundle);
- }
- }
+ tracker = new BundleTracker(context, Bundle.ACTIVE, this);
+ tracker.open();
LOG.info("Camel activator started");
}
@@ -216,14 +206,7 @@
if (LOG.isDebugEnabled()) {
LOG.debug("Removing Camel bundles");
}
- for (Bundle bundle : context.getBundles()) {
- if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING
- || bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) {
- mayBeRemoveComponentAndLanguageFor(bundle);
- mayBeRemoveTypeConverterFor(bundle);
- }
- }
-
+ tracker.close();
LOG.info("Camel activator stopped");
}
@@ -269,27 +252,27 @@
return bundle;
}
- protected static synchronized TypeConverterEntry[] getTypeConverterEntries() {
+ protected static TypeConverterEntry[] getTypeConverterEntries() {
Collection<TypeConverterEntry> entries = TYPE_CONVERTERS.values();
return entries.toArray(new TypeConverterEntry[entries.size()]);
}
- public static synchronized Class getComponent(String name) throws Exception {
+ public static Class getComponent(String name) throws Exception {
LOG.trace("Finding Component: " + name);
return getClassFromEntries(name, COMPONENTS);
}
- public static synchronized Class getLanguage(String name) throws Exception {
+ public static Class getLanguage(String name) throws Exception {
LOG.trace("Finding Language: " + name);
return getClassFromEntries(name, LANGUAGES);
}
- public static synchronized Class getLanguageResolver(String name) throws Exception {
+ public static Class getLanguageResolver(String name) throws Exception {
LOG.trace("Finding LanguageResolver: " + name);
return getClassFromEntries(name, LANGUAGE_RESOLVERS);
}
- protected static synchronized Class getClassFromEntries(String name, Map<String, ComponentEntry> entries) throws Exception {
+ protected static Class getClassFromEntries(String name, Map<String, ComponentEntry> entries) throws Exception {
ComponentEntry entry = entries.get(name);
if (entry == null) {
return null;