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 attempting
25 * 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 during the
33 * (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 established.
41 *
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 *
52 * @param exceptionHandler the handler to set
53 */
54 void setExceptionHandler(ExceptionHandler exceptionHandler);
55
56 /**
57 * Sets the connector's socket factory.
58 * <p>
59 * If no factory is configured that connector will use the platform's default
60 * factory.
61 *
62 * @param socketFactory the factory to set
63 */
64 void setSocketFactory(SocketFactory socketFactory);
65
66 }