directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1151285 - in /directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication: ReplicaDitStoreUtil.java ReplicaEventLog.java SyncReplConsumer.java SyncReplRequestHandler.java SyncreplConfiguration.java
Date Tue, 26 Jul 2011 22:57:58 GMT
Author: elecharny
Date: Tue Jul 26 22:57:56 2011
New Revision: 1151285

URL: http://svn.apache.org/viewvc?rev=1151285&view=rev
Log:
o Added some Javadoc
o Some minor refactoring

Modified:
    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/ReplicaEventLog.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplConsumer.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncreplConfiguration.java

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=1151285&r1=1151284&r2=1151285&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 Jul 26 22:57:56 2011
@@ -78,6 +78,9 @@ public class ReplicaDitStoreUtil
     }
 
 
+    /**
+     * Initialize the replication Store, creating the pu=consumers,ou=system entry
+     */
     private void init() throws Exception
     {
         Dn replConsumerDn = new Dn( schemaManager, REPL_CONSUMER_DN );
@@ -85,17 +88,22 @@ public class ReplicaDitStoreUtil
         if ( !adminSession.exists( replConsumerDn ) )
         {
             LOG.debug( "creating the entry for storing replication consumers' details" );
-            Entry entry = new DefaultEntry( schemaManager );
-            entry.setDn( replConsumerDn );
-            entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.ORGANIZATIONAL_UNIT_OC
);
-            entry.add( SchemaConstants.OU_AT, "consumers" );
+            
+            Entry entry = new DefaultEntry( schemaManager , replConsumerDn,
+                SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.ORGANIZATIONAL_UNIT_OC,
+                SchemaConstants.OU_AT, "consumers" );
 
             adminSession.add( entry );
         }
-
     }
 
 
+    /**
+     * Add a new consumer entry
+     * 
+     * @param replica
+     * @throws Exception
+     */
     public void addConsumerEntry( ReplicaEventLog replica ) throws Exception
     {
         if ( replica == null )
@@ -103,17 +111,16 @@ public class ReplicaDitStoreUtil
             return;
         }
 
-        Entry entry = new DefaultEntry( schemaManager );
-        entry.setDn( new Dn( schemaManager, "ads-dsReplicaId=" + replica.getId() + "," +
REPL_CONSUMER_DN ) );
-
-        entry.add( SchemaConstants.OBJECT_CLASS_AT, "ads-replEventLog" );
-        entry.add( "ads-dsReplicaId", String.valueOf( replica.getId() ) );
-        entry.add( "ads-replAliasDerefMode", replica.getSearchCriteria().getAliasDerefMode().getJndiValue()
);
-        entry.add( "ads-searchBaseDN", replica.getSearchCriteria().getBase().getName() );
-        entry.add( "ads-replLastSentCsn", replica.getLastSentCsn() );
-        entry.add( "ads-replSearchScope", replica.getSearchCriteria().getScope().getLdapUrlValue()
);
-        entry.add( "ads-replRefreshNPersist", String.valueOf( replica.isRefreshNPersist()
) );
-        entry.add( "ads-replSearchFilter", replica.getSearchFilter() );
+        Dn replicaDn = new Dn( schemaManager, "ads-dsReplicaId=" + replica.getId() + ","
+ REPL_CONSUMER_DN );
+        Entry entry = new DefaultEntry( schemaManager, replicaDn,
+            SchemaConstants.OBJECT_CLASS_AT, "ads-replEventLog",
+            "ads-dsReplicaId", String.valueOf( replica.getId() ),
+            "ads-replAliasDerefMode", replica.getSearchCriteria().getAliasDerefMode().getJndiValue(),
+            "ads-searchBaseDN", replica.getSearchCriteria().getBase().getName(),
+            "ads-replLastSentCsn", replica.getLastSentCsn(),
+            "ads-replSearchScope", replica.getSearchCriteria().getScope().getLdapUrlValue(),
+            "ads-replRefreshNPersist", String.valueOf( replica.isRefreshNPersist() ),
+            "ads-replSearchFilter", replica.getSearchFilter() );
 
         adminSession.add( entry );
         LOG.debug( "stored replication consumer entry {}", entry.getDn() );
