directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1153112 - in /directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap: LdapServer.java replication/ReplicaDitStoreUtil.java replication/ReplicationRequestHandler.java replication/SyncReplRequestHandler.java
Date Tue, 02 Aug 2011 13:12:24 GMT
Author: elecharny
Date: Tue Aug  2 13:12:22 2011
New Revision: 1153112

URL: http://svn.apache.org/viewvc?rev=1153112&view=rev
Log:
o Renamed the replication handler init() method to start() as it goes better with the stop()
method
o Added some Javadoc
o Removed the ReplicaDitStoreUtil.coreConnection field, we use directly the adminSession now

Modified:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaDitStoreUtil.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicationRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplRequestHandler.java

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java?rev=1153112&r1=1153111&r2=1153112&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
Tue Aug  2 13:12:22 2011
@@ -503,7 +503,7 @@ public class LdapServer extends Director
     {
         if ( replicationReqHandler != null )
         {
-            replicationReqHandler.init( this );
+            replicationReqHandler.start( this );
             ( ( SearchHandler ) getSearchHandler() ).setReplicationReqHandler( replicationReqHandler
);
         }
     }

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaDitStoreUtil.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaDitStoreUtil.java?rev=1153112&r1=1153111&r2=1153112&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaDitStoreUtil.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaDitStoreUtil.java
Tue Aug  2 13:12:22 2011
@@ -28,11 +28,10 @@ import java.util.Map;
 
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.LdapCoreSessionConnection;
 import org.apache.directory.server.core.event.EventType;
 import org.apache.directory.server.core.event.NotificationCriteria;
+import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
 import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
@@ -40,9 +39,15 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.entry.Modification;
 import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.model.entry.StringValue;
+import org.apache.directory.shared.ldap.model.filter.EqualityNode;
+import org.apache.directory.shared.ldap.model.filter.ExprNode;
 import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.model.message.SearchRequest;
