View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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  package ch.qos.logback.core.net.server;
15  
16  /**
17   *
18   * A mock {@link Client} that notifies waiting thread when it has started, and
19   * waits to be interrupted before exiting.
20   *
21   * @author Carl Harris
22   */
23  class MockClient implements Client {
24  
25      private boolean running;
26      private boolean closed;
27  
28      public void run() {
29          synchronized (this) {
30              running = true;
31              notifyAll();
32              while (running && !Thread.currentThread().isInterrupted()) {
33                  try {
34                      wait();
35                  } catch (InterruptedException ex) {
36                      Thread.currentThread().interrupt();
37                  }
38              }
39          }
40      }
41  
42      public void close() {
43          synchronized (this) {
44              running = false;
45              closed = true;
46              notifyAll();
47          }
48      }
49  
50      public synchronized boolean isRunning() {
51          return running;
52      }
53  
54      public synchronized boolean isClosed() {
55          return closed;
56      }
57  
58  }