com.sun.grizzly
Interface Transport

All Superinterfaces:
ExceptionHandler
All Known Subinterfaces:
NIOTransport
All Known Implementing Classes:
AbstractNIOTransport, AbstractTransport, TCPNIOTransport, UDPNIOTransport

public interface Transport
extends ExceptionHandler

Transport interface describes the transport unit used in Grizzly. Transport implementation could operate over TCP, UDP or other custom protocol, using blocking, NIO or NIO.2 Java API.

Author:
Alexey Stashok

Nested Class Summary
static class Transport.State
           
 
Nested classes/interfaces inherited from interface com.sun.grizzly.utils.ExceptionHandler
ExceptionHandler.Severity
 
Method Summary
 void addExceptionHandler(ExceptionHandler handler)
          Add ExceptionHandler to handle errors, occurred during the Transport execution.
 void configureBlocking(boolean isBlocking)
          Sets the Transport mode.
 void fireIOEvent(IOEvent ioEvent, Connection connection)
          Fires specific IOEvent on the Connection
 void fireIOEvent(IOEvent ioEvent, Connection connection, Object strategyContext)
          Fires specific IOEvent on the Connection
 AttributeBuilder getAttributeBuilder()
          Get Transport associated AttributeBuilder, which will be used by Transport and its Connections to store custom Attributes.
 ExecutorService getInternalThreadPool()
          Get a thread pool, which will process transport internal tasks like NIO Selector polling etc.
 MemoryManager getMemoryManager()
          Get the Transport associated MemoryManager, which will be used by the Transport, its Connections and by during processing I/O events, occurred on Connections.
 String getName()
          Gets the Transport name.
 Processor getProcessor()
          Gets the default Processor, which will process Connection I/O events in case, if Connection doesn't have own Processor preferences.
 ProcessorSelector getProcessorSelector()
          Gets the default ProcessorSelector, which will be used to get Processor to process Connection I/O events, in case if this Transport's Processor is null and Connection doesn't have neither preferred Processor nor ProcessorSelector.
 int getReadBufferSize()
          Get the default size of Buffers, which will be allocated for reading data from Transport's Connections.
 StateHolder<Transport.State> getState()
          Return the Transport state controller.
 Strategy getStrategy()
          Get the Strategy implementation, which will be used by Transport to process IOEvent.
 ExecutorService getWorkerThreadPool()
          Get a worker thread pool, which could be chosen to process occurred I/O operations.
 int getWriteBufferSize()
          Get the default size of Buffers, which will be allocated for writing data to Transport's Connections.
 boolean isBlocking()
          Returns the Transport mode.
 boolean isStopped()
          Returns true, if this Transport is in stopped state, false otherwise.
 void notifyException(ExceptionHandler.Severity severity, Throwable throwable)
          Notify about error, occurred during Transport execution.
 void pause()
          Pauses the transport
 void removeExceptionHandler(ExceptionHandler handler)
          Remove ExceptionHandler from the list of Transport ExceptionHandlers.
 void resume()
          Resumes the transport after a pause
 void setAttributeBuilder(AttributeBuilder attributeBuilder)
          Set Transport associated AttributeBuilder, which will be used by Transport and its Connections to store custom Attributes.
 void setInternalThreadPool(ExecutorService internalThreadPool)
          Set a thread pool, which will process transport internal tasks like NIO Selector polling etc.
 void setMemoryManager(MemoryManager memoryManager)
          Set the Transport associated MemoryManager, which will be used by the Transport, its Connections and by during processing I/O events, occurred on Connections.
 void setName(String name)
          Sets the Transport name.
 void setProcessor(Processor processor)
          Sets the default Processor, which will process Connection I/O events in case, if Connection doesn't have own Processor preferences.
 void setProcessorSelector(ProcessorSelector selector)
          Sets the default ProcessorSelector, which will be used to get Processor to process Connection I/O events, in case if this Transport's Processor is null and Connection doesn't have neither preferred Processor nor ProcessorSelector.
 void setReadBufferSize(int readBufferSize)
          Set the default size of Buffers, which will be allocated for reading data from Transport's Connections.
 void setStrategy(Strategy strategy)
          Set the Strategy implementation, which will be used by Transport to process IOEvent.
 void setWorkerThreadPool(ExecutorService workerThreadPool)
          Set a worker thread pool, which could be chosen to process occurred I/O operations.
 void setWriteBufferSize(int writeBufferSize)
          Set the default size of Buffers, which will be allocated for writing data to Transport's Connections.
 void start()
          Starts the transport
 void stop()
          Stops the transport and closes all the connections
 

