mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

boli
08.50.2007 cf3a52a7591faffc24a890b5baebfd260b929fcd
opendj-sdk/opends/src/server/org/opends/server/loggers/AsyncronousTextWriter.java
@@ -32,6 +32,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
/**
 * A Text Writer which writes log records asynchronously to
@@ -49,7 +50,7 @@
  private final LinkedBlockingQueue<String> queue;
  private String name;
  private boolean stopRequested;
  private AtomicBoolean stopRequested;
  private WriterThread writerThread;
  private boolean autoFlush;
@@ -72,7 +73,7 @@
    this.queue = new LinkedBlockingQueue<String>(capacity);
    this.writerThread = null;
    this.stopRequested = false;
    this.stopRequested = new AtomicBoolean(false);
    writerThread = new WriterThread();
    writerThread.start();
@@ -97,7 +98,7 @@
    public void run()
    {
      String message = null;
      while (!isShuttingDown() || !queue.isEmpty()) {
      while (!stopRequested.get() || !queue.isEmpty()) {
        try
        {
          message = queue.poll(10, TimeUnit.SECONDS);
@@ -124,28 +125,6 @@
    }
  }
  // Method needs to be synchronized with _shutdown mutator, as we don't
  // want shutdown to start after we check for it, but before we queue
  // request.
  private synchronized void writeAsynchronously(String record)
  {
    // If shutting down reject, otherwise publish (if we have a publisher!)
    while (!isShuttingDown())
    {
      // Put request on queue for writer
      try
      {
        queue.put(record);
        break;
      }
      catch(InterruptedException e)
      {
        // We expect this to happen. Just ignore it and hopefully
        // drop out in the next try.
      }
    }
  }
  /**
   * Write the log record asyncronously.
   *
@@ -155,7 +134,20 @@
  {
    // No writer?  Off to the bit bucket.
    if (writer != null) {
      writeAsynchronously(record);
      while (!stopRequested.get())
      {
        // Put request on queue for writer
        try
        {
          queue.put(record);
          break;
        }
        catch(InterruptedException e)
        {
          // We expect this to happen. Just ignore it and hopefully
          // drop out in the next try.
        }
      }
    }
  }
@@ -205,14 +197,6 @@
  }
  /**
   * Queries whether the publisher is in shutdown mode.
   */
  private boolean isShuttingDown()
  {
    return stopRequested;
  }
  /**
   * {@inheritDoc}
   */
  public void shutdown()
@@ -227,7 +211,7 @@
   */
  public void shutdown(boolean shutdownWrapped)
  {
    stopRequested = true;
    stopRequested.set(true);
    // Wait for publisher thread to terminate
    while (writerThread != null && writerThread.isAlive()) {