001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.net;
015
016import java.net.Socket;
017import java.util.concurrent.Callable;
018
019import javax.net.SocketFactory;
020
021/**
022 * A {@link Runnable} that (re)connects a socket.
023 * <p>
024 * An implementation of this interface is responsible for repeatedly 
025 * attempting to create a socket connection to a remote host.
026 *
027 * @author Carl Harris
028 */
029public interface SocketConnector extends Callable<Socket> {
030
031    /**
032     * An exception handler that is notified of all exceptions that occur
033     * during the (re)connection process.
034     */
035    public interface ExceptionHandler {
036        void connectionFailed(SocketConnector connector, Exception ex);
037    }
038
039    /**
040     * Blocks the calling thread until a connection is successfully
041     * established.
042     * @return the connected socket
043     * @throws InterruptedException
044     */
045    Socket call() throws InterruptedException;
046
047    /**
048     * Sets the connector's exception handler.
049     * <p>
050     * The handler must be set before the {@link #call()} method is invoked.
051     * @param exceptionHandler the handler to set
052     */
053    void setExceptionHandler(ExceptionHandler exceptionHandler);
054
055    /**
056     * Sets the connector's socket factory.
057     * <p>
058     * If no factory is configured that connector will use the platform's
059     * default factory.
060     * 
061     * @param socketFactory the factory to set
062     */
063    void setSocketFactory(SocketFactory socketFactory);
064
065}