FileDocCategorySizeDatePackage
ReceiverBase.javaAPI DocApache Tomcat 6.0.1412452Fri Jul 20 04:20:34 BST 2007org.apache.catalina.tribes.transport

ReceiverBase

public abstract class ReceiverBase extends Object implements RxTaskPool.TaskCreator, org.apache.catalina.tribes.ChannelReceiver, org.apache.catalina.tribes.io.ListenCallback

Title:

Description:

Company:

author
not attributable
version
1.0

Fields Summary
public static final int
OPTION_DIRECT_BUFFER
protected static org.apache.juli.logging.Log
log
private org.apache.catalina.tribes.MessageListener
listener
private String
host
private InetAddress
bind
private int
port
private int
securePort
private int
rxBufSize
private int
txBufSize
private boolean
listen
private RxTaskPool
pool
private boolean
direct
private long
tcpSelectorTimeout
private int
autoBind
private int
maxThreads
private int
minThreads
private int
maxTasks
private int
minTasks
private boolean
tcpNoDelay
private boolean
soKeepAlive
private boolean
ooBInline
private boolean
soReuseAddress
private boolean
soLingerOn
private int
soLingerTime
private int
soTrafficClass
private int
timeout
private boolean
useBufferPool
private ExecutorService
executor
Constructors Summary
public ReceiverBase()



      
    
Methods Summary
protected intbind(java.net.ServerSocket socket, int portstart, int retries)
recursive bind to find the next available port

param
socket ServerSocket
param
portstart int
param
retries int
return
int
throws
IOException

        InetSocketAddress addr = null;
        while ( retries > 0 ) {
            try {
                addr = new InetSocketAddress(getBind(), portstart);
                socket.bind(addr);
                setPort(portstart);
                log.info("Receiver Server Socket bound to:"+addr);
                return 0;
            }catch ( IOException x) {
                retries--;
                if ( retries <= 0 ) {
                    log.info("Unable to bind server socket to:"+addr+" throwing error.");
                    throw x;
                }
                portstart++;
                try {Thread.sleep(25);}catch( InterruptedException ti){Thread.currentThread().interrupted();}
                retries = bind(socket,portstart,retries);
            }
        }
        return retries;
    
public booleandoListen()

        return listen;
    
public java.lang.StringgetAddress()

        getBind();
        return this.host;
    
public intgetAutoBind()

        return autoBind;
    
public java.net.InetAddressgetBind()

return
Returns the bind.

        if (bind == null) {
            try {
                if ("auto".equals(host)) {
                    host = java.net.InetAddress.getLocalHost().getHostAddress();
                }
                if (log.isDebugEnabled())
                    log.debug("Starting replication listener on address:"+ host);
                bind = java.net.InetAddress.getByName(host);
            } catch (IOException ioe) {
                log.error("Failed bind replication listener on address:"+ host, ioe);
            }
        }
        return bind;
    
public booleangetDirect()

        return direct;
    
public java.util.concurrent.ExecutorServicegetExecutor()

        return executor;
    
public java.lang.StringgetHost()

        return getAddress();
    
public org.apache.catalina.tribes.MessageListenergetListener()

        return listener;
    
public intgetMaxTasks()

        return maxTasks;
    
public intgetMaxThreads()

        return maxThreads;
    
public org.apache.catalina.tribes.MessageListenergetMessageListener()
getMessageListener

return
MessageListener
todo
Implement this org.apache.catalina.tribes.ChannelReceiver method

        return listener;
    
public intgetMinTasks()

        return minTasks;
    
public intgetMinThreads()

        return minThreads;
    
public booleangetOoBInline()

        return ooBInline;
    
public intgetPort()

return
The port
todo
Implement this org.apache.catalina.tribes.ChannelReceiver method

        return port;
    
public intgetRxBufSize()

        return rxBufSize;
    
public intgetSecurePort()

        return securePort;
    
public longgetSelectorTimeout()

        return tcpSelectorTimeout;
    
public booleangetSoKeepAlive()

        return soKeepAlive;
    
public booleangetSoLingerOn()

        return soLingerOn;
    
public intgetSoLingerTime()

        return soLingerTime;
    
public booleangetSoReuseAddress()

        return soReuseAddress;
    
public intgetSoTrafficClass()

        return soTrafficClass;
    
public RxTaskPoolgetTaskPool()

        return pool;
    
public java.lang.StringgetTcpListenAddress()

deprecated
use getAddress
return
String

        return getAddress();
    
public intgetTcpListenPort()

deprecated
use getPort
return
int

        return getPort();
    
public booleangetTcpNoDelay()

        return tcpNoDelay;
    
public longgetTcpSelectorTimeout()

deprecated
use getSelectorTimeout
return
long

        return getSelectorTimeout();
    
