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;
15  
16  import java.net.Socket;
17  import java.util.concurrent.Callable;
18  
19  import javax.net.SocketFactory;
20  
21  /**
22   * A {@link Runnable} that (re)connects a socket.
23   * <p>
24   * An implementation of this interface is responsible for repeatedly 
25   * attempting to create a socket connection to a remote host.
26   *
27   * @author Carl Harris
28   */
29  public interface SocketConnector extends Callable<Socket> {
30  
31      /**
32       * An exception handler that is notified of all exceptions that occur
33       * during the (re)connection process.
34       */
35      public interface ExceptionHandler {
36          void connectionFailed(SocketConnector connector, Exception ex);
37      }
38  
39      /**
40       * Blocks the calling thread until a connection is successfully
41       * established.
42       * @return the connected socket
43       * @throws InterruptedException
44       */
45      Socket call() throws InterruptedException;
46  
47      /**
48       * Sets the connector's exception handler.
49       * <p>
50       * The handler must be set before the {@link #call()} method is invoked.
51       * @param exceptionHandler the handler to set
52       */
53      void setExceptionHandler(ExceptionHandler exceptionHandler);
54  
55      /**
56       * Sets the connector's socket factory.
57       * <p>
58       * If no factory is configured that connector will use the platform's
59       * default factory.
60       * 
61       * @param socketFactory the factory to set
62       */
63      void setSocketFactory(SocketFactory socketFactory);
64  
65  }