From 3d755209dc2cab1dad0cf00843fbd3af009ecf62 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 06 Oct 2015 08:08:53 +0000
Subject: [PATCH] Removed the ParallelTextWriter experiment (never achieved?, never a success?)

---
 /dev/null                                                                                                                             |  250 -------------------------------
 opendj-server-legacy/src/main/java/org/opends/server/loggers/TextAccessLogPublisher.java                                              |   80 +---------
 opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedHTTPAccessLogPublisherConfiguration.xml |   18 --
 opendj-server-legacy/src/main/java/org/opends/server/loggers/TextHTTPAccessLogPublisher.java                                          |   80 +---------
 opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAccessLogPublisherConfiguration.xml     |   18 --
 opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAuditLogPublisherConfiguration.xml      |   18 --
 6 files changed, 22 insertions(+), 442 deletions(-)

diff --git a/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAccessLogPublisherConfiguration.xml b/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAccessLogPublisherConfiguration.xml
index d302926..d93b28a 100644
--- a/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAccessLogPublisherConfiguration.xml
+++ b/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAccessLogPublisherConfiguration.xml
@@ -74,27 +74,13 @@
       The maximum number of log records that can be stored in the
       asynchronous queue.
     </adm:synopsis>
-    <adm:description>
-      Setting the queue size to zero activates parallel log writer
-      implementation which has no queue size limit and as such the
-      parallel log writer should only be used on a very well tuned
-      server configuration to avoid potential out of memory errors.
-    </adm:description>
-    <adm:requires-admin-action>
-      <adm:other>
-        <adm:synopsis>
-          The <adm:user-friendly-name /> must be restarted if this property
-          is changed and the asynchronous property is set to true.
-        </adm:synopsis>
-      </adm:other>
-    </adm:requires-admin-action>
-        <adm:default-behavior>
+    <adm:default-behavior>
       <adm:defined>
         <adm:value>5000</adm:value>
       </adm:defined>
     </adm:default-behavior>
     <adm:syntax>
-      <adm:integer lower-limit="0" />
+      <adm:integer lower-limit="1" />
     </adm:syntax>
     <adm:profile name="ldap">
       <ldap:attribute>
diff --git a/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAuditLogPublisherConfiguration.xml b/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAuditLogPublisherConfiguration.xml
index eca7a3e..2ab6b41 100644
--- a/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAuditLogPublisherConfiguration.xml
+++ b/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedAuditLogPublisherConfiguration.xml
@@ -73,27 +73,13 @@
       The maximum number of log records that can be stored in the
       asynchronous queue.
     </adm:synopsis>
-    <adm:description>
-      Setting the queue size to zero activates parallel log writer
-      implementation which has no queue size limit and as such the
-      parallel log writer should only be used on a very well tuned
-      server configuration to avoid potential out of memory errors.
-    </adm:description>
-    <adm:requires-admin-action>
-      <adm:other>
-        <adm:synopsis>
-          The <adm:user-friendly-name /> must be restarted if this property 
-          is changed and the asynchronous property is set to true.
-        </adm:synopsis>
-      </adm:other>
-    </adm:requires-admin-action>
-        <adm:default-behavior>
+    <adm:default-behavior>
       <adm:defined>
         <adm:value>5000</adm:value>
       </adm:defined>
     </adm:default-behavior>
     <adm:syntax>
-      <adm:integer lower-limit="0" />
+      <adm:integer lower-limit="1" />
     </adm:syntax>
     <adm:profile name="ldap">
       <ldap:attribute>
diff --git a/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedHTTPAccessLogPublisherConfiguration.xml b/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedHTTPAccessLogPublisherConfiguration.xml
index df60884..841d210 100644
--- a/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedHTTPAccessLogPublisherConfiguration.xml
+++ b/opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/FileBasedHTTPAccessLogPublisherConfiguration.xml
@@ -73,27 +73,13 @@
       The maximum number of log records that can be stored in the
       asynchronous queue.
     </adm:synopsis>
