| | |
| | | import org.opends.server.api.ServerShutdownListener; |
| | | import org.opends.server.core.DirectoryServer; |
| | | |
| | | import static org.opends.server.loggers.Debug.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugCought; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | |
| | | /** |
| | | * This class defines a thread that will be used for performing asynchronous |
| | |
| | | implements ServerShutdownListener |
| | | { |
| | | |
| | | private static final String CLASS_NAME = |
| | | "org.opends.server.loggers.LoggerThread"; |
| | | |
| | | private CopyOnWriteArrayList<RotationPolicy> rotationPolicies; |
| | | private CopyOnWriteArrayList<RetentionPolicy> retentionPolicies; |
| | | private LoggerAlarmHandler handler; |
| | |
| | | */ |
| | | public void run() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "run"); |
| | | |
| | | |
| | | this.loggerThread = Thread.currentThread(); |
| | | |
| | | while(! stopRequested) |
| | | while (!stopRequested) |
| | | { |
| | | try |
| | | { |
| | | sleep(time); |
| | | } |
| | | catch(InterruptedException e) |
| | | catch (InterruptedException e) |
| | | { |
| | | // We expect this to happen. |
| | | } |
| | | catch(Exception e) |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "run", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | |
| | | handler.flush(); |
| | | |
| | | if(rotationPolicies != null) |
| | | if (rotationPolicies != null) |
| | | { |
| | | for(RotationPolicy rotationPolicy : rotationPolicies) |
| | | for (RotationPolicy rotationPolicy : rotationPolicies) |
| | | { |
| | | if(rotationPolicy.rotateFile()) |
| | | if (rotationPolicy.rotateFile()) |
| | | { |
| | | handler.rollover(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(retentionPolicies != null) |
| | | if (retentionPolicies != null) |
| | | { |
| | | for(RetentionPolicy retentionPolicy : retentionPolicies) |
| | | for (RetentionPolicy retentionPolicy : retentionPolicies) |
| | | { |
| | | int numFilesDeleted = retentionPolicy.deleteFiles(); |
| | | System.out.println(numFilesDeleted + " files deleted"); |
| | |
| | | */ |
| | | public String getShutdownListenerName() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getShutdownListenerName"); |
| | | |
| | | |
| | | return "Logger Thread " + getName(); |
| | | } |
| | |
| | | */ |
| | | public void processServerShutdown(String reason) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "processServerShutdown", |
| | | String.valueOf(reason)); |
| | | |
| | | |
| | | stopRequested = true; |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "processServerShutdown", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | } |