From 9c954f1411d833f43c98ad3bc607c4ec4f07aaf5 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Fri, 08 Jun 2007 18:50:35 +0000
Subject: [PATCH] Fixed an issue where the error log doesn't actually log messages. Also improved the performance of the loggers when they are disabled.
---
opends/src/server/org/opends/server/loggers/AsyncronousTextWriter.java | 54 +++++++++++++++++++-----------------------------------
1 files changed, 19 insertions(+), 35 deletions(-)
diff --git a/opends/src/server/org/opends/server/loggers/AsyncronousTextWriter.java b/opends/src/server/org/opends/server/loggers/AsyncronousTextWriter.java
index a294791..a0e4a5d 100644
--- a/opends/src/server/org/opends/server/loggers/AsyncronousTextWriter.java
+++ b/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()) {
--
Gitblit v1.10.0