org.glassfish.grizzly
Interface Transport

All Superinterfaces:
JmxMonitoringAware<TransportProbe>, MonitoringAware<TransportProbe>
All Known Implementing Classes:
AbstractTransport, NIOTransport, TCPNIOTransport, UDPNIOTransport

public interface Transport
extends JmxMonitoringAware<TransportProbe>

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
           
 
Field Summary
static int DEFAULT_READ_BUFFER_SIZE
          The default read buffer size.
 
Method Summary
 void configureBlocking(boolean isBlocking)
          Sets the Transport mode.
 void configureStandalone(boolean isStandalone)
           
 void fireIOEvent(IOEvent ioEvent, Connection connection, IOEventProcessingHandler processingHandler)
          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.
 MonitoringConfig<ConnectionProbe> getConnectionMonitoringConfig()
          Get the monitoring configuration for Transport Connections.
 IOStrategy getIOStrategy()
          Get the IOStrategy implementation, which will be used by Transport to process IOEvent.
 ExecutorService getKernelThreadPool()
           
 ThreadPoolConfig getKernelThreadPoolConfig()
           
 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.
 JmxMonitoringConfig<TransportProbe> getMonitoringConfig()
          Get the Transport monitoring configuration MonitoringConfig.
 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.
 Reader getReader(boolean isBlocking)
          Get the Reader implementation, depending on the requested mode.
 Reader getReader(Connection connection)
          Get the Reader to read data from the Connection.
 StateHolder<Transport.State> getState()
          Return the Transport state controller.
 MonitoringConfig<ThreadPoolProbe> getThreadPoolMonitoringConfig()
          Get the monitoring configuration for Transport thread pool.
 ExecutorService getWorkerThreadPool()
          Get a thread pool, which will run IOEvent processing (depending on Transport IOStrategy) to let kernel threads continue their job.
 ThreadPoolConfig getWorkerThreadPoolConfig()
           
 int getWriteBufferSize()
          Get the default size of Buffers, which will be allocated for writing data to Transport's Connections.
 Writer getWriter(boolean isBlocking)
          Get the Writer implementation, depending on the requested mode.
 Writer getWriter(Connection connection)
          Get the Writer to write data to the Connection.
 boolean isBlocking()
          Returns the Transport mode.
 boolean isPaused()
           
 boolean isStandalone()
           
 boolean isStopped()
          Returns true, if this Transport is in stopped state, false otherwise.
 void notifyTransportError(Throwable error)
          Method gets invoked, when error occur during the Transport lifecycle.
 Processor obtainProcessor(IOEvent ioEvent, Connection connection)
          Gets the default Processor, which will process Transport Connections I/O events in case, if Connection doesn't have own Processor preferences.
 void pause()
          Pauses the transport
 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 setIOStrategy(IOStrategy IOStrategy)
          Set the IOStrategy implementation, which will be used by Transport to process IOEvent.
 void setKernelThreadPool(ExecutorService threadPool)
          Set a thread pool which will run Transport internal tasks.
 void setKernelThreadPoolConfig(ThreadPoolConfig kernelConfig)
          Set the ThreadPoolConfig to be used by the Transport internal thread pool.
 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 setWorkerThreadPool(ExecutorService threadPool)
          Set a thread pool, which will run IOEvent processing (depending on Transport IOStrategy) to let kernel threads continue their job.
 void setWorkerThreadPoolConfig(ThreadPoolConfig workerConfig)
          Set the ThreadPoolConfig to be used by the worker thread pool.
 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
 

Field Detail

DEFAULT_READ_BUFFER_SIZE

static final int DEFAULT_READ_BUFFER_SIZE
The default read buffer size. This value is used to determine how large of a buffer to allocate when performing a read from a socket.

Since:
2.2.8
See Also:
Constant Field Values
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.

configureStandalone

void configureStandalone(boolean isStandalone)

isStandalone

boolean isStandalone()

obtainProcessor

Processor obtainProcessor(IOEvent ioEvent,
                          Connection connection)
Gets the default Processor, which will process Transport Connections 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.

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.

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:
selector - 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.

getIOStrategy

IOStrategy getIOStrategy()
Get the IOStrategy implementation, which will be used by Transport to process IOEvent. IOStrategy 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 IOStrategy implementation, which will be used by Transport to process IOEvent.

