org.fusesource.hawtdispatch.transport
Class TcpTransport

java.lang.Object
  extended by org.fusesource.hawtdispatch.transport.ServiceBase
      extended by org.fusesource.hawtdispatch.transport.TcpTransport
All Implemented Interfaces:
Transport
Direct Known Subclasses:
SslTransport

public class TcpTransport
extends ServiceBase
implements Transport

An implementation of the Transport interface using raw tcp/ip

Author:
Hiram Chirino

Nested Class Summary
 
Nested classes/interfaces inherited from class org.fusesource.hawtdispatch.transport.ServiceBase
ServiceBase.STARTING, ServiceBase.State, ServiceBase.STOPPING
 
Field Summary
protected  Executor blockingExecutor
           
protected  SocketChannel channel
           
protected  ProtocolCodec codec
           
protected  DispatchQueue dispatchQueue
           
protected  CustomDispatchSource<Integer,Integer> drainOutboundSource
           
static int IPTOS_LOWCOST
           
static int IPTOS_LOWDELAY
           
static int IPTOS_RELIABILITY
           
static int IPTOS_THROUGHPUT
           
protected  TransportListener listener
           
protected  URI localLocation
           
protected  org.fusesource.hawtdispatch.transport.TcpTransport.RateLimitingChannel rateLimitingChannel
           
protected  URI remoteLocation
           
protected  org.fusesource.hawtdispatch.transport.TcpTransport.SocketState socketState
           
protected  boolean useLocalHost
           
protected  CustomDispatchSource<Integer,Integer> yieldSource
           
 
Fields inherited from class org.fusesource.hawtdispatch.transport.ServiceBase
_serviceState, CREATED, STARTED, STOPPED
 
Constructor Summary
TcpTransport()
           
 
Method Summary
 void _start(Task onCompleted)
           
 void _stop(Task onCompleted)
           
 void connected(SocketChannel channel)
           
 void connecting(URI remoteLocation, URI localLocation)
           
 void drainInbound()
           
 void flush()
          Forces a flush of any output buffers.
 boolean full()
           
 Executor getBlockingExecutor()
           
 DispatchQueue getDispatchQueue()
          Returns the dispatch queue used by the transport
 SocketAddress getLocalAddress()
           
static InetAddress getLocalHost()
           
 int getMaxReadRate()
           
 int getMaxWriteRate()
           
 ProtocolCodec getProtocolCodec()
           
 ReadableByteChannel getReadChannel()
           
 int getReceiveBufferSize()
           
 SocketAddress getRemoteAddress()
           
 int getSendBufferSize()
           
 SocketChannel getSocketChannel()
           
 int getTrafficClass()
           
 TransportListener getTransportListener()
          Returns the current transport listener
 WritableByteChannel getWriteChannel()
           
protected  void initializeChannel()
           
protected  void initializeCodec()
           
 boolean isClosed()
           
 boolean isCloseOnCancel()
           
 boolean isConnected()
           
 boolean isKeepAlive()
           
 boolean isUseLocalHost()
           
 boolean offer(Object command)
          A one way asynchronous send of a command.
protected  void onConnected()
           
 void onTransportFailure(IOException error)
           
protected  String resolveHostName(String host)
           
 void resumeRead()
          resume delivery of commands.
protected  void resumeWrite()
           
 void setBlockingExecutor(Executor blockingExecutor)
           
 void setCloseOnCancel(boolean closeOnCancel)
           
 void setDispatchQueue(DispatchQueue queue)
          Sets the dispatch queue used by the transport
 void setKeepAlive(boolean keepAlive)
           
 void setMaxReadRate(int maxReadRate)
           
 void setMaxWriteRate(int maxWriteRate)
           
 void setProtocolCodec(ProtocolCodec protocolCodec)
          Sets the protocol codec for the transport
 void setReceiveBufferSize(int receiveBufferSize)
           
 void setSendBufferSize(int sendBufferSize)
           
 void setTrafficClass(int trafficClass)
           
 void setTransportListener(TransportListener transportListener)
          Registers an inbound command listener
 void setUseLocalHost(boolean useLocalHost)
          Sets whether 'localhost' or the actual local host name should be used to make local connections.
 void suspendRead()
          suspend delivery of commands.
protected  void suspendWrite()
           
protected  boolean transportFlush()
           
 
Methods inherited from class org.fusesource.hawtdispatch.transport.ServiceBase
getServiceState, start, start, stop, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.fusesource.hawtdispatch.transport.Transport
start, start, stop, stop
 

Field Detail

remoteLocation

protected URI remoteLocation

localLocation

protected URI localLocation

listener

protected TransportListener listener

codec

protected ProtocolCodec codec

channel

protected SocketChannel channel

socketState

protected org.fusesource.hawtdispatch.transport.TcpTransport.SocketState socketState

dispatchQueue

protected DispatchQueue dispatchQueue

drainOutboundSource

protected CustomDispatchSource<Integer,Integer> drainOutboundSource

yieldSource

protected CustomDispatchSource<Integer,Integer> yieldSource

useLocalHost

protected boolean useLocalHost

IPTOS_LOWCOST

public static final int IPTOS_LOWCOST
See Also:
Constant Field Values

IPTOS_RELIABILITY

public static final int IPTOS_RELIABILITY
See Also:
Constant Field Values

IPTOS_THROUGHPUT

public static final int IPTOS_THROUGHPUT
See Also:
Constant Field Values

IPTOS_LOWDELAY

public static final int IPTOS_LOWDELAY
See Also:
Constant Field Values

rateLimitingChannel

protected org.fusesource.hawtdispatch.transport.TcpTransport.RateLimitingChannel rateLimitingChannel