-    <adm:description>
-      Setting the queue size to zero activates parallel log writer
-      implementation which has no queue size limit and as such the
-      parallel log writer should only be used on a very well tuned
-      server configuration to avoid potential out of memory errors.
-    </adm:description>
-    <adm:requires-admin-action>
-      <adm:other>
-        <adm:synopsis>
-          The <adm:user-friendly-name /> must be restarted if this property 
-          is changed and the asynchronous property is set to true.
-        </adm:synopsis>
-      </adm:other>
-    </adm:requires-admin-action>
-        <adm:default-behavior>
+    <adm:default-behavior>
       <adm:defined>
         <adm:value>5000</adm:value>
       </adm:defined>
     </adm:default-behavior>
     <adm:syntax>
-      <adm:integer lower-limit="0" />
+      <adm:integer lower-limit="1" />
     </adm:syntax>
     <adm:profile name="ldap">
       <ldap:attribute>
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/loggers/ParallelTextWriter.java b/opendj-server-legacy/src/main/java/org/opends/server/loggers/ParallelTextWriter.java
deleted file mode 100644
index 2cd8ba9..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/loggers/ParallelTextWriter.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Copyright 2006-2009 Sun Microsystems, Inc.
- *      Portions Copyright 2014-2015 ForgeRock AS
- */
-package org.opends.server.loggers;
-
-
-
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.opends.server.api.DirectoryThread;
-import org.opends.server.api.ServerShutdownListener;
-import org.opends.server.core.DirectoryServer;
-
-
-
-/**
- * A Text Writer which writes log records asynchronously to
- * character-based stream. Note that this implementation is
- * parallel unbound ie there is no queue size cap imposed.
- */
-class ParallelTextWriter
-    implements ServerShutdownListener, TextWriter
-{
-  /**
-   * The wrapped Text Writer.
-   */
-  private final TextWriter writer;
-
-  /** Queue to store unpublished records. */
-  private final ConcurrentLinkedQueue<String> queue;
-
-  private final Semaphore queueSemaphore = new Semaphore(0, false);
-
-  private String name;
-  private AtomicBoolean stopRequested;
-  private WriterThread writerThread;
-
-  private boolean autoFlush;
-
-  /**
-   * Construct a new ParallelTextWriter wrapper.
-   *
-   * @param name      the name of the thread.
-   * @param autoFlush indicates if the underlying writer should be flushed
-   *                  after the queue is flushed.
-   * @param writer    a character stream used for output.
-   */
-  public ParallelTextWriter(String name, boolean autoFlush, TextWriter writer)
-  {
-    this.name = name;
-    this.autoFlush = autoFlush;
-    this.writer = writer;
-
-    this.queue = new ConcurrentLinkedQueue<>();
-    this.writerThread = null;
-    this.stopRequested = new AtomicBoolean(false);
-
-    writerThread = new WriterThread();
-    writerThread.start();
-
-    DirectoryServer.registerShutdownListener(this);
-  }
-
-  /**
-   * The publisher thread is responsible for emptying the queue of log records
-   * waiting to published.
-   */
-  private class WriterThread extends DirectoryThread
-  {
-    public WriterThread()
-    {
-      super(name);
-    }
-    /**
-     * The run method of the writerThread. Run until queue is empty
-     * AND we've been asked to terminate
-     */
-    @Override
-    public void run()
-    {
-      while (!stopRequested.get())
-      {
-        try
-        {
-          if (queueSemaphore.tryAcquire(10, TimeUnit.SECONDS))
-          {
-            for (int i = (queueSemaphore.drainPermits() + 1); i > 0; i--)
-            {
-              String message = queue.poll();
-              if (message != null)
-              {
-                writer.writeRecord(message);
-              }
-              else
-              {
-                break;
-              }
-            }
-            if (autoFlush)
-            {
-              flush();
-            }
-          }
-        }
-        catch (InterruptedException ex)
-        {
-          // Ignore. We'll rerun the loop
-          // and presumably fall out.
-        }
-      }
-    }
-  }
-
-  /**
-   * Write the log record asyncronously.
-   *
-   * @param record the log record to write.
-   */
-  public void writeRecord(String record)
-  {
-    // No writer?  Off to the bit bucket.
-    if (writer != null) {
-      while (!stopRequested.get())
-      {
-        // Put request on queue for writer
-        queue.add(record);
-        queueSemaphore.release();
-        break;
-      }
-    }
-  }
-
-  /** {@inheritDoc} */
-  public void flush()
-  {
-    writer.flush();
-  }
-
-  /** {@inheritDoc} */
-  public long getBytesWritten()
-  {
-    return writer.getBytesWritten();
-  }
-
-  /**
-   * Retrieves the wrapped writer.
-   *
-   * @return The wrapped writer used by this asyncronous writer.
-   */
-  public TextWriter getWrappedWriter()
-  {
-    return writer;
-  }
-
-  /** {@inheritDoc} */
-  public String getShutdownListenerName()
-  {
-    return "ParallelTextWriter Thread " + name;
-  }
-
-  /** {@inheritDoc} */
-  public void processServerShutdown(LocalizableMessage reason)
-  {
-    // Don't shutdown the wrapped writer on server shutdown as it
-    // might get more write requests before the log publishers are
-    // manually shutdown just before the server process exists.
-    shutdown(false);
-  }
-
-  /** {@inheritDoc} */
-  public void shutdown()
-  {
-    shutdown(true);
-  }
-
-  /**
-   * Releases any resources held by the writer.
-   *
-   * @param shutdownWrapped If the wrapped writer should be closed as well.
-   */
-  public void shutdown(boolean shutdownWrapped)
-  {
-    stopRequested.set(true);
-
-    // Wait for publisher thread to terminate
-    while (writerThread != null && writerThread.isAlive()) {
-      try {
-        // Interrupt the thread if its blocking
-        writerThread.interrupt();
-        writerThread.join();
-      }
-      catch (InterruptedException ex) {
-        // Ignore; we gotta wait..
-      }
-    }
-
-    // The writer writerThread SHOULD have drained the queue.
-    // If not, handle outstanding requests ourselves,
-    // and push them to the writer.
-    while (!queue.isEmpty()) {
-      String message = queue.poll();
-      writer.writeRecord(message);
-    }
-
-    // Shutdown the wrapped writer.
-    if (shutdownWrapped && writer != null)
-    {
-      writer.shutdown();
-    }
-
-    DirectoryServer.deregisterShutdownListener(this);
-  }
-
-  /**
-   * Set the auto flush setting for this writer.
-   *
-   * @param autoFlush If the writer should flush the buffer after every line.
-   */
-  public void setAutoFlush(boolean autoFlush)
-  {
-    this.autoFlush = autoFlush;
-  }
-}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextAccessLogPublisher.java b/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextAccessLogPublisher.java
index 046bc25..054f21d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextAccessLogPublisher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextAccessLogPublisher.java
@@ -102,10 +102,6 @@
       {
         currentWriter = ((AsynchronousTextWriter) writer).getWrappedWriter();
       }