public intgetTcpThreadCount()

deprecated
use getMinThreads()/getMaxThreads()
return
int

        return getMaxThreads();
    
public intgetTimeout()

        return timeout;
    
public intgetTxBufSize()

        return txBufSize;
    
public booleangetUseBufferPool()

        return useBufferPool;
    
public intgetWorkerThreadOptions()

        int options = 0;
        if ( getDirect() ) options = options | OPTION_DIRECT_BUFFER;
        return options;
    
public voidheartbeat()

        //empty operation
    
public booleanisListening()

        return listen;
    
public voidmessageDataReceived(org.apache.catalina.tribes.ChannelMessage data)

        if ( this.listener != null ) {
            if ( listener.accept(data) ) listener.messageReceived(data);
        }
    
public voidsetAddress(java.lang.String host)

        this.host = host;
    
public voidsetAutoBind(int autoBind)

        this.autoBind = autoBind;
        if ( this.autoBind <= 0 ) this.autoBind = 1;
    
public voidsetBind(java.net.InetAddress bind)

param
bind The bind to set.

        this.bind = bind;
    
public voidsetDirect(boolean direct)

        this.direct = direct;
    
public voidsetExecutor(java.util.concurrent.ExecutorService executor)

        this.executor = executor;
    
public voidsetHost(java.lang.String host)

        setAddress(host);
    
public voidsetListen(boolean doListen)

        this.listen = doListen;
    
public voidsetListener(org.apache.catalina.tribes.MessageListener listener)

        this.listener = listener;
    
public voidsetLog(org.apache.juli.logging.Log log)

        this.log = log;
    
public voidsetMaxTasks(int maxTasks)

        this.maxTasks = maxTasks;
    
public voidsetMaxThreads(int maxThreads)

        this.maxThreads = maxThreads;
    
public voidsetMessageListener(org.apache.catalina.tribes.MessageListener listener)
setMessageListener

param
listener MessageListener
todo
Implement this org.apache.catalina.tribes.ChannelReceiver method

        this.listener = listener;
    
public voidsetMinTasks(int minTasks)

        this.minTasks = minTasks;
    
public voidsetMinThreads(int minThreads)

        this.minThreads = minThreads;
    
public voidsetOoBInline(boolean ooBInline)

        this.ooBInline = ooBInline;
    
public voidsetPool(RxTaskPool pool)

        this.pool = pool;
    
public voidsetPort(int port)

        this.port = port;
    
public voidsetRxBufSize(int rxBufSize)

        this.rxBufSize = rxBufSize;
    
public voidsetSecurePort(int securePort)

        this.securePort = securePort;
    
public voidsetSelectorTimeout(long selTimeout)

        tcpSelectorTimeout = selTimeout;
    
public voidsetSoKeepAlive(boolean soKeepAlive)

        this.soKeepAlive = soKeepAlive;
    
public voidsetSoLingerOn(boolean soLingerOn)

        this.soLingerOn = soLingerOn;
    
public voidsetSoLingerTime(int soLingerTime)

        this.soLingerTime = soLingerTime;
    
public voidsetSoReuseAddress(boolean soReuseAddress)

        this.soReuseAddress = soReuseAddress;
    
public voidsetSoTrafficClass(int soTrafficClass)

        this.soTrafficClass = soTrafficClass;
    
public voidsetTcpListenAddress(java.lang.String tcpListenHost)

deprecated
use setAddress
param
tcpListenHost String

        setAddress(tcpListenHost);
    
public voidsetTcpListenPort(int tcpListenPort)

deprecated
use setPort
param
tcpListenPort int

        setPort(tcpListenPort);
    
public voidsetTcpNoDelay(boolean tcpNoDelay)

        this.tcpNoDelay = tcpNoDelay;
    
public voidsetTcpSelectorTimeout(long selTimeout)

deprecated
use setSelectorTimeout
param
selTimeout long

        setSelectorTimeout(selTimeout);
    
public voidsetTcpThreadCount(int tcpThreadCount)

deprecated
use setMaxThreads/setMinThreads
param
tcpThreadCount int

        setMaxThreads(tcpThreadCount);
        setMinThreads(tcpThreadCount);
    
public voidsetTimeout(int timeout)

        this.timeout = timeout;
    
public voidsetTxBufSize(int txBufSize)

        this.txBufSize = txBufSize;
    
public voidsetUseBufferPool(boolean useBufferPool)

        this.useBufferPool = useBufferPool;
    
public voidstart()

        if ( executor == null ) {
            executor = new ThreadPoolExecutor(minThreads,maxThreads,60,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>());
        }
    
public voidstop()

        if ( executor != null ) executor.shutdownNow();//ignore left overs
        executor = null;