directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gokt...@apache.org
Subject svn commit: r1224731 - in /directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component: hub/ hub/listener/ utilities/
Date Mon, 26 Dec 2011 14:33:02 GMT
Author: gokturk
Date: Mon Dec 26 14:33:01 2011
New Revision: 1224731

URL: http://svn.apache.org/viewvc?rev=1224731&view=rev
Log:
* Class ComponentRegistry is added to keep and retrieve ADSComponent references component-hub
wide, and code changes to use it instead.
* New event method is added on HubListener and AbstractHubListener to notify user-made entry
creations to Hub

Added:
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentRegistry.java
  (with props)
Modified:
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ConfigurationManager.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/AbstractHubListener.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/HubListener.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java?rev=1224731&r1=1224730&r2=1224731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java
Mon Dec 26 14:33:01 2011
@@ -28,6 +28,7 @@ import java.util.List;
 
 import org.apache.directory.server.component.ADSComponent;
 import org.apache.directory.server.component.hub.listener.HubListener;
+import org.apache.directory.server.component.instance.CachedComponentInstance;
 
 
 /**
@@ -164,6 +165,30 @@ public class ComponentEventManager
 
 
     /**
+     * Iterate through listeners for specified ADSComponent's component type.
+     * Calls their onNewInstanceConfiguration() method with supplied CachedComponentInstance
parameter.
+     *
+     * @param component ADSComponent reference to be used for notification
+     * @param createdInstance Reference to a newly created configuration as CachedComponentInstance
+     */
+    public synchronized void fireConfigurationCreated( ADSComponent component, CachedComponentInstance
createdInstance )
+    {
+        List<HubListener> listenersByType = listenersMap.get( component.getComponentType()
);
+
+        // Iterate over listeners for 'new configuration' event
+        if ( listenersByType != null )
+        {
+            for ( HubListener listener : listenersByType )
+            {
+                listener.onNewInstanceConfiguration( component, createdInstance );
+            }
+        }
+
+        unCacheCreation( component );
+    }
+
+
+    /**
      * Caches ADSComponent to notify late-coming listeners.
      *
      * @param comp ADSComponent reference to cache

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java?rev=1224731&r1=1224730&r2=1224731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
Mon Dec 26 14:33:01 2011
@@ -20,13 +20,8 @@
 package org.apache.directory.server.component.hub;
 
 
-import java.util.ArrayList;
-import java.util.Dictionary;
 import java.util.Properties;
 
-import java.util.Hashtable;
-import java.util.List;
-
 import org.apache.directory.server.component.ADSComponent;
 import org.apache.directory.server.component.hub.listener.HubListener;
 import org.apache.directory.server.component.instance.DefaultComponentInstanceGenerator;
@@ -86,14 +81,9 @@ public class ComponentHub
     private SingleFileLdifPartition configPartition;
 
     /*
-     * Map to keep "component type" -> "components" mapping.
-     */
-    private Dictionary<String, List<ADSComponent>> componentMap;
-
-    /*
-     * List to keep all active ApacheDS components.
+     * Used to set and get ADSComponent references.
      */