+import org.apache.directory.shared.ldap.model.message.SearchRequestImpl;
 import org.apache.directory.shared.ldap.model.message.SearchScope;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -55,41 +60,46 @@ import org.slf4j.LoggerFactory;
  */
 public class ReplicaDitStoreUtil
 {
+    /** Logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( ReplicaDitStoreUtil.class
);
+
+    /** The admin session used to commuicate with the backend */
     private CoreSession adminSession;
 
+    /** The schema manager instance */
     private SchemaManager schemaManager;
 
-    private static final String REPL_CONSUMER_DN = "ou=consumers,ou=system";
+    /** The replication factory DN */
+    private static final String REPL_CONSUMER_DN_STR = "ou=consumers,ou=system";
+    private static Dn REPL_CONSUMER_DN;
 
-    private static final Logger LOG = LoggerFactory.getLogger( ReplicaDitStoreUtil.class
);
+    /** An ObjectClass AT instance */
+    private static AttributeType OBJECT_CLASS_AT;
 
     private Map<Integer, List<Modification>> modMap = new HashMap<Integer,
List<Modification>>();
 
-    private LdapCoreSessionConnection coreConnection;
-
 
     public ReplicaDitStoreUtil( DirectoryService dirService ) throws Exception
     {
-        this.adminSession = dirService.getAdminSession();
-        this.schemaManager = dirService.getSchemaManager();
-        coreConnection = new LdapCoreSessionConnection( adminSession );
+        adminSession = dirService.getAdminSession();
+        schemaManager = dirService.getSchemaManager();
+        REPL_CONSUMER_DN = dirService.getDnFactory().create( REPL_CONSUMER_DN_STR );
+        OBJECT_CLASS_AT = dirService.getSchemaManager().lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT
);
 
         init();
     }
 
 
     /**
-     * Initialize the replication Store, creating the pu=consumers,ou=system entry
+     * Initialize the replication Store, creating the ou=consumers,ou=system entry
      */
     private void init() throws Exception
     {
-        Dn replConsumerDn = new Dn( schemaManager, REPL_CONSUMER_DN );
-
-        if ( !adminSession.exists( replConsumerDn ) )
+        if ( !adminSession.exists( REPL_CONSUMER_DN ) )
         {
             LOG.debug( "creating the entry for storing replication consumers' details" );
             
-            Entry entry = new DefaultEntry( schemaManager , replConsumerDn,
+            Entry entry = new DefaultEntry( schemaManager , REPL_CONSUMER_DN,
                 SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.ORGANIZATIONAL_UNIT_OC,
                 SchemaConstants.OU_AT, "consumers" );
 
@@ -162,8 +172,14 @@ public class ReplicaDitStoreUtil
     {
         List<ReplicaEventLog> replicas = new ArrayList<ReplicaEventLog>();
 
-        EntryCursor cursor = coreConnection.search( REPL_CONSUMER_DN, "(" + SchemaConstants.OBJECT_CLASS
+ "=" + SchemaConstants.ADS_REPL_EVENT_LOG + ")",
-            SearchScope.ONELEVEL, "+", "*" );
+        ExprNode filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
SchemaConstants.ADS_REPL_EVENT_LOG ) );
+        SearchRequest searchRequest = new SearchRequestImpl();
+        searchRequest.setBase( REPL_CONSUMER_DN );
+        searchRequest.setScope( SearchScope.ONELEVEL );
+        searchRequest.setFilter( filter );
+        searchRequest.addAttributes( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES, SchemaConstants.ALL_USER_ATTRIBUTES
);
+        
+        EntryFilteringCursor cursor = adminSession.search( searchRequest );
 
         while ( cursor.next() )
         {

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicationRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicationRequestHandler.java?rev=1153112&r1=1153111&r2=1153112&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicationRequestHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicationRequestHandler.java
Tue Aug  2 13:12:22 2011
@@ -37,7 +37,7 @@ public interface ReplicationRequestHandl
      *
      * @param server the LdapServer instance
      */
-    void init( LdapServer server );
+    void start( LdapServer server );
 
     
     /**

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplRequestHandler.java?rev=1153112&r1=1153111&r2=1153112&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplRequestHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplRequestHandler.java
Tue Aug  2 13:12:22 2011
@@ -100,19 +100,22 @@ import org.slf4j.LoggerFactory;
 @SuppressWarnings("unchecked")
 public class SyncReplRequestHandler implements ReplicationRequestHandler
 {
+    /** The logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( SyncReplRequestHandler.class
);
 
     public static final String REPLICA_ID_DELIM = ";";
 
-    private static final Logger LOG = LoggerFactory.getLogger( SyncReplRequestHandler.class
);
-
+    /** Tells if the replication handler is already started */
     private boolean initialized = false;
 
+    /** The directory service instance */
     private DirectoryService dirService;
 
     /** The reference on the Ldap server instance */
     protected LdapServer ldapServer;
 
-    private AttributeType objectClassAttributeType;
+    /** An ObjectClass AT instance */
+    private static AttributeType OBJECT_CLASS_AT;
 
     private Map<Integer, ReplicaEventLog> replicaLogMap = new HashMap<Integer, ReplicaEventLog>();
 
@@ -127,18 +130,25 @@ public class SyncReplRequestHandler impl
     private ReplicaDitStoreUtil replicaUtil;
 
 
+    /**
+     * Create a SyncReplRequestHandler empty instance 
+     */
     public SyncReplRequestHandler()
     {
     }
 
 
-    public void init( LdapServer server )
+    /**
+     * {@inheritDoc}
+     */
+    public void start( LdapServer server )
     {
         if ( initialized )
         {
             LOG.warn( "syncrepl provider was already initialized" );
             return;
         }
+        
         try
         {
             LOG.info( "initializing the syncrepl provider" );
@@ -146,6 +156,9 @@ public class SyncReplRequestHandler impl
             this.ldapServer = server;
             this.dirService = server.getDirectoryService();
 
+            OBJECT_CLASS_AT = dirService.getSchemaManager()
+                .lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
+
             File workDir = dirService.getInstanceLayout().getLogDirectory();
             syncReplData = new File( workDir, "syncrepl-data" );
             
@@ -156,6 +169,8 @@ public class SyncReplRequestHandler impl
 
             String path = syncReplData.getPath();
 
+            // Create the system responsible for transmitting the requests when
+            // the direct connection to the consumer is closed.
             brokerService = new BrokerService();
             brokerService.setUseJmx( false );
             brokerService.setPersistent( true );
@@ -851,14 +866,8 @@ public class SyncReplRequestHandler impl
 
     private EqualityNode<String> newIsReferralEqualityNode( LdapSession session ) throws
Exception
     {
-        if ( objectClassAttributeType == null )
-        {
-            objectClassAttributeType = session.getCoreSession().getDirectoryService().getSchemaManager()
-                .lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
-        }
-
         EqualityNode<String> ocIsReferral = new EqualityNode<String>( SchemaConstants.OBJECT_CLASS_AT,
new StringValue(
-            objectClassAttributeType, SchemaConstants.REFERRAL_OC ) );
+            OBJECT_CLASS_AT, SchemaConstants.REFERRAL_OC ) );
 
         return ocIsReferral;
     }
@@ -871,6 +880,7 @@ public class SyncReplRequestHandler impl
             for ( Map.Entry<Integer, ReplicaEventLog> e : replicaLogMap.entrySet()
)
             {
                 ReplicaEventLog replica = e.getValue();
+                
                 if ( replica.isDirty() )
                 {
                     LOG.debug( "updating the details of replica {}", replica );
@@ -951,6 +961,7 @@ public class SyncReplRequestHandler impl
                 while ( true )
                 {
                     storeReplicaInfo();
+                    
                     try
                     {
                         Thread.sleep( 10000 );



Mime
View raw message