You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Ales Dolecek (Updated) (JIRA)" <ji...@apache.org> on 2012/01/10 16:33:39 UTC

[jira] [Updated] (CHAIN-62) Use of thread context ClassLoader under OSGi

     [ https://issues.apache.org/jira/browse/CHAIN-62?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ales Dolecek updated CHAIN-62:
------------------------------

    Comment: was deleted

(was: 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