| | |
| | | package org.opends.server.replication.protocol; |
| | | |
| | | import org.opends.server.api.DirectoryThread; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugVerbose; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugInfo; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | |
| | | import java.io.IOException; |
| | | |
| | |
| | | */ |
| | | public class HeartbeatThread extends DirectoryThread |
| | | { |
| | | /** |
| | | * The tracer object for the debug logger. |
| | | */ |
| | | private static final DebugTracer TRACER = getTracer(); |
| | | |
| | | |
| | | /** |
| | | * For test purposes only to simulate loss of heartbeats. |
| | |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugInfo("Heartbeat thread is starting, interval is %d", |
| | | TRACER.debugInfo("Heartbeat thread is starting, interval is %d", |
| | | heartbeatInterval); |
| | | } |
| | | HeartbeatMessage heartbeatMessage = new HeartbeatMessage(); |
| | |
| | | long now = System.currentTimeMillis(); |
| | | if (debugEnabled()) |
| | | { |
| | | debugVerbose("Heartbeat thread awoke at %d, last message was sent " + |
| | | "at %d", now, session.getLastPublishTime()); |
| | | TRACER.debugVerbose("Heartbeat thread awoke at %d, last message " + |
| | | "was sent at %d", now, session.getLastPublishTime()); |
| | | } |
| | | |
| | | if (now > session.getLastPublishTime() + heartbeatInterval) |
| | |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugVerbose("Heartbeat sent at %d", now); |
| | | TRACER.debugVerbose("Heartbeat sent at %d", now); |
| | | } |
| | | session.publish(heartbeatMessage); |
| | | } |
| | |
| | | |
| | | if (debugEnabled()) |
| | | { |
| | | debugVerbose("Heartbeat thread sleeping for %d", sleepTime); |
| | | TRACER.debugVerbose("Heartbeat thread sleeping for %d", sleepTime); |
| | | } |
| | | Thread.sleep(sleepTime); |
| | | } |
| | |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugInfo("Heartbeat thread could not send a heartbeat."); |
| | | TRACER.debugInfo("Heartbeat thread could not send a heartbeat."); |
| | | } |
| | | // This will be caught in another thread. |
| | | } |
| | |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugInfo("Heartbeat thread is exiting."); |
| | | TRACER.debugInfo("Heartbeat thread is exiting."); |
| | | } |
| | | } |
| | | } |