You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by go...@apache.org on 2012/06/22 02:01:28 UTC

svn commit: r1352731 - in /directory/apacheds/branches/apacheds-osgi/hub: api/src/main/java/org/apache/directory/server/hub/api/ core/src/main/java/org/apache/directory/server/hub/core/

Author: gokturk
Date: Fri Jun 22 00:01:25 2012
New Revision: 1352731

URL: http://svn.apache.org/viewvc?rev=1352731&view=rev
Log:
* Minor refactorings for better naming
* Altered configuration update behaviour for components for better error handling
* Locks are deleted from Hub and Components. Hub is providing notification system for clients. It's client's job to stop component actually.Trying to provide this concurrency control from within Hub is so messy.

Added:
    directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractComponentListener.java
      - copied, changed from r1348830, directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractHubClient.java
    directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentListener.java   (with props)
Removed:
    directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractHubClient.java
Modified:
    directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentHub.java
    directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/ComponentHubImpl.java
    directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/HubClientManager.java

Copied: directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractComponentListener.java (from r1348830, directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractHubClient.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractComponentListener.java?p2=directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractComponentListener.java&p1=directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractHubClient.java&r1=1348830&r2=1352731&rev=1352731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractHubClient.java (original)
+++ directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/AbstractComponentListener.java Fri Jun 22 00:01:25 2012
@@ -26,33 +26,42 @@ import org.apache.directory.server.hub.a
 import org.apache.directory.server.hub.api.exception.HubAbortException;
 
 
-public class AbstractHubClient
+public class AbstractComponentListener implements ComponentListener
 {
+    /* (non-Javadoc)
+     * @see org.apache.directory.server.hub.api.ComponentListener#componentActivated(org.apache.directory.server.hub.api.component.DirectoryComponent)
+     */
+    @Override
     public void componentActivated( DirectoryComponent component )
     {
 
     }
 
 
+    /* (non-Javadoc)
+     * @see org.apache.directory.server.hub.api.ComponentListener#componentDeactivating(org.apache.directory.server.hub.api.component.DirectoryComponent)
+     */
+    @Override
     public void componentDeactivating( DirectoryComponent component ) throws HubAbortException
     {
 
     }
 
 
+    /* (non-Javadoc)
+     * @see org.apache.directory.server.hub.api.ComponentListener#componentDeactivated(org.apache.directory.server.hub.api.component.DirectoryComponent)
+     */
+    @Override
     public void componentDeactivated( DirectoryComponent component )
     {
 
     }
 
 
-    public void componentReconfiguring( DirectoryComponent component, DcConfiguration newConfiguration )
-        throws HubAbortException
-    {
-
-    }
-
-
+    /* (non-Javadoc)
+     * @see org.apache.directory.server.hub.api.ComponentListener#componentReconfigured(org.apache.directory.server.hub.api.component.DirectoryComponent, boolean)
+     */
+    @Override
     public void componentReconfigured( DirectoryComponent component, boolean newInstance )
     {
 

Modified: directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentHub.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentHub.java?rev=1352731&r1=1352730&r2=1352731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentHub.java (original)
+++ directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentHub.java Fri Jun 22 00:01:25 2012
@@ -68,10 +68,10 @@ public interface ComponentHub
     public abstract void removeInjection( String injectionType );
 
 
-    public abstract void registerClient( AbstractHubClient hubClient, String type );
+    public abstract void registerClient( ComponentListener hubClient, String type );
 
 
-    public abstract void unregisterClient( AbstractHubClient hubClient, String type );
+    public abstract void unregisterClient( ComponentListener hubClient, String type );
 
 
     public abstract DirectoryComponentRegistry getDCRegistry();
@@ -85,10 +85,4 @@ public interface ComponentHub
 
     public abstract PidHandlerRegistry getPIDHandlerRegistry();
 
-
-    public abstract ReadLock getReadLock();
-
-
-    public abstract WriteLock getWriteLock();
-
 }
\ No newline at end of file

Added: directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentListener.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentListener.java?rev=1352731&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentListener.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentListener.java Fri Jun 22 00:01:25 2012
@@ -0,0 +1,40 @@
+/*
+ *   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.directory.server.hub.api;
+
+
+import org.apache.directory.server.hub.api.component.DirectoryComponent;
+import org.apache.directory.server.hub.api.exception.HubAbortException;
+
+
+public interface ComponentListener
+{
+    public abstract void componentActivated( DirectoryComponent component );
+
+
+    public abstract void componentDeactivating( DirectoryComponent component ) throws HubAbortException;
+
+
+    public abstract void componentDeactivated( DirectoryComponent component );
+
+
+    public abstract void componentReconfigured( DirectoryComponent component, boolean newInstance );
+}
\ No newline at end of file

Propchange: directory/apacheds/branches/apacheds-osgi/hub/api/src/main/java/org/apache/directory/server/hub/api/ComponentListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/ComponentHubImpl.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/ComponentHubImpl.java?rev=1352731&r1=1352730&r2=1352731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/ComponentHubImpl.java (original)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/ComponentHubImpl.java Fri Jun 22 00:01:25 2012
@@ -27,14 +27,10 @@ import java.util.Collection;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Set;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
-
 import org.apache.directory.server.component.handler.ipojo.DcHandlerConstants;
 import org.apache.directory.server.core.api.interceptor.Interceptor;
-import org.apache.directory.server.hub.api.AbstractHubClient;
 import org.apache.directory.server.hub.api.ComponentHub;
+import org.apache.directory.server.hub.api.ComponentListener;
 import org.apache.directory.server.hub.api.HubStore;
 import org.apache.directory.server.hub.api.component.DcConfiguration;
 import org.apache.directory.server.hub.api.component.DcProperty;
@@ -75,10 +71,6 @@ public class ComponentHubImpl implements
     private PidHandlerRegistry handlersReg = new PidHandlerRegistry();
     private ParentLinkRegistry parentLinksReg = new ParentLinkRegistry();
 
-    private ReentrantReadWriteLock hubLock = new ReentrantReadWriteLock();
-    private ReadLock readLock = hubLock.readLock();
-    private WriteLock writeLock = hubLock.writeLock();
-
     private CollectionConnector collectionConnector;
     public IPojoConnector ipojoConnector;
 
@@ -90,7 +82,6 @@ public class ComponentHubImpl implements
 
     private ConfiguratorInterceptor configurator;
 
-
     public ComponentHubImpl( HubStore store )
     {
         this.store = store;
@@ -183,11 +174,12 @@ public class ComponentHubImpl implements
                 throw new HubAbortException( "Store raised an error while updating metadata:"
                     + metadata.getMetadataPID(), e );
             }
-
         }
 
         /*
-         * This call will set metadata with constant properties.
+         * This call will set metadata with constant properties and altered component management
+         * by management flags, like exclusive,threadsafe,vs...
+         * 
          * Stored metadata is kept until this point for new component configurations.
          */
         metadatasReg.addMetadataDescriptor( metadata );
@@ -266,8 +258,6 @@ public class ComponentHubImpl implements
             }
         }
 
