org.glassfish.grizzly
Class AbstractTransport

java.lang.Object
  extended by org.glassfish.grizzly.AbstractTransport
All Implemented Interfaces:
Transport, ExceptionHandler
Direct Known Subclasses:
AbstractNIOTransport

public abstract class AbstractTransport
extends Object
implements Transport

Abstract Transport. Implements common transport functionality.

Author:
Alexey Stashok

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Transport
Transport.State
 
Nested classes/interfaces inherited from interface org.glassfish.grizzly.util.ExceptionHandler
ExceptionHandler.Severity
 
Field Summary
protected  AttributeBuilder attributeBuilder
          Transport AttributeBuilder, which will be used to create Attributes
protected  LinkedTransferQueue<ExceptionHandler> exceptionHandlers
          Transport ExceptionHandler list
protected  ExecutorService internalThreadPool
          Transport internal thread pool
protected  boolean isBlocking
          Transport mode
protected  MemoryManager memoryManager
          Transport MemoryManager
protected  String name
          Transport name
protected  Processor processor
          Transport default Processor
protected  ProcessorSelector processorSelector
          Transport default ProcessorSelector
protected  int readBufferSize
          Transport default buffer size for read operations
protected  StateHolder<Transport.State> state
          Transport state controller
protected  Strategy strategy
          Transport Strategy
protected  ExecutorService workerThreadPool
          Transport worker thread pool
protected  int writeBufferSize
          Transport default buffer size for write operations
 
Constructor Summary
AbstractTransport(String name)
           
 
Method Summary
 void addExceptionHandler(ExceptionHandler handler)
          Add ExceptionHandler to handle errors, occurred during the Transport execution.
protected abstract  void closeConnection(Connection connection)
          Close the connection, managed by Transport
 void configureBlocking(boolean isBlocking)
          Sets the Transport mode.
 void fireIOEvent(IOEvent ioEvent, Connection connection)
          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.
abstract  void pause()
          Pauses the transport
 void removeExceptionHandler(ExceptionHandler handler)
          Remove ExceptionHandler from the list of Transport ExceptionHandlers.
abstract  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.
abstract  void start()
          Starts the transport
abstract  void stop()
          Stops the transport and closes all the connections
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.glassfish.grizzly.Transport
fireIOEvent
 

Field Detail

name

protected String name
Transport name


isBlocking

protected boolean isBlocking
Transport mode


state

protected StateHolder<Transport.State> state
Transport state controller


processor

protected Processor processor
Transport default Processor


processorSelector

protected ProcessorSelector processorSelector
Transport default ProcessorSelector


strategy

protected Strategy strategy
Transport Strategy


memoryManager

protected MemoryManager memoryManager
Transport MemoryManager


workerThreadPool

protected ExecutorService workerThreadPool
Transport worker thread pool


internalThreadPool

protected ExecutorService internalThreadPool
Transport internal thread pool


attributeBuilder

protected AttributeBuilder attributeBuilder
Transport AttributeBuilder, which will be used to create Attributes


readBufferSize

protected int readBufferSize
Transport default buffer size for read operations


writeBufferSize

protected int writeBufferSize
Transport default buffer size for write operations


exceptionHandlers

protected LinkedTransferQueue<ExceptionHandler> exceptionHandlers
Transport ExceptionHandler list

Constructor Detail

AbstractTransport

public AbstractTransport(String name)
Method Detail

getName

public String getName()
Gets the Transport name.

Specified by:
getName in interface Transport
Returns:
the Transport name.

setName

public void setName(String name)
Sets the Transport name.

Specified by:
setName in interface Transport
Parameters:
name - the Transport name.

isBlocking

public 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().

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

configureBlocking

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

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

getState

public 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.

Specified by:
getState in interface Transport
Returns:
StateHolder state controller.

getReadBufferSize

public 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().

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

setReadBufferSize

public 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).

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

getWriteBufferSize

public 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().

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

setWriteBufferSize

public 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).

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

isStopped

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

Specified by:
isStopped in interface Transport
Returns:
true, if this Transport is in stopped state, false otherwise.

getProcessor

public 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).

Specified by:
getProcessor in interface Transport
Returns:
the default Processor, which will process Connection I/O events, if one doesn't have own Processor preferences.

setProcessor

public 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).

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

getProcessorSelector

public 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.

Specified by:
getProcessorSelector in interface Transport
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

public 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.

Specified by:
setProcessorSelector in interface Transport

getStrategy

public 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.

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

setStrategy

public 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.

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

getMemoryManager

public 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.

Specified by:
getMemoryManager in interface Transport
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

public 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.

Specified by:
setMemoryManager in interface Transport
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.

getWorkerThreadPool

public 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.

Specified by:
getWorkerThreadPool in interface Transport
Returns:
ExecutorService worker thread pool.

setWorkerThreadPool

public 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.

Specified by:
setWorkerThreadPool in interface Transport
Parameters:
workerThreadPool - ExecutorService worker thread pool.

getInternalThreadPool

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

Specified by:
getInternalThreadPool in interface Transport
Returns:
ExecutorService internal thread pool.

setInternalThreadPool

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

Specified by:
setInternalThreadPool in interface Transport
Parameters:
internalThreadPool - ExecutorService internal thread pool.

getAttributeBuilder

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

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

setAttributeBuilder

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

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

addExceptionHandler

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

Specified by:
addExceptionHandler in interface Transport
Parameters:
handler - ExceptionHandler to be added.

removeExceptionHandler

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

Specified by:
removeExceptionHandler in interface Transport
Parameters:
handler - ExceptionHandler to be removed.

notifyException

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

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

fireIOEvent

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

Specified by:
fireIOEvent in interface Transport
Parameters:
ioEvent - I/O event
connection - Connection, on which we fire the event.
Throws:
IOException

closeConnection

protected abstract void closeConnection(Connection connection)
                                 throws IOException
Close the connection, managed by Transport

Parameters:
connection -
Throws:
IOException

start

public abstract void start()
                    throws IOException
Starts the transport

Specified by:
start in interface Transport
Throws:
IOException

stop

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

Specified by:
stop in interface Transport
Throws:
IOException

pause

public abstract void pause()
                    throws IOException
Pauses the transport

Specified by:
pause in interface Transport
Throws:
IOException

resume

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

Specified by:
resume in interface Transport
Throws:
IOException


Copyright © 2009 SUN Microsystems. All Rights Reserved.