You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2018/02/21 09:05:57 UTC

svn commit: r1824949 - in /aries/trunk/jndi: jndi-core/ jndi-core/src/main/java/org/apache/aries/jndi/ jndi-core/src/main/java/org/apache/aries/jndi/startup/ jndi-core/src/main/resources/org/apache/aries/jndi/nls/ jndi-rmi/ jndi-rmi/src/main/java/org/a...

Author: gnodet
Date: Wed Feb 21 09:05:56 2018
New Revision: 1824949

URL: http://svn.apache.org/viewvc?rev=1824949&view=rev
Log:
[ARIES-1786] Remove dependency on aries util

Added:
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/SingleServiceTracker.java
Removed:
    aries/trunk/jndi/jndi-core/src/main/resources/org/apache/aries/jndi/nls/jndiMessages.properties
    aries/trunk/jndi/jndi-rmi/src/main/resources/org/apache/aries/jndi/nls/jndiRmiMessages.properties
    aries/trunk/jndi/jndi-url/src/main/resources/org/apache/aries/jndi/nls/jndiUrlMessages.properties
Modified:
    aries/trunk/jndi/jndi-core/pom.xml
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java
    aries/trunk/jndi/jndi-rmi/pom.xml
    aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java
    aries/trunk/jndi/jndi-url/pom.xml
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java
    aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/BlueprintURLContextTest.java
    aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java
    aries/trunk/jndi/parent/pom.xml

Modified: aries/trunk/jndi/jndi-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/pom.xml?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/pom.xml (original)
+++ aries/trunk/jndi/jndi-core/pom.xml Wed Feb 21 09:05:56 2018
@@ -75,10 +75,6 @@
             <version>${jndi-api.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.aries</groupId>
-            <artifactId>org.apache.aries.util</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>osgi.core</artifactId>
             <scope>provided</scope>

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java Wed Feb 21 09:05:56 2018
@@ -126,7 +126,7 @@ public final class ContextHelper {
             if (contextFactoryClass == null) {
                 return new DelegateContext(context, environment);
             } else {
-                throw new NoInitialContextException(Utils.MESSAGES.getMessage("no.initial.context.factory", contextFactoryClass));
+                throw new NoInitialContextException("Unable to find the InitialContextFactory " + contextFactoryClass + ".");
             }
         }
     }

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java Wed Feb 21 09:05:56 2018
@@ -39,7 +39,7 @@ public class OSGiInitialContextFactoryBu
         Activator.getAugmenterInvoker().augmentEnvironment(environment);
         BundleContext context = Utils.getBundleContext(environment, InitialContext.class);
         if (context == null) {
-            throw new NoInitialContextException(Utils.MESSAGES.getMessage("cannot.find.callers.bundlecontext"));
+            throw new NoInitialContextException("The calling code's BundleContext could not be determined.");
         }
         Activator.getAugmenterInvoker().unaugmentEnvironment(environment);
         return ContextHelper.getInitialContext(context, environment);

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java Wed Feb 21 09:05:56 2018
@@ -18,7 +18,6 @@
  */
 package org.apache.aries.jndi;
 