-    private List<ADSComponent> components;
+    private ComponentRegistry componentRegistry = new ComponentRegistry();
 
     /*
      * Used to manage listeners.
@@ -169,9 +159,6 @@ public class ComponentHub
         this.schemaPartition = schemaPartition;
         this.configPartition = configPartition;
 
-        componentMap = new Hashtable<String, List<ADSComponent>>();
-        components = new ArrayList<ADSComponent>();
-
         componentSchemaManager.addSchemaGenerator( Interceptor.class.getName(), new DefaultComponentSchemaGenerator()
);
         componentSchemaManager.addSchemaGenerator( Partition.class.getName(), new DefaultComponentSchemaGenerator()
);
 
@@ -233,23 +220,11 @@ public class ComponentHub
         //Actual ADSComponent creation
         ADSComponent component = generateADSComponent( componentType, arrivingFactory );
 
+        // Fire 'Component Created' event
         eventManager.fireComponentCreated( component );
 
-        //Keep the newly created ADSComponent reference.
-        components.add( component );
-
-        List<ADSComponent> componentsByType = componentMap.get( componentType );
-        if ( componentsByType == null )
-        {
-            List<ADSComponent> newCompList = new ArrayList<ADSComponent>();
-            newCompList.add( component );
-            componentMap.put( componentType, newCompList );
-        }
-        else
-        {
-            componentsByType.add( component );
-        }
-
+        // Add the newly created component reference to registries
+        componentRegistry.addComponent( component );
     }
 
 
@@ -269,7 +244,8 @@ public class ComponentHub
         String componentType = parseComponentType( leavingFactory );
 
         ADSComponent associatedComp = null;
-        for ( ADSComponent _comp : components )
+
+        for ( ADSComponent _comp : componentRegistry.getAllComponents() )
         {
             if ( _comp.getFactory().getName().equals( leavingFactory.getName() ) )
             {
@@ -285,12 +261,12 @@ public class ComponentHub
             return;
         }
 
-        // All clients are notified now cache and delete the ADSComponent existence on ApacheDS
-        cacheAndReleaseADSComponent( associatedComp );
-
         // Fire "Component Deleted" event
         eventManager.fireComponentDeleted( associatedComp );
 
+        // Remove the component reference from registries
+        componentRegistry.removeComponent( associatedComp );
+
     }
 
 
@@ -394,17 +370,6 @@ public class ComponentHub
 
 
     /**
-     * Cache the ADSComponent existence on ApacheDS with all of its DIT entries. And then
release it from hub.
-     *
-     * @param leavingComp ADSComponent reference to cache and release.
-     */
-    private void cacheAndReleaseADSComponent( ADSComponent leavingComp )
-    {
-
-    }
-
-
-    /**
      * Registers a HubListener for specified component type.
      *
      * @param componentType component type to get notifications for.

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentRegistry.java?rev=1224731&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentRegistry.java
(added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentRegistry.java
Mon Dec 26 14:33:01 2011
@@ -0,0 +1,136 @@
+/*
+ *  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.component.hub;
+
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.directory.server.component.ADSComponent;
+
+
+/*
+ * Class to store and retrieve ADSComponent references under different mappings.
+ */
+public class ComponentRegistry
+{
+    /*
+     * Used to map component name to ADSComponent
+     */
+    private Dictionary<String, ADSComponent> nameToComponentMap;
+
+    /*
+     * Used to map component type to all ADSComponents of that type
+     */
+    private Dictionary<String, List<ADSComponent>> typeToComponentsMap;
+
+    /*
+     * Used to keep all components
+     */
+    private List<ADSComponent> components;
+
+
+    public ComponentRegistry()
+    {
+        nameToComponentMap = new Hashtable<String, ADSComponent>();
+        typeToComponentsMap = new Hashtable<String, List<ADSComponent>>();
+        components = new ArrayList<ADSComponent>();
+    }
+
+
+    /**
+     * Adds the component to registries
+     *
+     * @param component ADSComponent reference to keep in registers.
+     */
+    public void addComponent( ADSComponent component )
+    {
+        components.add( component );
+
+        String componentType = component.getComponentType().toLowerCase();
+        List<ADSComponent> componentsByType = typeToComponentsMap.get( componentType
);
+
+        if ( componentsByType == null )
+        {
+            List<ADSComponent> newCompList = new ArrayList<ADSComponent>();
+            newCompList.add( component );
+            typeToComponentsMap.put( componentType, newCompList );
+        }
+
+        nameToComponentMap.put( component.getComponentName().toLowerCase(), component );
+    }
+
+
+    /**
+     * Deletes a component from registries
+     *
+     * @param component ADSComponent reference to remove from registries
+     */
+    public void removeComponent( ADSComponent component )
+    {
+        components.remove( component );
+
+        String componentType = component.getComponentType().toLowerCase();
+        List<ADSComponent> componentsByType = typeToComponentsMap.get( componentType
);
+        if ( componentsByType != null )
+        {
+            componentsByType.remove( component );
+        }
+
+        nameToComponentMap.remove( component.getComponentName().toLowerCase() );
+    }
+
+
+    /**
+     * Used to retrieve all component references.
+     *
+     * @return All ADSComponents in regitries as List
+     */
+    public List<ADSComponent> getAllComponents()
+    {
+        return components;
+    }
+
+
+    /**
+     * Retrieve the component by its name.
+     *
+     * @param componentName Component name to retrieve its ADSComponent reference
+     * @return ADSComponent reference 
+     */
+    public ADSComponent getComponentByName( String componentName )
+    {
+        return nameToComponentMap.get( componentName.toLowerCase() );
+    }
+
+
+    /**
+     * Gets all the components under specified type.
+     *
+     * @param componentType Component type to look for
+     * @return All ADSComponent references for given type
+     */
+    public List<ADSComponent> getComponentsByType( String componentType )
+    {
+        return typeToComponentsMap.get( componentType.toLowerCase() );
+    }
+}

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

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ConfigurationManager.java?rev=1224731&r1=1224730&r2=1224731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ConfigurationManager.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ConfigurationManager.java
Mon Dec 26 14:33:01 2011
@@ -344,6 +344,12 @@ public class ConfigurationManager
     }
 
 