Method Detail

getName

String getName()
Gets the Transport name.

Returns:
the Transport name.

setName

void setName(String name)
Sets the Transport name.

Parameters:
name - the Transport name.

getState

StateHolder<Transport.State> getState()
Return the Transport state controller. Using the state controller, it is possible to get/set the Transport state in thread-safe manner.

Returns:
StateHolder state controller.

isBlocking

boolean isBlocking()
Returns the Transport mode. true, if Transport is operating in blocking mode, or false otherwise. Specific Transport Connections may override this setting by Connection.isBlocking().

Returns:
the Transport mode. true, if Transport is operating in blocking mode, or false otherwise.

configureBlocking

void configureBlocking(boolean isBlocking)
Sets the Transport mode. Specific Transport Connections may override this setting by Connection.configureBlocking(boolean).

Parameters:
isBlocking - the Transport mode. true, if Transport should operate in blocking mode, or false otherwise.

getProcessor

Processor getProcessor()
Gets the default Processor, which will process Connection I/O events in case, if Connection doesn't have own Processor preferences. If Transport associated Processor is null, and Connection doesn't have any preferred Processor - then Transport will try to get Processor using ProcessorSelector.select(IOEvent, Connection).

Returns:
the default Processor, which will process Connection I/O events, if one doesn't have own Processor preferences.

setProcessor

void setProcessor(Processor processor)
Sets the default Processor, which will process Connection I/O events in case, if Connection doesn't have own Processor preferences. If Transport associated Processor is null, and Connection doesn't have any preferred Processor - then Transport will try to get Processor using ProcessorSelector.select(IOEvent, Connection).

Parameters:
processor - the default Processor, which will process Connection I/O events, if one doesn't have own Processor preferences.

getProcessorSelector

ProcessorSelector getProcessorSelector()
Gets the default ProcessorSelector, which will be used to get Processor to process Connection I/O events, in case if this Transport's Processor is null and Connection doesn't have neither preferred Processor nor ProcessorSelector. Transport's ProcessorSelector is the last place, where Transport will try to get Processor to process Connection I/O event. If ProcessorSelector is not set - IllegalStateException will be thrown.

Returns:
the default ProcessorSelector, which will be used to get Processor to process Connection I/O events, in case if this Transport's Processor is null and Connection doesn't have neither preferred Processor nor ProcessorSelector.

setProcessorSelector

void setProcessorSelector(ProcessorSelector selector)
Sets the default ProcessorSelector, which will be used to get Processor to process Connection I/O events, in case if this Transport's Processor is null and Connection doesn't have neither preferred Processor nor ProcessorSelector. Transport's ProcessorSelector is the last place, where Transport will try to get Processor to process Connection I/O event. If ProcessorSelector is not set - IllegalStateException will be thrown.

Parameters:
the - default ProcessorSelector, which will be used to get Processor to process Connection I/O events, in case if this Transport's Processor is null and Connection doesn't have neither preferred Processor nor ProcessorSelector.

getMemoryManager

MemoryManager getMemoryManager()
Get the Transport associated MemoryManager, which will be used by the Transport, its Connections and by during processing I/O events, occurred on Connections.

Returns:
the Transport associated MemoryManager, which will be used by the Transport, its Connections and by during processing I/O events, occurred on Connections.

setMemoryManager

void setMemoryManager(MemoryManager memoryManager)
Set the Transport associated MemoryManager, which will be used by the Transport, its Connections and by during processing I/O events, occurred on Connections.

Parameters:
memoryManager - the Transport associated MemoryManager, which will be used by the Transport, its Connections and by during processing I/O events, occurred on Connections.

getStrategy

Strategy getStrategy()
Get the Strategy implementation, which will be used by Transport to process IOEvent. Strategy is responsible for choosing the way, how I/O event will be processed: using current Thread, worker Thread; or make any other decisions.

Returns:
the Strategy implementation, which will be used by Transport to process IOEvent.

setStrategy

void setStrategy(Strategy strategy)
Set the Strategy implementation, which will be used by Transport to process IOEvent. Strategy is responsible for choosing the way, how I/O event will be processed: using current Thread, worker Thread; or make any other decisions.

Parameters:
strategy - the Strategy implementation, which will be used by Transport to process IOEvent.

getReadBufferSize

int getReadBufferSize()
Get the default size of Buffers, which will be allocated for reading data from Transport's Connections. For particullar Connection, this setting could be overriden by Connection.getReadBufferSize().

