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 attempting
025 * 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 during the
033     * (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 established.
041     * 
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     * 
052     * @param exceptionHandler the handler to set
053     */
054    void setExceptionHandler(ExceptionHandler exceptionHandler);
055
056    /**
057     * Sets the connector's socket factory.
058     * <p>
059     * If no factory is configured that connector will use the platform's default
060     * factory.
061     * 
062     * @param socketFactory the factory to set
063     */
064    void setSocketFactory(SocketFactory socketFactory);
065
066}