-import org.apache.aries.util.nls.MessageUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -42,8 +41,6 @@ import java.util.function.Supplier;
  */
 public final class Utils {
 
-    public static final MessageUtil MESSAGES = MessageUtil.createMessageUtil(Utils.class, "org.apache.aries.jndi.nls.jndiMessages");
-
     /**
      * Ensure no one constructs us
      */

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java Wed Feb 21 09:05:56 2018
@@ -151,12 +151,15 @@ public class Activator implements Bundle
             }
             icfBuilder = builder;
         } catch (NamingException e) {
-            LOGGER.debug(Utils.MESSAGES.getMessage("unable.to.set.static.ICFB"), e);
+            LOGGER.debug("A failure occurred when attempting to register an InitialContextFactoryBuilder with the NamingManager. " +
+                         "Support for calling new InitialContext() will not be enabled.", e);
         } catch (IllegalStateException e) {
             // Log the problem at info level, but only log the exception at debug level, as in many cases this is not a real issue and people
             // don't want to see stack traces at info level when everything it working as expected.
-            LOGGER.info(Utils.MESSAGES.getMessage("unable.to.set.static.ICFB.already.exists", getClassName(InitialContextFactoryBuilder.class)));
-            LOGGER.debug(Utils.MESSAGES.getMessage("unable.to.set.static.ICFB.already.exists", getClassName(InitialContextFactoryBuilder.class)), e);
+            String msg = "It was not possible to register an InitialContextFactoryBuilder with the NamingManager because " +
+                         "another builder called " + getClassName(InitialContextFactoryBuilder.class) + " was already registered. Support for calling new InitialContext() will not be enabled.";
+            LOGGER.info(msg);
+            LOGGER.debug(msg, e);
         }
 
         try {
@@ -171,12 +174,15 @@ public class Activator implements Bundle
             }
             ofBuilder = builder;
         } catch (NamingException e) {
-            LOGGER.info(Utils.MESSAGES.getMessage("unable.to.set.static.OFB"), e);
+            LOGGER.info("A failure occurred when attempting to register an ObjectFactoryBuilder with the NamingManager. " +
+                        "Looking up certain objects may not work correctly.", e);
         } catch (IllegalStateException e) {
             // Log the problem at info level, but only log the exception at debug level, as in many cases this is not a real issue and people
             // don't want to see stack traces at info level when everything it working as expected.
-            LOGGER.info(Utils.MESSAGES.getMessage("unable.to.set.static.OFB.already.exists", getClassName(ObjectFactoryBuilder.class)));
-            LOGGER.debug(Utils.MESSAGES.getMessage("unable.to.set.static.OFB.already.exists", getClassName(ObjectFactoryBuilder.class)), e);
+            String msg = "It was not possible to register an ObjectFactoryBuilder with the NamingManager because " +
+                         "another builder called " + getClassName(ObjectFactoryBuilder.class) + " was already registered. Looking up certain objects may not work correctly.";
+            LOGGER.info(msg);
+            LOGGER.debug(msg, e);
         }
 
         context.registerService(JNDIProviderAdmin.class.getName(),

Modified: aries/trunk/jndi/jndi-rmi/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-rmi/pom.xml?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-rmi/pom.xml (original)
+++ aries/trunk/jndi/jndi-rmi/pom.xml Wed Feb 21 09:05:56 2018
@@ -73,10 +73,6 @@
             <version>${jndi-api.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.aries</groupId>
-            <artifactId>org.apache.aries.util</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>osgi.core</artifactId>
             <scope>provided</scope>

Modified: aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java (original)
+++ aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java Wed Feb 21 09:05:56 2018
@@ -18,8 +18,6 @@
  */
 package org.apache.aries.jndi.rmi;
 
-import org.apache.aries.util.AriesFrameworkUtil;
-import org.apache.aries.util.nls.MessageUtil;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -28,7 +26,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.naming.spi.ObjectFactory;
-import java.util.Dictionary;
 import java.util.Hashtable;
 
 public class Activator implements BundleActivator {
@@ -41,20 +38,29 @@ public class Activator implements Bundle
         LOGGER.debug("Registering RMI url handler");
 
         try {
-            Hashtable<Object, Object> props = new Hashtable<Object, Object>();
+            Hashtable<String, Object> props = new Hashtable<>();
             props.put(JNDIConstants.JNDI_URLSCHEME, new String[]{"rmi"});
             reg = context.registerService(
                     ObjectFactory.class.getName(),
                     ClassLoader.getSystemClassLoader().loadClass("com.sun.jndi.url.rmi.rmiURLContextFactory").newInstance(),
-                    (Dictionary) props);
+                    props);
         } catch (Exception e) {
-            MessageUtil msg = MessageUtil.createMessageUtil(Activator.class, "org.apache.aries.jndi.nls.jndiRmiMessages");
-            LOGGER.info(msg.getMessage("rmi.factory.creation.failed"), e);
+            LOGGER.info("A failure occurred while attempting to create the handler for the rmi JNDI URL scheme.", e);
         }
     }
 
     public void stop(BundleContext context) {
-        AriesFrameworkUtil.safeUnregisterService(reg);
+        safeUnregisterService(reg);
+    }
+
+    private static void safeUnregisterService(ServiceRegistration reg) {
+        if (reg != null) {
+            try {
+                reg.unregister();
+            } catch (IllegalStateException e) {
+                //This can be safely ignored
+            }
+        }
     }
 
 }

