directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gokt...@apache.org
Subject svn commit: r1227714 - in /directory/apacheds/branches/apacheds-osgi/component-hub: ./ src/main/java/org/apache/directory/server/component/hub/ src/main/java/org/apache/directory/server/component/utilities/
Date Thu, 05 Jan 2012 17:29:40 GMT
Author: gokturk
Date: Thu Jan  5 17:29:39 2012
New Revision: 1227714

URL: http://svn.apache.org/viewvc?rev=1227714&view=rev
Log:
* ADSOSGIEventsHelper is created as OSGI Event Handling helper on topics.
* Activator is added for BundleContext retrieval
* Code Reorgs.


Added:
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/Activator.java
  (with props)
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSOSGIEventsHelper.java
  (with props)
Modified:
    directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml
    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/ComponentSchemaManager.java

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml?rev=1227714&r1=1227713&r2=1227714&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml (original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml Thu Jan  5 17:29:39 2012
@@ -94,6 +94,7 @@
           <manifestLocation>META-INF</manifestLocation>
           <instructions>
             <Bundle-SymbolicName>${project.groupId}.component.hub</Bundle-SymbolicName>
+            <Bundle-Activator>org.apache.directory.server.component.hub.Activator</Bundle-Activator>
           </instructions>
         </configuration>
       </plugin>

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/Activator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/Activator.java?rev=1227714&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/Activator.java
(added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/Activator.java
Thu Jan  5 17:29:39 2012
@@ -0,0 +1,49 @@
+/*
+ *  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 org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+
+/**
+ * Activator for apacheds-component-hub.
+ * Keeping BundleContext reference for OSGI Event handling.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Activator implements BundleActivator
+{
+
+    @Override
+    public void start( BundleContext context ) throws Exception
+    {
+        ComponentHub.bundleContext = context;
+    }
+
+
+    @Override
+    public void stop( BundleContext context ) throws Exception
+    {
+        ComponentHub.bundleContext = null;
+    }
+
+}
\ No newline at end of file

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

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=1227714&r1=1227713&r2=1227714&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
Thu Jan  5 17:29:39 2012
@@ -20,6 +20,8 @@
 package org.apache.directory.server.component.hub;
 
 
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Properties;
 
 import org.apache.directory.server.component.ADSComponent;
@@ -28,6 +30,7 @@ import org.apache.directory.server.compo
 import org.apache.directory.server.component.schema.DefaultComponentSchemaGenerator;
 import org.apache.directory.server.component.utilities.ADSComponentHelper;
 import org.apache.directory.server.component.utilities.ADSConstants;
+import org.apache.directory.server.component.utilities.ADSOSGIEventsHelper;
 import org.apache.directory.server.core.api.DirectoryService;
 import org.apache.directory.server.core.api.interceptor.Interceptor;
 import org.apache.directory.server.core.api.partition.Partition;
@@ -36,13 +39,20 @@ import org.apache.directory.server.core.
 import org.apache.directory.shared.ipojo.helpers.IPojoHelper;
 import org.apache.felix.ipojo.Factory;
 import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Instantiate;
 import org.apache.felix.ipojo.annotations.Invalidate;
 import org.apache.felix.ipojo.annotations.Property;
+import org.apache.felix.ipojo.annotations.Provides;
 import org.apache.felix.ipojo.annotations.Requires;
 import org.apache.felix.ipojo.annotations.Validate;
 import org.apache.felix.ipojo.whiteboard.Wbp;
 import org.apache.felix.ipojo.whiteboard.Whiteboards;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
 import org.osgi.service.log.LogService;
 
 
@@ -63,14 +73,25 @@ import org.osgi.service.log.LogService;
             onDeparture = "onInstanceDeparture",
             filter = "(objectClass=org.apache.felix.ipojo.architecture.Architecture)")
 })
-public class ComponentHub
+public class ComponentHub implements EventHandler
 {
+
+    /*
+     * BundleContext reference for event handling
+     */
+    public static BundleContext bundleContext;
+
     /*
      * DirectoryService reference
      */
     private DirectoryService ads;
 
     /*
+     * Relative path name of the ApacheDS instance
+     */
+    private String instanceDir;
+
+    /*
      * Schema Partition reference.
      */
     private SchemaPartition schemaPartition;
@@ -93,12 +114,12 @@ public class ComponentHub
     /*
      * Used to manage component's schemas.
      */
-    private ComponentSchemaManager componentSchemaManager = new ComponentSchemaManager( schemaPartition
);
+    private ComponentSchemaManager componentSchemaManager;
 
     /*
      * Used to manage config partition interactions.
      */
-    private ConfigurationManager configManager = new ConfigurationManager( configPartition,
componentSchemaManager );
+    private ConfigurationManager configManager;
 
     /*
      * Used to manage instances' DIT hooks.
@@ -108,7 +129,7 @@ public class ComponentHub
     /*
      * Used to manage components.
      */
-    private ComponentManager componentManager = new ComponentManager( configManager );
+    private ComponentManager componentManager;
 
     /*
      * Allowed interfaces for components.
@@ -130,37 +151,39 @@ public class ComponentHub
      * @param configPartition config partition reference
      * @return reference to a wrapped ComponentHub IPojo component
      */
-    public static ComponentHub createIPojoInstance( DirectoryService ads, SchemaPartition
schemaPartition,
+    public static ComponentHub createIPojoInstance( String instanceDir, SchemaPartition schemaPartition,
         SingleFileLdifPartition configPartition )
     {
-        String adsInstance = ads.getInstanceId();
-        String hubInstanceId = ADSConstants.ADS_HUB_FACTORY_NAME + "-" + adsInstance;
+        String hubInstanceId = ADSConstants.ADS_HUB_FACTORY_NAME + "-" + instanceDir;
         Properties conf = new Properties();
 
-        conf.put( "ads-hub-arg-ads", ads );
+        conf.put( "ads-hub-arg-insdir", instanceDir );
         conf.put( "ads-hub-arg-schpart", schemaPartition );
         conf.put( "ads-hub-arg-confpart", configPartition );
 
         ComponentHub componentHubInstance = ( ComponentHub ) IPojoHelper.createIPojoComponent(
-            ADSConstants.ADS_HUB_FACTORY_NAME, hubInstanceId, null );
+            ADSConstants.ADS_HUB_FACTORY_NAME, hubInstanceId, conf );
 
         return componentHubInstance;
     }
 
 
     public ComponentHub(
-        @Property(name = "ads-hub-arg-ads") DirectoryService ads,
-
+        @Property(name = "ads-hub-arg-insdir") String instanceDir,
         @Property(name = "ads-hub-arg-schpart") SchemaPartition schemaPartition,
-
         @Property(name = "ads-hub-arg-confpart") SingleFileLdifPartition configPartition
)
     {
-        this.ads = ads;
+        this.instanceDir = instanceDir;
         this.schemaPartition = schemaPartition;
         this.configPartition = configPartition;
+        
+        componentSchemaManager = new ComponentSchemaManager( schemaPartition );
+        configManager = new ConfigurationManager( configPartition, componentSchemaManager
);
 
+        // Initialized here because of the IPojo's object initialization routine !
         componentSchemaManager.addSchemaGenerator( Interceptor.class.getName(), new DefaultComponentSchemaGenerator()
);
         componentSchemaManager.addSchemaGenerator( Partition.class.getName(), new DefaultComponentSchemaGenerator()
);
+        componentManager = new ComponentManager( configManager );
 
         componentManager.addInstanceGenerator( Interceptor.class.getName(), new DefaultComponentInstanceGenerator()
);
         componentManager.addInstanceGenerator( Partition.class.getName(), new DefaultComponentInstanceGenerator()
);
@@ -172,9 +195,8 @@ public class ComponentHub
     /**
      * Register the DirectoryListener of InstanceManager with ADS
      *
-     * @param ads DirectoryService reference to register listener with.
      */
-    public void RegisterWithDS( DirectoryService ads )
+    private void RegisterWithDS()
     {
         instanceManager.registerWithDirectoryService( ads );
     }
@@ -188,6 +210,17 @@ public class ComponentHub
     public void hubValidated()
     {
         logger.log( LogService.LOG_INFO, "ADSComponentHub validated." );
+
+        // Register the class for OSGI Event handling
+        String[] topics = new String[]
+            {
+                ADSOSGIEventsHelper.getTopic_DSInitialized( instanceDir )
+        };
+
+        Dictionary props = new Hashtable();
+        props.put( EventConstants.EVENT_TOPIC, topics );
+
+        bundleContext.registerService( EventHandler.class.getName(), this, props );
     }
 
 
@@ -390,4 +423,28 @@ public class ComponentHub
     {
         eventManager.removeListener( listener );
     }
+
+
+    /**
+     * OSGI Event handler.
+     * Used for pairing component-hub with the DirectoryService reference.
+     */
+    @Override
+    public void handleEvent( Event event )
+    {
+        String topic = event.getTopic();
+        if ( topic.equals( ADSOSGIEventsHelper.getTopic_DSInitialized( instanceDir ) ) )
+        {
+            DirectoryService createdDS = ( DirectoryService ) event.getProperty( ADSOSGIEventsHelper.ADS_EVENT_ARG_DS
);
+            if ( createdDS == null )
+            {
+                logger.log( LogService.LOG_INFO,
+                    "DSInitialized event does not contain created DirectoryServiceReference"
);
+                return;
+            }
+
+            ads = createdDS;
+            RegisterWithDS();
+        }
+    }
 }

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentSchemaManager.java?rev=1227714&r1=1227713&r2=1227714&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentSchemaManager.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentSchemaManager.java
Thu Jan  5 17:29:39 2012
@@ -20,6 +20,7 @@
 package org.apache.directory.server.component.hub;
 
 
+import java.io.InputStream;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
@@ -195,7 +196,8 @@ public class ComponentSchemaManager
     {
         try
         {
-            LdifReader reader = new LdifReader( this.getClass().getResourceAsStream( "componenthub.ldif"
) );
+            InputStream is  = this.getClass().getResourceAsStream( "componenthub.ldif" );
+            LdifReader reader = new LdifReader( is );
 
             for ( LdifEntry le : reader )
             {

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSOSGIEventsHelper.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSOSGIEventsHelper.java?rev=1227714&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSOSGIEventsHelper.java
(added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSOSGIEventsHelper.java
Thu Jan  5 17:29:39 2012
@@ -0,0 +1,48 @@
+/*
+ *  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.utilities;
+
+
+public class ADSOSGIEventsHelper
+{
+    /** Header for all events under ComponentHub */
+    private static final String eventHeader = "org/apache/directory/server/";
+
+    /** DirectoryService reference argument name for ComponentHub OSGI Events. */
+    public static final String ADS_EVENT_ARG_DS = "org/apache/directory/server/dsreference";
+
+
+    public static String getTopic_CoreInterceptorsReady( String instanceDir )
+    {
+        return eventHeader + instanceDir + "/CoreInterceptorsReady";
+    }
+
+
+    public static String getTopic_CorePartitionsReady( String instanceDir )
+    {
+        return eventHeader + instanceDir + "/CorePartitionsReady";
+    }
+
+
+    public static String getTopic_DSInitialized( String instanceDir )
+    {
+        return eventHeader + instanceDir + "/DSInitialized";
+    }
+}

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



Mime
View raw message