setIOStrategy

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

Parameters:
IOStrategy - the IOStrategy 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 particular Connection, this setting could be overridden 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 particular Connection, this setting could be overridden by Connection.setReadBufferSize(int). If not explicitly configured, this value will be set to DEFAULT_READ_BUFFER_SIZE.

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 particular Connection, this setting could be overridden 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 particular Connection, this setting could be overridden 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 thread pool, which will run IOEvent processing (depending on Transport IOStrategy) to let kernel threads continue their job.

Returns:
ExecutorService transport worker thread pool.

getKernelThreadPool

ExecutorService getKernelThreadPool()
Returns:
ExecutorService responsible for running Transport internal tasks. For example SelectorRunner threads for NIO.

setWorkerThreadPool

void setWorkerThreadPool(ExecutorService threadPool)
Set a thread pool, which will run IOEvent processing (depending on Transport IOStrategy) to let kernel threads continue their job.

Parameters:
threadPool - ExecutorService transport worker thread pool.

setKernelThreadPool

void setKernelThreadPool(ExecutorService threadPool)
Set a thread pool which will run Transport internal tasks. For example SelectorRunner threads for NIO.

Parameters:
threadPool - ExecutorService for SelectorRunners

setKernelThreadPoolConfig

void setKernelThreadPoolConfig(ThreadPoolConfig kernelConfig)
Set the ThreadPoolConfig to be used by the Transport internal thread pool.

Parameters:
kernelConfig - kernel thread pool configuration.

setWorkerThreadPoolConfig

void setWorkerThreadPoolConfig(ThreadPoolConfig workerConfig)
Set the ThreadPoolConfig to be used by the worker thread pool.

Parameters:
workerConfig - worker thread pool configuration.

getKernelThreadPoolConfig

ThreadPoolConfig getKernelThreadPoolConfig()
Returns:
the ThreadPoolConfig that will be used to construct the ExecutorService which will run the Transport's internal tasks. For example SelectorRunners for NIO.

getWorkerThreadPoolConfig

ThreadPoolConfig getWorkerThreadPoolConfig()
Returns:
the ThreadPoolConfig that will be used to construct the ExecutorService for IOStrategies that require worker threads. Depending on the IOStrategy being used, this may return null.

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.

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,
                 IOEventProcessingHandler processingHandler)
Fires specific IOEvent on the Connection

Parameters:
ioEvent - I/O event
connection - Connection, on which we fire the event.
processingHandler - I/O event processing handler.

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.

isPaused

boolean isPaused()

getReader

Reader getReader(Connection connection)
Get the Reader to read data from the Connection. The Transport may decide to return blocking or non-blocking Reader depending on the Connection settings.

Parameters:
connection - Connection.
Returns:
Reader.

getReader

Reader getReader(boolean isBlocking)
Get the Reader implementation, depending on the requested mode.

Parameters:
isBlocking - blocking mode.
Returns:
Reader.

getWriter

Writer getWriter(Connection connection)
Get the Writer to write data to the Connection. The Transport may decide to return blocking or non-blocking Writer depending on the Connection settings.

Parameters:
connection - Connection.
Returns:
Writer.

getWriter

Writer getWriter(boolean isBlocking)
Get the Writer implementation, depending on the requested mode.

Parameters:
isBlocking - blocking mode.
Returns:
Writer.

getConnectionMonitoringConfig

MonitoringConfig<ConnectionProbe> getConnectionMonitoringConfig()
Get the monitoring configuration for Transport Connections.


getThreadPoolMonitoringConfig

MonitoringConfig<ThreadPoolProbe> getThreadPoolMonitoringConfig()
Get the monitoring configuration for Transport thread pool.


getMonitoringConfig

JmxMonitoringConfig<TransportProbe> getMonitoringConfig()
Get the Transport monitoring configuration MonitoringConfig.

Specified by:
getMonitoringConfig in interface JmxMonitoringAware<TransportProbe>
Specified by:
getMonitoringConfig in interface MonitoringAware<TransportProbe>
Returns:
the object associated JmxMonitoringConfig.

notifyTransportError

void notifyTransportError(Throwable error)
Method gets invoked, when error occur during the Transport lifecycle.

Parameters:
error - Throwable.


Copyright © 2013 Oracle Corporation. All Rights Reserved.