-      else if (writer instanceof ParallelTextWriter)
-      {
-        currentWriter = ((ParallelTextWriter) writer).getWrappedWriter();
-      }
       else
       {
         currentWriter = writer;
@@ -118,67 +114,25 @@
 
         if (config.isAsynchronous())
         {
-          if (useAsyncWriter(config))
+          if (writer instanceof AsynchronousTextWriter)
           {
-            if (writer instanceof AsynchronousTextWriter)
+            if (hasAsyncConfigChanged(config))
             {
-              if (hasAsyncConfigChanged(config))
-              {
-                // reinstantiate
-                final AsynchronousTextWriter previousWriter = (AsynchronousTextWriter) writer;
-                writer = newAsyncWriter(mfWriter, config);
-                previousWriter.shutdown(false);
-              }
-            }
-            else if (writer instanceof ParallelTextWriter)
-            {
-              // convert parallel to async
-              final ParallelTextWriter previousWriter = (ParallelTextWriter) writer;
+              // reinstantiate
+              final AsynchronousTextWriter previousWriter = (AsynchronousTextWriter) writer;
               writer = newAsyncWriter(mfWriter, config);
               previousWriter.shutdown(false);
             }
-            else
-            {
-              // turn async text writer on
-              writer = newAsyncWriter(mfWriter, config);
-            }
           }
           else
           {
-            if (writer instanceof AsynchronousTextWriter)
-            {
-              // convert async to parallel
-              final AsynchronousTextWriter previousWriter = (AsynchronousTextWriter) writer;
-              writer = newParallelWriter(mfWriter, config);
-              previousWriter.shutdown(false);
-            }
-            else if (writer instanceof ParallelTextWriter)
-            {
-              if (hasParallelConfigChanged(config))
-              {
-                // reinstantiate
-                final ParallelTextWriter previousWriter = (ParallelTextWriter) writer;
-                writer = newParallelWriter(mfWriter, config);
-                previousWriter.shutdown(false);
-              }
-            }
-            else
-            {
-              // turn parallel text writer on
-              writer = newParallelWriter(mfWriter, config);
-            }
+            // turn async text writer on
+            writer = newAsyncWriter(mfWriter, config);
           }
         }
         else
         {
-          if (writer instanceof ParallelTextWriter)
-          {
-            // asynchronous is being turned off, remove parallel text writers.
-            final ParallelTextWriter previousWriter = (ParallelTextWriter) writer;
-            writer = mfWriter;
-            previousWriter.shutdown(false);
-          }
-          else if (writer instanceof AsynchronousTextWriter)
+          if (writer instanceof AsynchronousTextWriter)
           {
             // asynchronous is being turned off, remove async text writers.
             final AsynchronousTextWriter previousWriter = (AsynchronousTextWriter) writer;
@@ -276,14 +230,7 @@
 
       if (cfg.isAsynchronous())
       {
-        if (useAsyncWriter(cfg))
-        {
-          this.writer = newAsyncWriter(theWriter, cfg);
-        }
-        else
-        {
-          this.writer = newParallelWriter(theWriter, cfg);
-        }
+        this.writer = newAsyncWriter(theWriter, cfg);
       }
       else
       {
@@ -311,11 +258,6 @@
     cfg.addFileBasedAccessChangeListener(this);
   }
 
-  private boolean useAsyncWriter(FileBasedAccessLogPublisherCfg config)
-  {
-    return config.getQueueSize() > 0;
-  }
-
   private boolean hasAsyncConfigChanged(FileBasedAccessLogPublisherCfg newConfig)
   {
     return hasParallelConfigChanged(newConfig) && cfg.getQueueSize() != newConfig.getQueueSize();
@@ -332,12 +274,6 @@
     return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), mfWriter);
   }
 
-  private ParallelTextWriter newParallelWriter(MultifileTextWriter mfWriter, FileBasedAccessLogPublisherCfg config)
-  {
-    String name = "Parallel Text Writer for " + config.dn();
-    return new ParallelTextWriter(name, config.isAutoFlush(), mfWriter);
-  }
-
   @Override
   public boolean isConfigurationAcceptable(
       final FileBasedAccessLogPublisherCfg configuration,
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextHTTPAccessLogPublisher.java b/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextHTTPAccessLogPublisher.java
index 839a7a8..2c37a58 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextHTTPAccessLogPublisher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextHTTPAccessLogPublisher.java
@@ -124,10 +124,6 @@
       {
         currentWriter = ((AsynchronousTextWriter) writer).getWrappedWriter();
       }
-      else if (writer instanceof ParallelTextWriter)
-      {
-        currentWriter = ((ParallelTextWriter) writer).getWrappedWriter();
-      }
       else
       {
         currentWriter = writer;
@@ -140,67 +136,25 @@
 
         if (config.isAsynchronous())
         {
-          if (useAsyncWriter(config))
+          if (writer instanceof AsynchronousTextWriter)
           {
-            if (writer instanceof AsynchronousTextWriter)
+            if (hasAsyncConfigChanged(config))
             {
-              if (hasAsyncConfigChanged(config))
-              {
-                // reinstantiate
-                final AsynchronousTextWriter previousWriter = (AsynchronousTextWriter) writer;
-                writer = newAsyncWriter(mfWriter, config);
-                previousWriter.shutdown(false);
-              }
-            }
-            else if (writer instanceof ParallelTextWriter)
-            {
-              // convert parallel to async
-              final ParallelTextWriter previousWriter = (ParallelTextWriter) writer;
+              // reinstantiate
+              final AsynchronousTextWriter previousWriter = (AsynchronousTextWriter) writer;
               writer = newAsyncWriter(mfWriter, config);
               previousWriter.shutdown(false);
             }
-            else
-            {
-              // turn async text writer on
-              writer = newAsyncWriter(mfWriter, config);
-            }
           }
           else
           {
-            if (writer instanceof AsynchronousTextWriter)
-            {
-              // convert async to parallel
-              final AsynchronousTextWriter previousWriter = (AsynchronousTextWriter) writer;
-              writer = newParallelWriter(mfWriter, config);
-              previousWriter.shutdown(false);
-            }
-            else if (writer instanceof ParallelTextWriter)
-            {
-              if (hasParallelConfigChanged(config))
-              {
-                // reinstantiate
-                final ParallelTextWriter previousWriter = (ParallelTextWriter) writer;
-                writer = newParallelWriter(mfWriter, config);
-                previousWriter.shutdown(false);
-              }
-            }
-            else
-            {
-              // turn parallel text writer on
-              writer = newParallelWriter(mfWriter, config);
-            }
+            // turn async text writer on
+            writer = newAsyncWriter(mfWriter, config);
           }
         }
         else
         {
-          if (writer instanceof ParallelTextWriter)
-          {
-            // asynchronous is being turned off, remove parallel text writers.
-            final ParallelTextWriter previousWriter = (ParallelTextWriter) writer;
-            writer = mfWriter;
-            previousWriter.shutdown(false);
-          }
-          else if (writer instanceof AsynchronousTextWriter)
+          if (writer instanceof AsynchronousTextWriter)
           {
             // asynchronous is being turned off, remove async text writers.
             final AsynchronousTextWriter previousWriter = (AsynchronousTextWriter) writer;
@@ -275,11 +229,6 @@
     return getFileForPath(config.getLogFile());
   }
 
-  private boolean useAsyncWriter(FileBasedHTTPAccessLogPublisherCfg config)
-  {
-    return config.getQueueSize() > 0;
-  }
-
   private boolean hasAsyncConfigChanged(FileBasedHTTPAccessLogPublisherCfg newConfig)
   {
     return hasParallelConfigChanged(newConfig) && cfg.getQueueSize() != newConfig.getQueueSize();
@@ -296,12 +245,6 @@
     return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), mfWriter);
   }
 
-  private ParallelTextWriter newParallelWriter(MultifileTextWriter mfWriter, FileBasedHTTPAccessLogPublisherCfg config)
-  {
-    String name = "Parallel Text Writer for " + config.dn();
-    return new ParallelTextWriter(name, config.isAutoFlush(), mfWriter);
-  }
-
   private List<String> extractFieldsOrder(String logFormat)
   {
     // there will always be at least one field value due to the regexp
@@ -386,14 +329,7 @@
 
       if (cfg.isAsynchronous())
       {
-        if (useAsyncWriter(cfg))
-        {
-          this.writer = newAsyncWriter(theWriter, cfg);
-        }
-        else
-        {
-          this.writer = newParallelWriter(theWriter, cfg);
-        }
+        this.writer = newAsyncWriter(theWriter, cfg);
       }
       else
       {

--
Gitblit v1.10.0