ch.qos.logback.core.net
Class SocketConnectorBase

java.lang.Object
  extended by ch.qos.logback.core.net.SocketConnectorBase
All Implemented Interfaces:
SocketConnector, Runnable

public class SocketConnectorBase
extends Object
implements SocketConnector

Base implementation of SocketConnector.

Author:
Carl Harris

Nested Class Summary
static interface SocketConnectorBase.DelayStrategy
          A strategy for choosing a delay after a failed connection attempt.
 
Nested classes/interfaces inherited from interface ch.qos.logback.core.net.SocketConnector
SocketConnector.ExceptionHandler
 
Constructor Summary
SocketConnectorBase(InetAddress address, int port, int initialDelay, int retryDelay)
          Constructs a new connector.
SocketConnectorBase(InetAddress address, int port, SocketConnectorBase.DelayStrategy delayStrategy)
          Constructs a new connector.
 
Method Summary
 Socket awaitConnection()
          Blocks the calling thread until a connection is successfully established.
 Socket awaitConnection(long delay)
          Blocks the calling thread until a connection is successfully established or timeout occurs.
 void run()
          
 void setExceptionHandler(SocketConnector.ExceptionHandler exceptionHandler)
          Sets the connector's exception handler.
 void setSocketFactory(SocketFactory socketFactory)
          Sets the connector's socket factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnectorBase

public SocketConnectorBase(InetAddress address,
                           int port,
                           int initialDelay,
                           int retryDelay)
Constructs a new connector.

Parameters:
address - address of remote listener
port - port of remote listener
initialDelay - delay before initial connection attempt
retryDelay - delay after failed connection attempt

SocketConnectorBase

public SocketConnectorBase(InetAddress address,
                           int port,
                           SocketConnectorBase.DelayStrategy delayStrategy)
Constructs a new connector.

Parameters:
address - address of remote listener
port - port of remote listener
delayStrategy - strategy for choosing the delay to impose before each connection attempt
Method Detail

run

public void run()

Specified by:
run in interface Runnable

awaitConnection

public Socket awaitConnection()
                       throws InterruptedException
Blocks the calling thread until a connection is successfully established.

Specified by:
awaitConnection in interface SocketConnector
Returns:
the connected socket
Throws:
InterruptedException

awaitConnection

public Socket awaitConnection(long delay)
                       throws InterruptedException
Blocks the calling thread until a connection is successfully established or timeout occurs.

Specified by:
awaitConnection in interface SocketConnector
Returns:
the connected socket or null if timeout occurs
Throws:
InterruptedException

setExceptionHandler

public void setExceptionHandler(SocketConnector.ExceptionHandler exceptionHandler)
Sets the connector's exception handler.

The handler must be set before the Runnable.run() method is invoked.

Specified by:
setExceptionHandler in interface SocketConnector
Parameters:
exceptionHandler - the handler to set

setSocketFactory

public void setSocketFactory(SocketFactory socketFactory)
Sets the connector's socket factory.

If no factory is configured that connector will use the platform's default factory.

Specified by:
setSocketFactory in interface SocketConnector
Parameters:
socketFactory - the factory to set


Copyright © 2005-2013 QOS.ch. All Rights Reserved.