+    /**
+     * Every component entry needs a parent for its component type.
+     * This method checks and installs that parent entry for component.
+     *
+     * @param component ADSComponent to create parent entry on DIT.
+     */
     private void checkAndCreateComponentParentEntry( ADSComponent component )
     {
         try

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/AbstractHubListener.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/AbstractHubListener.java?rev=1224731&r1=1224730&r2=1224731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/AbstractHubListener.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/AbstractHubListener.java
Mon Dec 26 14:33:01 2011
@@ -21,6 +21,7 @@ package org.apache.directory.server.comp
 
 
 import org.apache.directory.server.component.ADSComponent;
+import org.apache.directory.server.component.instance.CachedComponentInstance;
 
 
 /**
@@ -50,4 +51,15 @@ public abstract class AbstractHubListene
     {
     }
 
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.directory.server.component.hub.listener.HubListener#onNewInstanceConfiguration(org.apache.directory.server.component.ADSComponent,
org.apache.directory.server.component.instance.CachedComponentInstance)
+     */
+    @Override
+    public void onNewInstanceConfiguration( ADSComponent component, CachedComponentInstance
createdInstance )
+    {
+
+    }
+
 }

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/HubListener.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/HubListener.java?rev=1224731&r1=1224730&r2=1224731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/HubListener.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/HubListener.java
Mon Dec 26 14:33:01 2011
@@ -55,6 +55,13 @@ public interface HubListener
     public void onComponentDeletion( ADSComponent component );
 
 
-    public void onNewInstanceConfiguration( ADSComponent component, CachedComponentInstance
createdConf );
+    /**
+     * Notified when new configuration is created by user in DIT.
+     * It is added to component's cached instances list automatically.
+     *
+     * @param component Parent component of the created configuration
+     * @param createdConf CachedComponentInstance reference generated from created configuration
+     */
+    public void onNewInstanceConfiguration( ADSComponent component, CachedComponentInstance
createdInstance );
 
 }

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java?rev=1224731&r1=1224730&r2=1224731&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java
Mon Dec 26 14:33:01 2011
@@ -26,7 +26,6 @@ import java.util.List;
 import java.util.Properties;
 
 import org.apache.directory.server.component.ADSComponent;
-import org.apache.directory.server.component.hub.ComponentManager;
 import org.apache.directory.server.component.instance.ADSComponentInstance;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
 import org.apache.directory.shared.ldap.model.entry.Entry;
@@ -35,8 +34,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.ldif.LdapLdifException;
 import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.model.name.Dn;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 public class LdifConfigHelper
@@ -78,7 +75,7 @@ public class LdifConfigHelper
             String attribute = ( String ) key + "=" + ( String ) instanceConfiguration.get(
key );
             attributes.add( attribute );
         }
-        
+
         LdifEntry instanceEntry;
         try
         {



Mime
View raw message