-        clientManager.fireDCReconfiguring( component, newConfiguration );
-
         boolean isExclusive = metadata.isExclusive();
         boolean reinstantiate = false;
 
@@ -363,7 +353,7 @@ public class ComponentHubImpl implements
                     }
                     catch ( Exception e2 )
                     {
-                        disposeComponent( component );
+                        deactivateComponent( component );
 
                         throw new HubAbortException( "Reconfiguration reverted but component couldn't be saved:"
                             + component.getComponentPID(), e );
@@ -450,6 +440,7 @@ public class ComponentHubImpl implements
         if ( parents != null )
         {
             List<ParentLink> alteredParents = new ArrayList<ParentLink>();
+            boolean removed = true;
             for ( ParentLink parentLink : parents )
             {
                 DcConfiguration newParentConf = parentLink.getParent().getConfiguration();
@@ -482,15 +473,19 @@ public class ComponentHubImpl implements
                             // TODO log given parent couldn't be reverted from cancelled removal of its referenced property.
                         }
                     }
+                    
+                    removed = false;
+                    break;
                 }
             }
+            
+            if(removed)
+            {
+                parentLinksReg.destroyComponentLinks( component );
+            }
         }
-
-        DcOperationsManager opManager = handlersReg.getPIDHandler( component.getComponentManagerPID() );
-        if ( opManager != null )
-        {
-            opManager.disposeComponent( component );
-        }
+        
+        deactivateComponent( component );
 
         componentsReg.removeDirectoryComponent( component );
 
@@ -543,7 +538,7 @@ public class ComponentHubImpl implements
      * @see org.apache.directory.server.hub.ComponentHub#registerClient(org.apache.directory.server.hub.client.AbstractHubClient, java.lang.String)
      */
     @Override
-    public void registerClient( AbstractHubClient hubClient, String type )
+    public void registerClient( ComponentListener hubClient, String type )
     {
         clientManager.registerHubClient( hubClient, type );
     }
@@ -553,7 +548,7 @@ public class ComponentHubImpl implements
      * @see org.apache.directory.server.hub.ComponentHub#unregisterClient(org.apache.directory.server.hub.client.AbstractHubClient, java.lang.String)
      */
     @Override
-    public void unregisterClient( AbstractHubClient hubClient, String type )
+    public void unregisterClient( ComponentListener hubClient, String type )
     {
         clientManager.unregisterHubClient( hubClient, type );
     }
@@ -581,7 +576,7 @@ public class ComponentHubImpl implements
         {
             for ( DirectoryComponent component : attachedComponents )
             {
-                disposeComponent( component );
+                deactivateComponent( component );
             }
         }
     }
@@ -879,7 +874,7 @@ public class ComponentHubImpl implements
     }
 
 
