View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2022, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  
15  package ch.qos.logback.classic.joran;
16  
17  import ch.qos.logback.classic.LoggerContext;
18  import ch.qos.logback.core.contention.AbstractMultiThreadedHarness;
19  import ch.qos.logback.core.status.InfoStatus;
20  
21  import java.util.concurrent.CountDownLatch;
22  
23  class ReconfigureOnChangeTaskHarness extends AbstractMultiThreadedHarness {
24  
25      private final LoggerContext loggerContext;
26  
27      private final CountDownLatch countDownLatch;
28  
29      ReconfigureOnChangeTaskHarness(LoggerContext loggerContext, int aChangeCountLimit) {
30          this.loggerContext = loggerContext;
31          this.countDownLatch = new CountDownLatch(aChangeCountLimit);
32          ChangeDetectedListener cdl = new ChangeDetectedListener(countDownLatch);
33          loggerContext.addConfigurationEventListener(cdl);
34      }
35  
36      public void waitUntilEndCondition() throws InterruptedException {
37  
38          String classname = this.getClass().getSimpleName();
39  
40          loggerContext.getStatusManager()
41                  .add(new InfoStatus("Entering " + classname + ".waitUntilEndCondition()", this));
42          countDownLatch.await();
43          loggerContext.getStatusManager()
44                  .add(new InfoStatus("*****Exiting " + classname + ".waitUntilEndCondition()", this));
45      }
46  
47  }