From c22404d2ae49ed50c10f0da2f8d7ed032ebd5fed Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Tue, 04 Sep 2007 23:54:02 +0000
Subject: [PATCH] Add a new LDIF connection handler, which can be used to watch for new LDIF files to be created in a directory, at which point the changes contained in those LDIF files will be processed by the server using internal operations. This can potentially be used to make configuration changes or invoke tasks if the server is unresponsive to external clients (e.g., all worker threads are busy).

---
 opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java |  133 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 122 insertions(+), 11 deletions(-)

diff --git a/opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java b/opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
index 14aaebb..3612521 100644
--- a/opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
+++ b/opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
@@ -25,18 +25,9 @@
  *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
  */
 package org.opends.server.protocols.internal;
-import org.opends.messages.Message;
 
 
 
-import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.server.loggers.ErrorLogger.logError;
-import static org.opends.server.loggers.debug.DebugLogger.*;
-import static org.opends.messages.ProtocolMessages.*;
-
-import static org.opends.server.util.ServerConstants.*;
-import static org.opends.server.util.StaticUtils.getExceptionMessage;
-
 import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
@@ -49,6 +40,7 @@
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.opends.messages.Message;
 import org.opends.server.api.ClientConnection;
 import org.opends.server.api.ConnectionHandler;
 import org.opends.server.api.ConnectionSecurityProvider;
@@ -71,8 +63,6 @@
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.DisconnectReason;
 import org.opends.server.types.Entry;
-
-
 import org.opends.server.types.IntermediateResponse;
 import org.opends.server.types.LDAPException;
 import org.opends.server.types.Modification;
@@ -88,6 +78,17 @@
 import org.opends.server.types.SearchResultEntry;
 import org.opends.server.types.SearchResultReference;
 import org.opends.server.types.SearchScope;
+import org.opends.server.util.AddChangeRecordEntry;
+import org.opends.server.util.DeleteChangeRecordEntry;
+import org.opends.server.util.ModifyChangeRecordEntry;
+import org.opends.server.util.ModifyDNChangeRecordEntry;
+
+import static org.opends.messages.ProtocolMessages.*;
+import static org.opends.server.config.ConfigConstants.*;
+import static org.opends.server.loggers.ErrorLogger.logError;
+import static org.opends.server.loggers.debug.DebugLogger.*;
+import static org.opends.server.util.ServerConstants.*;
+import static org.opends.server.util.StaticUtils.*;
 
 
 
@@ -933,6 +934,54 @@
 
 
   /**
+   * Processes an internal add operation based on the provided add
+   * change record entry.
+   *
+   * @param  addRecord  The add change record entry to be processed.
+   *
+   * @return  A reference to the add operation that was processed and
+   *          contains information about the result of the processing.
+   */
+  public AddOperation processAdd(AddChangeRecordEntry addRecord)
+  {
+    LinkedHashMap<ObjectClass,String> objectClasses =
+         new LinkedHashMap<ObjectClass,String>();
+    LinkedHashMap<AttributeType,List<Attribute>> userAttrs =
+         new LinkedHashMap<AttributeType,List<Attribute>>();
+    LinkedHashMap<AttributeType,List<Attribute>> opAttrs =
+         new LinkedHashMap<AttributeType,List<Attribute>>();
+
+    Entry e = new Entry(addRecord.getDN(), objectClasses, userAttrs,
+                        opAttrs);
+
+    ArrayList<AttributeValue> duplicateValues =
+         new ArrayList<AttributeValue>();
+    for (Attribute a : addRecord.getAttributes())
+    {
+      if (a.getAttributeType().isObjectClassType())
+      {
+        for (AttributeValue v : a.getValues())
+        {
+          String ocName = v.getStringValue();
+          String lowerName = toLowerCase(ocName);
+          ObjectClass oc = DirectoryServer.getObjectClass(lowerName,
+                                                          true);
+          objectClasses.put(oc, ocName);
+        }
+      }
+      else
+      {
+        e.addAttribute(a, duplicateValues);
+      }
+    }
+
+    return processAdd(addRecord.getDN(), objectClasses, userAttrs,
+                      opAttrs);
+  }
+
+
+
+  /**
    * Processes an internal bind operation with the provided
    * information.  Note that regardless of whether the bind is
    * successful, the authentication state for this internal connection
@@ -1224,6 +1273,25 @@
 
 
   /**
+   * Processes an internal delete operation with the provided
+   * information.
+   *
+   * @param  deleteRecord  The delete change record entry to be
+   *                       processed.
+   *
+   * @return  A reference to the delete operation that was processed
+   *          and contains information about the result of the
+   *          processing.
+   */
+  public DeleteOperation processDelete(
+                              DeleteChangeRecordEntry deleteRecord)
+  {
+    return processDelete(deleteRecord.getDN());
+  }
+
+
+
+  /**
    * Processes an internal extended operation with the provided
    * information.
    *
@@ -1332,6 +1400,26 @@
 
 
   /**
+   * Processes an internal modify operation with the provided
+   * information.
+   *
+   * @param  modifyRecord  The modify change record entry with
+   *                       information about the changes to perform.
+   *
+   * @return  A reference to the modify operation that was processed
+   *          and contains information about the result of the
+   *          processing.
+   */
+  public ModifyOperation processModify(
+                              ModifyChangeRecordEntry modifyRecord)
+  {
+    return processModify(modifyRecord.getDN().toString(),
+                         modifyRecord.getModifications());
+  }
+
+
+
+  /**
    * Processes an internal modify DN operation with the provided
    * information.
    *
@@ -1498,6 +1586,29 @@
 
 
   /**
+   * Processes an internal modify DN operation with the provided
+   * information.
+   *
+   * @param  modifyDNRecord  The modify DN change record entry with
+   *                         information about the processing to
+   *                         perform.
+   *
+   * @return  A reference to the modify DN operation that was
+   *          processed and contains information about the result of
+   *          the processing.
+   */
+  public ModifyDNOperation processModifyDN(
+              ModifyDNChangeRecordEntry modifyDNRecord)
+  {
+    return processModifyDN(modifyDNRecord.getDN(),
+                           modifyDNRecord.getNewRDN(),
+                           modifyDNRecord.deleteOldRDN(),
+                           modifyDNRecord.getNewSuperiorDN());
+  }
+
+
+
+  /**
    * Processes an internal search operation with the provided
    * information.  It will not dereference any aliases, will not
    * request a size or time limit, and will retrieve all user

--
Gitblit v1.10.0