commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ales Dolecek (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CHAIN-62) Use of thread context ClassLoader under OSGi
Date Tue, 10 Jan 2012 15:33:39 GMT

    [ https://issues.apache.org/jira/browse/CHAIN-62?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13183335#comment-13183335
] 

Ales Dolecek commented on CHAIN-62:
-----------------------------------

What about following patch?

Index: src/main/java/org/apache/commons/chain/CatalogFactory.java
===================================================================
--- src/main/java/org/apache/commons/chain/CatalogFactory.java  (revision 1229598)
+++ src/main/java/org/apache/commons/chain/CatalogFactory.java  (working copy)
@@ -49,6 +49,11 @@
     public static final String DELIMITER = ":";


+    /**
+     * Default catalog factory to use.
+     */
+    public static CatalogFactory INSTANCE;
+
     // --------------------------------------------------------- Public Methods


@@ -178,17 +183,20 @@


     /**
-     * <p>Return the singleton {@link CatalogFactory} instance
-     * for the relevant <code>ClassLoader</code>.  For applications
-     * that use a thread context class loader (such as web applications
-     * running inside a servet container), this will return a separate
-     * instance for each application, even if this class is loaded from
+     * <p>Returns the {@link #INSTANCE} is set. Otherwise returns singleton
+     * {@link CatalogFactory} instance for the relevant <code>ClassLoader</code>.
+     * For applications that use a thread context class loader (such as web
+     * applications running inside a servet container), this will return a
+     * separate instance for each application, even if this class is loaded from
      * a shared parent class loader.</p>
      *
      * @return the per-application singleton instance of {@link CatalogFactory}
      */
     public static CatalogFactory getInstance() {

+        if (INSTANCE != null)
+            return INSTANCE;
+
         CatalogFactory factory = null;
         ClassLoader cl = getClassLoader();
         synchronized (factories) {
                
> Use of thread context ClassLoader under OSGi
> --------------------------------------------
>
>                 Key: CHAIN-62
>                 URL: https://issues.apache.org/jira/browse/CHAIN-62
>             Project: Commons Chain
>          Issue Type: Bug
>    Affects Versions: 1.2
>         Environment: OSGi
>            Reporter: Ales Dolecek
>            Priority: Minor
>
> The CatalogFactory#getInstance() is using thread context ClassLoader which gives undefined
behavior under OSGi.
> This leads to problems with ConfigCatalogRule and especislly LookupCommand.
> Two bundles wired to same commons chain may use different catalog factories when parsing
commands from XML or looking up commands from catalog.
> I think that CatalogFactory#getClassLoader() might allow disabling use of thread context
class loader - either
> a) detect that it is used inside OSGi framework, or
> b) provide static boolean flag to disable it
> Combination of both might be via use of bundle activator that would set the flag. The
activator would be used only under OSGi acting as "auto-detection" and still some other bundle
might revert to default if required.
> Ales

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message