blockingExecutor

protected Executor blockingExecutor
Constructor Detail

TcpTransport

public TcpTransport()
Method Detail

getLocalHost

public static InetAddress getLocalHost()
                                throws UnknownHostException
Throws:
UnknownHostException

connected

public void connected(SocketChannel channel)
               throws IOException,
                      Exception
Throws:
IOException
Exception

initializeChannel

protected void initializeChannel()
                          throws Exception
Throws:
Exception

initializeCodec

protected void initializeCodec()
                        throws Exception
Throws:
Exception

connecting

public void connecting(URI remoteLocation,
                       URI localLocation)
                throws Exception
Throws:
Exception

getDispatchQueue

public DispatchQueue getDispatchQueue()
Description copied from interface: Transport
Returns the dispatch queue used by the transport

Specified by:
getDispatchQueue in interface Transport
Specified by:
getDispatchQueue in class ServiceBase
Returns:

setDispatchQueue

public void setDispatchQueue(DispatchQueue queue)
Description copied from interface: Transport
Sets the dispatch queue used by the transport

Specified by:
setDispatchQueue in interface Transport

_start

public void _start(Task onCompleted)
Specified by:
_start in class ServiceBase

_stop

public void _stop(Task onCompleted)
Specified by:
_stop in class ServiceBase

resolveHostName

protected String resolveHostName(String host)
                          throws UnknownHostException
Throws:
UnknownHostException

onConnected

protected void onConnected()
                    throws IOException
Throws:
IOException

onTransportFailure

public void onTransportFailure(IOException error)

full

public boolean full()
Specified by:
full in interface Transport

offer

public boolean offer(Object command)
Description copied from interface: Transport
A one way asynchronous send of a command. Only sent if the the transport is not full.

Specified by:
offer in interface Transport
Returns:
true if the command was accepted.

flush

public void flush()
Description copied from interface: Transport
Forces a flush of any output buffers. Once the flush completes the listener's 'onRefill()' method will execute.

Specified by:
flush in interface Transport

transportFlush

protected boolean transportFlush()
                          throws IOException
Throws:
IOException

drainInbound

public void drainInbound()
Specified by:
drainInbound in interface Transport

getLocalAddress

public SocketAddress getLocalAddress()
Specified by:
getLocalAddress in interface Transport
Returns:
the remote address for this connection

getRemoteAddress

public SocketAddress getRemoteAddress()
Specified by:
getRemoteAddress in interface Transport
Returns:
the remote address for this connection

suspendRead

public void suspendRead()
Description copied from interface: Transport
suspend delivery of commands.

Specified by:
suspendRead in interface Transport

resumeRead

public void resumeRead()
Description copied from interface: Transport
resume delivery of commands.

Specified by:
resumeRead in interface Transport

suspendWrite

protected void suspendWrite()

resumeWrite

protected void resumeWrite()

getTransportListener

public TransportListener getTransportListener()
Description copied from interface: Transport
Returns the current transport listener

Specified by:
getTransportListener in interface Transport
Returns:

setTransportListener

public void setTransportListener(TransportListener transportListener)
Description copied from interface: Transport
Registers an inbound command listener

Specified by:
setTransportListener in interface Transport

getProtocolCodec

public ProtocolCodec getProtocolCodec()
Specified by:
getProtocolCodec in interface Transport
Returns:
The protocol codec for the transport.

setProtocolCodec

public void setProtocolCodec(ProtocolCodec protocolCodec)
                      throws Exception
Description copied from interface: Transport
Sets the protocol codec for the transport

Specified by:
setProtocolCodec in interface Transport
Throws:
Exception

isConnected

public boolean isConnected()
Specified by:
isConnected in interface Transport
Returns:
true if the transport is connected

isClosed

public boolean isClosed()
Specified by:
isClosed in interface Transport
Returns:
true if the transport is closed/stopped.

isUseLocalHost

public boolean isUseLocalHost()

setUseLocalHost

public void setUseLocalHost(boolean useLocalHost)
Sets whether 'localhost' or the actual local host name should be used to make local connections. On some operating systems such as Macs its not possible to connect as the local host name so localhost is better.


getSocketChannel

public SocketChannel getSocketChannel()

getReadChannel

public ReadableByteChannel getReadChannel()
Specified by:
getReadChannel in interface Transport

getWriteChannel

public WritableByteChannel getWriteChannel()
Specified by:
getWriteChannel in interface Transport

getMaxReadRate

public int getMaxReadRate()

setMaxReadRate

public void setMaxReadRate(int maxReadRate)

getMaxWriteRate

public int getMaxWriteRate()

setMaxWriteRate

public void setMaxWriteRate(int maxWriteRate)

getTrafficClass

public int getTrafficClass()

setTrafficClass

public void setTrafficClass(int trafficClass)

getReceiveBufferSize

public int getReceiveBufferSize()

setReceiveBufferSize

public void setReceiveBufferSize(int receiveBufferSize)

getSendBufferSize

public int getSendBufferSize()

setSendBufferSize

public void setSendBufferSize(int sendBufferSize)

isKeepAlive

public boolean isKeepAlive()

setKeepAlive

public void setKeepAlive(boolean keepAlive)

getBlockingExecutor

public Executor getBlockingExecutor()
Specified by:
getBlockingExecutor in interface Transport

setBlockingExecutor

public void setBlockingExecutor(Executor blockingExecutor)
Specified by:
setBlockingExecutor in interface Transport

isCloseOnCancel

public boolean isCloseOnCancel()

setCloseOnCancel

public void setCloseOnCancel(boolean closeOnCancel)


Copyright © 2010-2014 FuseSource, Corp.. All Rights Reserved.