-    private void disposeComponent( DirectoryComponent component )
+    private void deactivateComponent( DirectoryComponent component )
     {
         clientManager.fireDCDeactivated( component );
 
@@ -890,7 +885,7 @@ public class ComponentHubImpl implements
             {
                 dependencyResolver.addDependencyHook( parentLink.getParent(),
                     new DCDependency( DCDependencyType.REFERENCE, component.getComponentPID() ) );
-                disposeComponent( parentLink.getParent() );
+                deactivateComponent( parentLink.getParent() );
             }
         }
 
@@ -974,18 +969,4 @@ public class ComponentHubImpl implements
     {
         return handlersReg;
     }
-
-
-    @Override
-    public ReadLock getReadLock()
-    {
-        return readLock;
-    }
-
-
-    @Override
-    public WriteLock getWriteLock()
-    {
-        return writeLock;
-    }
 }

Modified: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/HubClientManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/HubClientManager.java?rev=1352731&r1=1352730&r2=1352731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/HubClientManager.java (original)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/HubClientManager.java Fri Jun 22 00:01:25 2012
@@ -28,8 +28,9 @@ import java.util.Set;
 
 import org.apache.commons.collections.MultiMap;
 import org.apache.commons.collections.map.MultiValueMap;
-import org.apache.directory.server.hub.api.AbstractHubClient;
+import org.apache.directory.server.hub.api.AbstractComponentListener;
 import org.apache.directory.server.hub.api.ComponentHub;
+import org.apache.directory.server.hub.api.ComponentListener;
 import org.apache.directory.server.hub.api.component.DcConfiguration;
 import org.apache.directory.server.hub.api.component.DirectoryComponent;
 import org.apache.directory.server.hub.api.exception.HubAbortException;
@@ -44,7 +45,7 @@ public class HubClientManager
     private MultiMap clientRegistrations = new MultiValueMap();
 
 
-    public synchronized void registerHubClient( AbstractHubClient hubClient, String type )
+    public synchronized void registerHubClient( ComponentListener hubClient, String type )
     {
         typeRegistrations.put( type, hubClient );
         clientRegistrations.put( hubClient, type );
@@ -70,7 +71,7 @@ public class HubClientManager
     }
 
 
-    public void unregisterHubClient( AbstractHubClient hubClient, String type )
+    public void unregisterHubClient( ComponentListener hubClient, String type )
     {
         if ( type == null )
         {
@@ -99,8 +100,8 @@ public class HubClientManager
 
     public synchronized void fireDCActivated( DirectoryComponent component )
     {
-        List<AbstractHubClient> clients = getRegisteredClients( component );
-        for ( AbstractHubClient client : clients )
+        List<AbstractComponentListener> clients = getRegisteredClients( component );
+        for ( ComponentListener client : clients )
         {
             client.componentActivated( component );
         }
@@ -109,8 +110,8 @@ public class HubClientManager
 
     public void fireDCDeactivated( DirectoryComponent component )
     {
-        List<AbstractHubClient> clients = getRegisteredClients( component );
-        for ( AbstractHubClient client : clients )
+        List<AbstractComponentListener> clients = getRegisteredClients( component );
+        for ( ComponentListener client : clients )
         {
             client.componentDeactivated( component );
         }
@@ -119,38 +120,27 @@ public class HubClientManager
 
     public void fireDCDeactivating( DirectoryComponent component ) throws HubAbortException
     {
-        List<AbstractHubClient> clients = getRegisteredClients( component );
-        for ( AbstractHubClient client : clients )
+        List<AbstractComponentListener> clients = getRegisteredClients( component );
+        for ( ComponentListener client : clients )
         {
             client.componentDeactivating( component );
         }
     }
 
 
-    public void fireDCReconfiguring( DirectoryComponent component, DcConfiguration newConfiguration )
-        throws HubAbortException
-    {
-        List<AbstractHubClient> clients = getRegisteredClients( component );
-        for ( AbstractHubClient client : clients )
-        {
-            client.componentReconfiguring( component, newConfiguration );
-        }
-    }
-
-
     public void fireDCReconfigured( DirectoryComponent component, boolean newInstance )
     {
-        List<AbstractHubClient> clients = getRegisteredClients( component );
-        for ( AbstractHubClient client : clients )
+        List<AbstractComponentListener> clients = getRegisteredClients( component );
+        for ( ComponentListener client : clients )
         {
             client.componentReconfigured( component, newInstance );
         }
     }
 
 
-    public List<AbstractHubClient> getRegisteredClients( DirectoryComponent component )
+    public List<AbstractComponentListener> getRegisteredClients( DirectoryComponent component )
     {
-        List<AbstractHubClient> registeredClients = new ArrayList<AbstractHubClient>();
+        List<AbstractComponentListener> registeredClients = new ArrayList<AbstractComponentListener>();
 
         DcMetadataDescriptor metadata = hub.getMetaRegistry()
             .getMetadataDescriptor( component.getComponentManagerPID() );