jsedding commented on code in PR #100:
URL: 
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/100#discussion_r1317054089


##########
src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java:
##########
@@ -490,69 +555,26 @@ protected void deactivate() {
     private void unregisterFactory() {
         FactoryRegistration local = null;
         synchronized ( this ) {
-            if ( this.factoryRegistration != null ) {
+            if (this.factoryRegistration != null) {
                 local = this.factoryRegistration;
                 this.factoryRegistration = null;
             }
         }
-        this.unregisterFactory(local);
-    }
-
-    /**
-     * Unregister the provided factory
-     */
-    private void unregisterFactory(final FactoryRegistration local) {
-        if ( local != null ) {
-            if ( local.factoryRegistration != null ) {
-                local.factoryRegistration.unregister();
-            }
-            if ( local.runtimeRegistration != null ) {
-                local.runtimeRegistration.unregister();
-            }
-            if ( local.commonFactory != null ) {
-                local.commonFactory.deactivate();
-            }
+        if (local != null) {
+            local.unregister();
         }
     }
 
     /**
      * Try to register the factory.
      */
     private void registerFactory(final BundleContext localContext) {
-        final FactoryRegistration local = new FactoryRegistration();
-
-        if ( localContext != null ) {
-            // activate and register factory
-            final Dictionary<String, Object> serviceProps = new Hashtable<>();
-            serviceProps.put(Constants.SERVICE_VENDOR, "The Apache Software 
Foundation");
-            serviceProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling 
Resource Resolver Factory");
-
-            local.commonFactory = new CommonResourceResolverFactoryImpl(this);
-            local.commonFactory.activate(localContext);
-            local.factoryRegistration = localContext.registerService(
-                ResourceResolverFactory.class, new 
ServiceFactory<ResourceResolverFactory>() {
-
-                    @Override
-                    public ResourceResolverFactory getService(final Bundle 
bundle, final ServiceRegistration<ResourceResolverFactory> registration) {
-                        if ( 
ResourceResolverFactoryActivator.this.bundleContext == null ) {
-                            return null;
-                        }
-                        final ResourceResolverFactoryImpl r = new 
ResourceResolverFactoryImpl(
-                                local.commonFactory, bundle,
-                            
ResourceResolverFactoryActivator.this.getServiceUserMapper());
-                        return r;
-                    }
-
-                    @Override
-                    public void ungetService(final Bundle bundle, final 
ServiceRegistration<ResourceResolverFactory> registration, final 
ResourceResolverFactory service) {
-                        // nothing to do
-                    }
-                }, serviceProps);
-
-            local.runtimeRegistration = 
localContext.registerService(RuntimeService.class,
-                    this.getRuntimeService(), null);
-
-            this.factoryRegistration = local;
+        if (!this.isDeactivating) {
+            synchronized (this) {

Review Comment:
   We could probably get rid of the synchronization. `factoryRegistration` 
should only ever get set via the `factoryRegistrationWorker` thread and is this 
guaranteed not to be concurrent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to