From 758558fed58b50e92cff9ca926f0e1b8267d29b5 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 17 Dec 2013 12:32:13 +0000
Subject: [PATCH] OPENDJ-1255 SEVERE_ERROR (Socket closed) in logs/errors file after uninstallation of a replicated server
---
opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java | 58 ++++++++++++++++++++++++----------------------------------
1 files changed, 24 insertions(+), 34 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java
index 1991546..111d635 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java
@@ -46,8 +46,6 @@
public class MonitoringPublisher extends DirectoryThread
{
- private volatile boolean shutdown = false;
-
/**
* The tracer object for the debug logger.
*/
@@ -59,9 +57,6 @@
/** Sleep time (in ms) before sending new monitoring messages. */
private volatile long period;
- /** Whether the thread is terminated. */
- private volatile boolean done = false;
-
private final Object shutdownLock = new Object();
/**
@@ -95,16 +90,8 @@
try
{
- while (!shutdown)
+ while (!isShutdownInitiated())
{
- synchronized (shutdownLock)
- {
- if (!shutdown)
- {
- shutdownLock.wait(period);
- }
- }
-
// Send global topology information to peer DSs
final int senderId = domain.getLocalRSServerId();
final MonitorMsg monitorMsg =
@@ -112,6 +99,11 @@
for (ServerHandler serverHandler : domain.getConnectedDSs().values())
{
+ // send() can be long operation, check for shutdown between each calls
+ if (isShutdownInitiated())
+ {
+ break;
+ }
monitorMsg.setDestination(serverHandler.getServerId());
try
{
@@ -122,6 +114,15 @@
// Server is disconnecting ? Forget it
}
}
+
+ synchronized (shutdownLock)
+ {
+ // double check to ensure the call to notify() was not missed
+ if (!isShutdownInitiated())
+ {
+ shutdownLock.wait(period);
+ }
+ }
}
}
catch (InterruptedException e)
@@ -130,7 +131,6 @@
"Monitoring publisher has been interrupted while sleeping."));
}
- done = true;
TRACER.debugInfo(getMessage("Monitoring publisher is terminated."));
}
@@ -141,15 +141,14 @@
*/
public void shutdown()
{
+ initiateShutdown();
synchronized (shutdownLock)
{
- shutdown = true;
shutdownLock.notifyAll();
-
- if (debugEnabled())
- {
- TRACER.debugInfo(getMessage("Shutting down monitoring publisher."));
- }
+ }
+ if (debugEnabled())
+ {
+ TRACER.debugInfo(getMessage("Shutting down monitoring publisher."));
}
}
@@ -161,19 +160,10 @@
{
try
{
- int FACTOR = 40; // Wait for 2 seconds before interrupting the thread
- int n = 0;
- while (!done && isAlive())
- {
- Thread.sleep(50);
- n++;
- if (n >= FACTOR)
- {
- TRACER.debugInfo(getMessage("Interrupting monitoring publisher."));
- interrupt();
- }
- }
- } catch (InterruptedException e)
+ // Here, "this" is the monitoring publisher thread
+ this.join(2000);
+ }
+ catch (InterruptedException e)
{
// exit the loop if this thread is interrupted.
}
--
Gitblit v1.10.0