Returns:
the default size of Buffers, which will be allocated for reading data from Transport's Connections.

setReadBufferSize

void setReadBufferSize(int readBufferSize)
Set the default size of Buffers, which will be allocated for reading data from Transport's Connections. For particullar Connection, this setting could be overriden by Connection.setReadBufferSize(int).

Parameters:
readBufferSize - the default size of Buffers, which will be allocated for reading data from Transport's Connections.

getWriteBufferSize

int getWriteBufferSize()
Get the default size of Buffers, which will be allocated for writing data to Transport's Connections. For particullar Connection, this setting could be overriden by Connection.getWriteBufferSize().

Returns:
the default size of Buffers, which will be allocated for writing data to Transport's Connections.

setWriteBufferSize

void setWriteBufferSize(int writeBufferSize)
Set the default size of Buffers, which will be allocated for writing data to Transport's Connections. For particullar Connection, this setting could be overriden by Connection.setWriteBufferSize(int).

Parameters:
writeBufferSize - the default size of Buffers, which will be allocated for writing data to Transport's Connections.

getWorkerThreadPool

ExecutorService getWorkerThreadPool()
Get a worker thread pool, which could be chosen to process occurred I/O operations. Custom Processors could be executed by this thread pool.

Returns:
ExecutorService worker thread pool.

setWorkerThreadPool

void setWorkerThreadPool(ExecutorService workerThreadPool)
Set a worker thread pool, which could be chosen to process occurred I/O operations. Custom Processor could be executed by this thread pool.

Parameters:
workerThreadPool - ExecutorService worker thread pool.

getInternalThreadPool

ExecutorService getInternalThreadPool()
Get a thread pool, which will process transport internal tasks like NIO Selector polling etc.

Returns:
ExecutorService internal thread pool.

setInternalThreadPool

void setInternalThreadPool(ExecutorService internalThreadPool)
Set a thread pool, which will process transport internal tasks like NIO Selector polling etc.

Parameters:
internalThreadPool - ExecutorService internal thread pool.

getAttributeBuilder

AttributeBuilder getAttributeBuilder()
Get Transport associated AttributeBuilder, which will be used by Transport and its Connections to store custom Attributes.

Returns:
Transport associated AttributeBuilder, which will be used by Transport and its Connections to store custom Attributes.

setAttributeBuilder

void setAttributeBuilder(AttributeBuilder attributeBuilder)
Set Transport associated AttributeBuilder, which will be used by Transport and its Connections to store custom Attributes.

Parameters:
attributeBuilder - Transport associated AttributeBuilder, which will be used by Transport and its Connections to store custom Attributes.

addExceptionHandler

void addExceptionHandler(ExceptionHandler handler)
Add ExceptionHandler to handle errors, occurred during the Transport execution.

Parameters:
handler - ExceptionHandler to be added.

removeExceptionHandler

void removeExceptionHandler(ExceptionHandler handler)
Remove ExceptionHandler from the list of Transport ExceptionHandlers.

Parameters:
handler - ExceptionHandler to be removed.

notifyException

void notifyException(ExceptionHandler.Severity severity,
                     Throwable throwable)
Notify about error, occurred during Transport execution.

Specified by:
notifyException in interface ExceptionHandler
Parameters:
severity - the error severity.
throwable - the error description.

start

void start()
           throws IOException
Starts the transport

Throws:
IOException

stop

void stop()
          throws IOException
Stops the transport and closes all the connections

Throws:
IOException

pause

void pause()
           throws IOException
Pauses the transport

Throws:
IOException

resume

void resume()
            throws IOException
Resumes the transport after a pause

Throws:
IOException

fireIOEvent

void fireIOEvent(IOEvent ioEvent,
                 Connection connection)
                 throws IOException
Fires specific IOEvent on the Connection

Parameters:
ioEvent - I/O event
connection - Connection, on which we fire the event.
Throws:
IOException

fireIOEvent

void fireIOEvent(IOEvent ioEvent,
                 Connection connection,
                 Object strategyContext)
                 throws IOException
Fires specific IOEvent on the Connection

Parameters:
ioEvent - I/O event
connection - Connection, on which we fire the event.
strategyContext - Strategy state
Throws:
IOException

isStopped

boolean isStopped()
Returns true, if this Transport is in stopped state, false otherwise.

Returns:
true, if this Transport is in stopped state, false otherwise.


Copyright © 2009 SUN Microsystems. All Rights Reserved.