Modified: aries/trunk/jndi/jndi-url/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/pom.xml?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/pom.xml (original)
+++ aries/trunk/jndi/jndi-url/pom.xml Wed Feb 21 09:05:56 2018
@@ -91,10 +91,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.aries</groupId>
-            <artifactId>org.apache.aries.util</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.apache.aries.proxy</groupId>
             <artifactId>org.apache.aries.proxy.api</artifactId>
         </dependency>

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java (original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java Wed Feb 21 09:05:56 2018
@@ -22,7 +22,6 @@ import org.apache.aries.jndi.url.Activat
 import org.apache.aries.jndi.url.OsgiName;
 import org.apache.aries.proxy.ProxyManager;
 import org.apache.aries.proxy.UnableToProxyException;
-import org.apache.aries.util.nls.MessageUtil;
 import org.osgi.framework.*;
 import org.osgi.service.jndi.JNDIConstants;
 
@@ -54,7 +53,6 @@ public final class ServiceHelper {
      */
     private static final ConcurrentMap<ServiceKey, WeakReference<Object>> proxyCache = new ConcurrentHashMap<>();
     private static final CacheClearoutListener cacheClearoutListener = new CacheClearoutListener(proxyCache);
-    private static final MessageUtil MESSAGES = MessageUtil.createMessageUtil(ServiceHelper.class, "org.apache.aries.jndi.nls.jndiUrlMessages");
 
     public static Object getService(BundleContext ctx, OsgiName lookupName, String id,
                                     boolean dynamicRebind, Map<String, Object> env, boolean requireProxy) throws NamingException {
@@ -214,7 +212,7 @@ public final class ServiceHelper {
         } catch (UnableToProxyException e) {
             throw new IllegalArgumentException(e);
         } catch (RuntimeException e) {
-            throw new IllegalArgumentException(MESSAGES.getMessage("unable.to.create.proxy", pair.ref), e);
+            throw new IllegalArgumentException("Unable to create a proxy for " + pair.ref + ".", e);
         }
     }
 

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java (original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java Wed Feb 21 09:05:56 2018
@@ -19,11 +19,9 @@
 package org.apache.aries.jndi.url;
 
 import org.apache.aries.proxy.ProxyManager;
-import org.apache.aries.util.AriesFrameworkUtil;
-import org.apache.aries.util.tracker.SingleServiceTracker;
-import org.apache.aries.util.tracker.SingleServiceTracker.SingleServiceListener;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.jndi.JNDIConstants;
 
@@ -32,20 +30,20 @@ import java.util.Hashtable;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-public class Activator implements BundleActivator, SingleServiceListener {
+public class Activator implements BundleActivator {
     private static SingleServiceTracker<ProxyManager> proxyManager;
     private BundleContext ctx;
-    private volatile ServiceRegistration osgiUrlReg = null;
-    private volatile ServiceRegistration blueprintUrlReg = null;
+    private volatile ServiceRegistration<?> osgiUrlReg = null;
+    private volatile ServiceRegistration<?> blueprintUrlReg = null;
 
     public static ProxyManager getProxyManager() {
         return proxyManager == null ? null : proxyManager.getService();
     }
 
     @Override
-    public void start(BundleContext context) {
+    public void start(BundleContext context) throws InvalidSyntaxException {
         ctx = context;
-        proxyManager = new SingleServiceTracker<>(context, ProxyManager.class, this);
+        proxyManager = new SingleServiceTracker<>(context, ProxyManager.class, this::serviceChanged);
         proxyManager.open();
         // Blueprint URL scheme requires access to the BlueprintContainer service.
         // We have an optional import
@@ -68,26 +66,30 @@ public class Activator implements Bundle
     @Override
     public void stop(BundleContext context) {
         proxyManager.close();
-        AriesFrameworkUtil.safeUnregisterService(osgiUrlReg);
-        AriesFrameworkUtil.safeUnregisterService(blueprintUrlReg);
+        safeUnregisterService(osgiUrlReg);
+        safeUnregisterService(blueprintUrlReg);
     }
 
-    @Override
-    public void serviceFound() {
-        Hashtable<String, Object> osgiUrlprops = new Hashtable<>();
-        osgiUrlprops.put(JNDIConstants.JNDI_URLSCHEME, new String[]{"osgi", "aries"});
-        osgiUrlReg = ctx.registerService(ObjectFactory.class.getName(),
-                new OsgiURLContextServiceFactory(), osgiUrlprops);
+    void serviceChanged(ProxyManager oldPm, ProxyManager newPm) {
+        if (newPm == null) {
+            safeUnregisterService(osgiUrlReg);
+            osgiUrlReg = null;
+        } else {
+            Hashtable<String, Object> osgiUrlprops = new Hashtable<>();
+            osgiUrlprops.put(JNDIConstants.JNDI_URLSCHEME, new String[]{"osgi", "aries"});
+            osgiUrlReg = ctx.registerService(ObjectFactory.class.getName(),
+                    new OsgiURLContextServiceFactory(), osgiUrlprops);
+        }
     }
 
-    @Override
-    public void serviceLost() {
-        AriesFrameworkUtil.safeUnregisterService(osgiUrlReg);
-        osgiUrlReg = null;
+    private static void safeUnregisterService(ServiceRegistration<?> reg) {
+        if (reg != null) {
+            try {
+                reg.unregister();
+            } catch (IllegalStateException e) {
+                //This can be safely ignored
+            }
+        }
     }
 
-    @Override
-    public void serviceReplaced() {
-
-    }
 }
\ No newline at end of file

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java (original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java Wed Feb 21 09:05:56 2018
@@ -19,7 +19,6 @@
 
 package org.apache.aries.jndi.url;
 
-import org.apache.aries.util.nls.MessageUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
@@ -40,7 +39,6 @@ public class BlueprintURLContext impleme
     static final Pattern graceP = Pattern.compile(".*;\\s*blueprint.graceperiod\\s*:=\\s*\"?([A-Za-z]+).*");
     static final Pattern timeoutP = Pattern.compile(".*;\\s*blueprint.timeout\\s*:=\\s*\"?([0-9]+).*");
     private static final String BLUEPRINT_NAMESPACE = "blueprint:comp/";
-    private static final MessageUtil MESSAGES = MessageUtil.createMessageUtil(BlueprintURLContext.class, "org.apache.aries.jndi.nls.jndiUrlMessages");
     private Bundle _callersBundle;
     private Map<String, Object> _env;
     private NameParser _parser = new BlueprintNameParser();
@@ -124,7 +122,7 @@ public class BlueprintURLContext impleme
             st.close();
         }
         if (result == null) {
-            throw new ServiceUnavailableException(MESSAGES.getMessage("no.blueprint.container", b.getSymbolicName() + '/' + b.getVersion()));
+            throw new ServiceUnavailableException("The BlueprintContainer service for bundle " + b.getSymbolicName() + '/' + b.getVersion() + " can not be located");
         }
         return result;
     }

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java (original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java Wed Feb 21 09:05:56 2018
@@ -19,7 +19,6 @@
 package org.apache.aries.jndi.url;
 
 import org.apache.aries.jndi.services.ServiceHelper;
-import org.apache.aries.util.nls.MessageUtil;
 import org.osgi.framework.AdminPermission;
 import org.osgi.framework.BundleContext;
 
@@ -33,7 +32,6 @@ import java.util.Map;
  * A JNDI context for looking stuff up from the service registry.
  */
 public class ServiceRegistryContext extends AbstractServiceRegistryContext implements Context {
-    private static final MessageUtil MESSAGES = MessageUtil.createMessageUtil(ServiceRegistryContext.class, "org.apache.aries.jndi.nls.jndiUrlMessages");
     /**
      * The parent name, if one is provided, of this context
      */
@@ -87,7 +85,7 @@ public class ServiceRegistryContext exte
                     AccessController.checkPermission(adminPermission);
                     return callerContext;
                 } catch (AccessControlException accessControlException) {
-                    NamingException namingException = new NameNotFoundException(MESSAGES.getMessage("caller.not.priviledged"));
+                    NamingException namingException = new NameNotFoundException("The Caller does not have permissions to get the BundleContext.");
                     namingException.setRootCause(accessControlException);
                     throw namingException;
                 }

Added: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/SingleServiceTracker.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/SingleServiceTracker.java?rev=1824949&view=auto
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/SingleServiceTracker.java (added)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/SingleServiceTracker.java Wed Feb 21 09:05:56 2018
@@ -0,0 +1,171 @@
+/*
+ * 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.jndi.url;
+
+import org.osgi.framework.*;
+
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+
+//This is from aries util
+public final class SingleServiceTracker<T> implements ServiceListener {
+
+    private final BundleContext ctx;
+    private final String className;
+    private final AtomicReference<T> service = new AtomicReference<>();
+    private final AtomicReference<ServiceReference> ref = new AtomicReference<>();
+    private final AtomicBoolean open = new AtomicBoolean(false);
+    private final BiConsumer<T, T> serviceListener;
+    private final String filterString;
+    private final Filter filter;
+
+    public SingleServiceTracker(BundleContext context, Class<T> clazz, BiConsumer<T, T> sl) throws InvalidSyntaxException {
+        this(context, clazz, null, sl);
+    }
+
+    public SingleServiceTracker(BundleContext context, Class<T> clazz, String filterString, BiConsumer<T, T> sl) throws InvalidSyntaxException {
+        this(context, clazz.getName(), filterString, sl);
+    }
+
+    public SingleServiceTracker(BundleContext context, String className, String filterString, BiConsumer<T, T> sl) throws InvalidSyntaxException {
+        this.ctx = context;
+        this.className = className;
+        this.serviceListener = sl;
+        if (filterString == null || filterString.isEmpty()) {
+            this.filterString = null;
+            this.filter = null;
+        } else {
+            this.filterString = filterString;
+            this.filter = context.createFilter(filterString);
+        }
+    }
+
+    public T getService() {
+        return service.get();
+    }
+
+    public ServiceReference getServiceReference() {
+        return ref.get();
+    }
+
+    public void open() {
+        if (open.compareAndSet(false, true)) {
+            try {
+                String filterString = '(' + Constants.OBJECTCLASS + '=' + className + ')';
+                if (filter != null) filterString = "(&" + filterString + filter + ')';
+                ctx.addServiceListener(this, filterString);
+                findMatchingReference(null);
+            } catch (InvalidSyntaxException e) {
+                // this can never happen. (famous last words :)
+            }
+        }
+    }
+
+    public void serviceChanged(ServiceEvent event) {
+        if (open.get()) {
+            if (event.getType() == ServiceEvent.UNREGISTERING) {
+                ServiceReference deadRef = event.getServiceReference();
+                if (deadRef.equals(ref.get())) {
+                    findMatchingReference(deadRef);
+                }
+            } else if (event.getType() == ServiceEvent.REGISTERED && ref.get() == null) {
+                findMatchingReference(null);
+            }
+        }
+    }
+
+    private void findMatchingReference(ServiceReference original) {
+        try {
+            boolean clear = true;
+            ServiceReference[] refs = ctx.getServiceReferences(className, filterString);
+            if (refs != null && refs.length > 0) {
+                if (refs.length > 1) {
+                    Arrays.sort(refs);
+                }
+                @SuppressWarnings("unchecked")
+                T service = (T) ctx.getService(refs[0]);
+                if (service != null) {
+                    clear = false;
+
+                    // We do the unget out of the lock so we don't exit this class while holding a lock.
+                    if (!update(original, refs[0], service)) {
+                        ctx.ungetService(refs[0]);
+                    }
+                }
+            } else if (original == null) {
+                clear = false;
+            }
+
+            if (clear) {
+                update(original, null, null);
+            }
+        } catch (InvalidSyntaxException e) {
+            // this can never happen. (famous last words :)
+        }
+    }
+
+    private boolean update(ServiceReference deadRef, ServiceReference newRef, T service) {
+        boolean result = false;
+        T prev = null;
+
+        // Make sure we don't try to get a lock on null
+        Object lock;
+
+        // we have to choose our lock.
+        if (newRef != null) lock = newRef;
+        else if (deadRef != null) lock = deadRef;
+        else lock = this;
+
+        // This lock is here to ensure that no two threads can set the ref and service
+        // at the same time.
+        synchronized (lock) {
+            if (open.get()) {
+                result = this.ref.compareAndSet(deadRef, newRef);
+                if (result) {
+                    prev = this.service.getAndSet(service);
+                }
+            }
+        }
+
+        if (result && serviceListener != null) {
+            serviceListener.accept(prev, service);
+        }
+
+        return result;
+    }
+
+    public void close() {
+        if (open.compareAndSet(true, false)) {
+            ctx.removeServiceListener(this);
+
+            ServiceReference deadRef;
+            T prev;
+            synchronized (this) {
+                deadRef = ref.getAndSet(null);
+                prev = service.getAndSet(null);
+            }
+            if (deadRef != null) {
+                serviceListener.accept(prev, null);
+                ctx.ungetService(deadRef);
+            }
+        }
+    }
+}

Modified: aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/BlueprintURLContextTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/BlueprintURLContextTest.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/BlueprintURLContextTest.java (original)
+++ aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/BlueprintURLContextTest.java Wed Feb 21 09:05:56 2018
@@ -22,6 +22,9 @@ package org.apache.aries.jndi.url;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -38,6 +41,7 @@ import javax.naming.NamingException;
 
 import org.apache.aries.mocks.BundleContextMock;
 import org.apache.aries.mocks.BundleMock;
+import org.apache.aries.proxy.ProxyManager;
 import org.apache.aries.unittest.mocks.Skeleton;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -95,13 +99,17 @@ public class BlueprintURLContextTest {
   
   
   @BeforeClass
-  public static void setup() { 
+  public static void setup() throws Exception {
     bundle = Skeleton.newMock(new BundleMock("aBundle", new Hashtable<String, String>()), Bundle.class);
     BundleContext bc = bundle.getBundleContext();
     new org.apache.aries.jndi.startup.Activator().start(bc);
     Activator a = new Activator();
     a.start(bc);
-    a.serviceFound();
+    ProxyManager pm = (ProxyManager) Proxy.newProxyInstance(
+            BlueprintURLContext.class.getClassLoader(),
+            new Class[]{ProxyManager.class},
+            (proxy, method, args) -> null);
+    a.serviceChanged(null, pm);
     
     // Register a BlueprintContainer mock that will answer getComponentInstance(String id) calls
     BlueprintContainer bpc = Skeleton.newMock(new BlueprintContainerStub(), BlueprintContainer.class);

Modified: aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java (original)
+++ aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java Wed Feb 21 09:05:56 2018
@@ -83,7 +83,7 @@ public class ServiceRegistryContextTest
    * @throws IllegalArgumentException 
    */
   @Before
-  public void registerService() throws NamingException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException 
+  public void registerService() throws Exception
   {
     bc =  Skeleton.newMock(new BundleContextMock(), BundleContext.class);
     registerProxyManager();

Modified: aries/trunk/jndi/parent/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/parent/pom.xml?rev=1824949&r1=1824948&r2=1824949&view=diff
==============================================================================
--- aries/trunk/jndi/parent/pom.xml (original)
+++ aries/trunk/jndi/parent/pom.xml Wed Feb 21 09:05:56 2018
@@ -59,7 +59,7 @@
             <dependency>
                 <groupId>org.apache.aries</groupId>
                 <artifactId>org.apache.aries.util</artifactId>
-                <version>1.0.0</version>
+                <version>1.1.3</version>
             </dependency>
             <dependency>
                 <groupId>org.apache.aries.proxy</groupId>