@@ -122,9 +129,9 @@ public class ReplicaDitStoreUtil
 
     public void updateReplicaLastSentCsn( ReplicaEventLog replica ) throws Exception
     {
-
         List<Modification> mods = modMap.get( replica.getId() );
         Attribute lastSentCsnAt = null;
+        
         if ( mods == null )
         {
             lastSentCsnAt = new DefaultAttribute( schemaManager
@@ -185,6 +192,7 @@ public class ReplicaDitStoreUtil
         searchCriteria.setBase( new Dn( schemaManager, baseDn ) );
 
         Attribute lastSentCsnAt = entry.get( "ads-replLastSentCsn" );
+        
         if ( lastSentCsnAt != null )
         {
             replica.setLastSentCsn( lastSentCsnAt.getString() );

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventLog.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventLog.java?rev=1151285&r1=1151284&r2=1151285&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventLog.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventLog.java
Tue Jul 26 22:57:56 2011
@@ -43,7 +43,6 @@ import org.slf4j.LoggerFactory;
  */
 public class ReplicaEventLog
 {
-
     /** IP address of the syncrepl consumer */
     private String hostName;
 
@@ -87,12 +86,6 @@ public class ReplicaEventLog
     private static final Logger LOG = LoggerFactory.getLogger( ReplicaEventLog.class );
 
 
-    public ReplicaEventLog()
-    {
-
-    }
-
-
     public ReplicaEventLog( int replicaId )
     {
         this.replicaId = replicaId;

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplConsumer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplConsumer.java?rev=1151285&r1=1151284&r2=1151285&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplConsumer.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplConsumer.java
Tue Jul 26 22:57:56 2011
@@ -88,21 +88,19 @@ import org.slf4j.LoggerFactory;
  *
  * Implementation of syncrepl slave a.k.a consumer.
  *
- * TODO write test cases
- *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class SyncReplConsumer implements ConnectionClosedEventListener, ReplicationConsumer
 {
+    /** the logger */
+    private static final Logger LOG = LoggerFactory.getLogger( SyncReplConsumer.class );
+
     /** the syncrepl configuration */
     private SyncreplConfiguration config;
 
     /** the sync cookie sent by the server */
     private byte[] syncCookie;
 
-    /** the logger */
-    private static final Logger LOG = LoggerFactory.getLogger( SyncReplConsumer.class );
-
     /** connection to the syncrepl provider */
     private LdapNetworkConnection connection;
 
@@ -126,17 +124,26 @@ public class SyncReplConsumer implements
 
     /** attributes on which modification should be ignored */
     private static final String[] MOD_IGNORE_AT = new String[]
-        { SchemaConstants.ENTRY_UUID_AT, SchemaConstants.ENTRY_CSN_AT, SchemaConstants.MODIFIERS_NAME_AT,
-            SchemaConstants.MODIFY_TIMESTAMP_AT, SchemaConstants.CREATE_TIMESTAMP_AT, SchemaConstants.CREATORS_NAME_AT,
SchemaConstants.ENTRY_PARENT_ID_AT };
+        {
+            SchemaConstants.ENTRY_UUID_AT, 
+            SchemaConstants.ENTRY_CSN_AT, 
+            SchemaConstants.MODIFIERS_NAME_AT,
+            SchemaConstants.MODIFY_TIMESTAMP_AT, 
+            SchemaConstants.CREATE_TIMESTAMP_AT, 
+            SchemaConstants.CREATORS_NAME_AT, 
+            SchemaConstants.ENTRY_PARENT_ID_AT 
+        };
 
+    /** A thread used to refresh in refreshOnly mode */
     private RefresherThread refreshThread;
 
     /** the cookie that was saved last time */
     private byte[] lastSavedCookie;
 
-
+    /** The (entrtyUuid=*) filter */
     private static final PresenceNode ENTRY_UUID_PRESENCE_FILTER = new PresenceNode( SchemaConstants.ENTRY_UUID_AT
);
 
+    /** The set used for search attributes, containing only the entryUuid AT */
     private static final Set<AttributeTypeOptions> ENTRY_UUID_ATOP_SET = new HashSet<AttributeTypeOptions>();
 
     private List<Modification> cookieModLst;
@@ -191,15 +198,17 @@ public class SyncReplConsumer implements
 
 
     /**
-     * Connect to the remote servers
-     * @return
+     * Connect to the remote server. Note that a SyncRepl consumer will be connected to only
+     * one remote server
+     * 
+     * @return true if the connections have been successful. 
      */
     public boolean connect()
     {
         try
         {
-            String providerHost = config.getProviderHost();
-            int port = config.getPort();
+            String providerHost = config.getRemoteHost();
+            int port = config.getRemotePort();
             
             // Create a connection
             if ( connection == null )
@@ -613,10 +622,10 @@ public class SyncReplConsumer implements
             }
 
             connection.unBind();
-            LOG.info( "Unbound from the server {}", config.getProviderHost() );
+            LOG.info( "Unbound from the server {}", config.getRemoteHost() );
 
             connection.close();
-            LOG.info( "Connection closed for the server {}", config.getProviderHost() );
+            LOG.info( "Connection closed for the server {}", config.getRemoteHost() );
 
             connection = null;
 
@@ -974,8 +983,11 @@ public class SyncReplConsumer implements
      */
     private class RefresherThread extends Thread
     {
-        private volatile boolean stop;
-
+        /** A field used to tell the thread it should stop */
+        private volatile boolean stop = false;
+        
+        /** A mutex used to make the thread sleeping for a moment */
+        private final Object mutex = new Object();
 
         public RefresherThread()
         {
@@ -994,7 +1006,7 @@ public class SyncReplConsumer implements
                     doSyncSearch( SynchronizationModeEnum.REFRESH_ONLY, false );
 
                     LOG.info( "--------------------- Sleep for a little while ------------------"
);
-                    Thread.sleep( config.getRefreshInterval() );
+                    mutex.wait( config.getRefreshInterval() );
                     LOG.debug( "--------------------- syncing again ------------------" );
 
                 }
@@ -1013,8 +1025,9 @@ public class SyncReplConsumer implements
         public void stopRefreshing()
         {
             stop = true;
-            // just incase if it is sleeping
-            this.interrupt();
+            
+            // just in case if it is sleeping, wake up the thread
+            mutex.notify();
         }
     }
 

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=1151285&r1=1151284&r2=1151285&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 Jul 26 22:57:56 2011
@@ -378,7 +378,6 @@ public class SyncReplRequestHandler impl
 
     private void doInitialRefresh( LdapSession session, SearchRequest req ) throws Exception
     {
-
         String originalFilter = req.getFilter().toString();
         InetSocketAddress address = ( InetSocketAddress ) session.getIoSession().getRemoteAddress();
         String hostName = address.getAddress().getHostName();
@@ -481,7 +480,7 @@ public class SyncReplRequestHandler impl
         }
 
         // if all is well then store the consumer infor
-        replicaUtil.addConsumerEntry( replicaLog );
+        replicaUtil.addConsumerEntry(replicaLog );
 
         // add to the map only after storing in the DIT, else the Replica update thread barfs
         replicaLogMap.put( replicaLog.getId(), replicaLog );
@@ -856,20 +855,20 @@ public class SyncReplRequestHandler impl
     {
         try
         {
-
             List<ReplicaEventLog> eventLogs = replicaUtil.getReplicaEventLogs();
+            
             if ( !eventLogs.isEmpty() )
             {
-                for ( ReplicaEventLog r : eventLogs )
+                for ( ReplicaEventLog replica : eventLogs )
                 {
-                    LOG.debug( "initializing the replica log from {}", r.getId() );
-                    r.configure( amqConnection, brokerService );
-                    replicaLogMap.put( r.getId(), r );
+                    LOG.debug( "initializing the replica log from {}", replica.getId() );
+                    replica.configure( amqConnection, brokerService );
+                    replicaLogMap.put( replica.getId(), replica );
 
                     // update the replicaCount's value to assign a correct value to the new
replica(s) 
-                    if ( replicaCount.get() < r.getId() )
+                    if ( replicaCount.get() < replica.getId() )
                     {
-                        replicaCount.set( r.getId() );
+                        replicaCount.set( replica.getId() );
                     }
                 }
             }

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncreplConfiguration.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncreplConfiguration.java?rev=1151285&r1=1151284&r2=1151285&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncreplConfiguration.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncreplConfiguration.java
Tue Jul 26 22:57:56 2011
@@ -30,22 +30,44 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.model.message.SearchScope;
 import org.apache.directory.shared.ldap.model.name.Dn;
-import org.apache.directory.shared.util.Strings;
 
 
 /**
- * 
- * A class for holding the syncrepl consumer's configuration.
+ * A class for holding the syncrepl consumer's configuration. the following parameters
+ * are part of the Syncrepl Consuer configuration :<br>
+ * <ul>
+ *   <li>remoteHost : the remote server's name, defaults to 'localhost'</li>
+ *   <li>remotePort : the remote server's LDAP port, defaults to 389</li>
+ *   <li>replUserDn : The replication User's DN</li>
+ *   <li>replUserPassword : The replication User's password</li>
+ *   <li>refreshNPersist : the replication mode, defaults to 'true'</li>
+ *   <li>refreshInterval : the interval between replications when in refreshOnly mode,
defaults to 60s</li>
+ *   <li>baseDn : the base from which to fetch entries on the remote server</li>
+ *   <li>filter : the filter to select entries,defaults to (ObjectClass=*)</li>
+ *   <li>attributes : the list of attributes to replicate, defaults to all</li>
+ *   <li>searchSizeLimit : the maximum number of entries to fetch, defaults to no limit</li>
+ *   <li>searchTimeout : the maximum delay to wait for entries, defaults to no limit</li>
+ *   <li>searchScope : the scope, defaults to SUBTREE</li>
+ *   <li>aliasDerefMode : set the aliss derefence policy, defaults to NEVER </li>
+ *   <li>replicaId : the replica identifier</li>
+ *   <li>configEntryDn : the configuration entry's DN</li>
+ *   <li>chaseReferrals : tells if we chase referrals, defaults to false</li>
+ *   <li>cookie : the replication cookie</li>
+ *   <li>useTls : the connection uses TLS, defaults to true</li>
+ *   <li>strictCertVerification : strictly verify the certificate, defaults to true</li>
+ *   <li>trustManager : the trustManager to use, defaults to @link{NoVerificationTrustManager}</li>
+ *   <li></li>
+ * </ul>
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class SyncreplConfiguration implements ReplicationConsumerConfig
 {
-    /** host name of the syncrepl provider server, default value is localhost */
-    private String providerHost = "localhost";
+    /** host name of the syncrepl remote server, default value is localhost */
+    private String remoteHost = "localhost";
 
     /** port number of the syncrepl provider server, default is 389 */
-    private int port = 389;
+    private int remotePort = 389;
 
     /** replication user's Dn */
     private String replUserDn;
@@ -68,7 +90,7 @@ public class SyncreplConfiguration imple
     /** names of attributes to be replicated, default value is all user attributes */
     private Set<String> attributes;
 
-    /** the numer for setting the limit on number of search results to be fetched
+    /** the maximum number of search results to be fetched
      * default value is 0 (i.e no limit) */
     private int searchSizeLimit = 0;
 
@@ -88,6 +110,7 @@ public class SyncreplConfiguration imple
     /** the replica's id */
     private int replicaId;
 
+    /** The configuration entry DN */
     private Dn configEntryDn = null;
 
     /** flag to indicate whether to chase referrals or not, default is false hence passes
ManageDsaITControl with syncsearch request*/
@@ -114,38 +137,38 @@ public class SyncreplConfiguration imple
 
 
     /**
-     * @return the providerHost
+     * @return the remote Host
      */
-    public String getProviderHost()
+    public String getRemoteHost()
     {
-        return providerHost;
+        return remoteHost;
     }
 
 
     /**
-     * @param providerHost the providerHost to set
+     * @param remoteHost the remote Host to set
      */
-    public void setProviderHost( String providerHost )
+    public void setRemoteHost( String remoteHost )
     {
-        this.providerHost = providerHost;
+        this.remoteHost = remoteHost;
     }
 
 
     /**
      * @return the port
      */
-    public int getPort()
+    public int getRemotePort()
     {
-        return port;
+        return remotePort;
     }
 
 
     /**
-     * @param port the port to set
+     * @param remotePort the remote port to set
      */
-    public void setPort( int port )
+    public void setRemotePort( int remotePort )
     {
-        this.port = port;
+        this.remotePort = remotePort;
     }
 
 



Mime
View raw message