org.glassfish.grizzly
Class AbstractTransport

java.lang.Object
  extended by org.glassfish.grizzly.AbstractTransport
All Implemented Interfaces:
JmxMonitoringAware<TransportProbe>, MonitoringAware<TransportProbe>, Transport
Direct Known Subclasses:
NIOTransport

public abstract class AbstractTransport
extends java.lang.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.IOEventReg, Transport.State
 
Field Summary
protected  AttributeBuilder attributeBuilder
          Transport AttributeBuilder, which will be used to create Attributes
protected  MonitoringConfigImpl<ConnectionProbe> connectionMonitoringConfig
          Connection probes
protected  boolean isBlocking
          Transport mode
protected  boolean isStandalone
           
protected  java.util.concurrent.ExecutorService kernelPool
          Kernel thread pool.
protected  ThreadPoolConfig kernelPoolConfig
           
protected  boolean managedWorkerPool
           
protected  MemoryManager memoryManager
          Transport MemoryManager
protected  java.lang.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  IOStrategy strategy
          Transport strategy
protected  MonitoringConfigImpl<ThreadPoolProbe> threadPoolMonitoringConfig
          Thread pool probes
protected  AbstractJmxMonitoringConfig<TransportProbe> transportMonitoringConfig
          Transport probes
protected  ThreadPoolConfig workerPoolConfig
           
protected  java.util.concurrent.ExecutorService workerThreadPool
          Worker thread pool
protected  int writeBufferSize
          Transport default buffer size for write operations
 
Constructor Summary
AbstractTransport(java.lang.String name)
           
 
Method Summary
protected abstract  void closeConnection(Connection connection)
          Close the connection, managed by Transport
 void configureBlocking(boolean isBlocking)
          Sets the Transport mode.
protected abstract  JmxObject createJmxManagementObject()
          Create the Transport JMX managment object.
 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.
 java.util.concurrent.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.
 java.lang.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.
 MonitoringConfig<ThreadPoolProbe> getThreadPoolMonitoringConfig()
          Get the monitoring configuration for Transport thread pool.
 java.util.concurrent.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.
 boolean isBlocking()
          Returns the Transport mode.
 boolean isPaused()
          
 boolean isStandalone()
           
 boolean isStopped()
          Returns true, if this Transport is in stopped state, false otherwise.
protected static void notifyProbesConfigChanged(AbstractTransport transport)
          Notify registered TransportProbes about the config changed event.
 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.
abstract  void pause()
          Pauses the transport
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 setIOStrategy(IOStrategy IOStrategy)
          Set the IOStrategy implementation, which will be used by Transport to process IOEvent.
protected  void setKernelPool0(java.util.concurrent.ExecutorService kernelPool)
           
 void setKernelThreadPool(java.util.concurrent.ExecutorService kernelPool)
          Set a thread pool which will run Transport internal tasks.
 void setKernelThreadPoolConfig(ThreadPoolConfig kernelPoolConfig)
          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(java.lang.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(java.util.concurrent.ExecutorService threadPool)
          Set a thread pool, which will run IOEvent processing (depending on Transport IOStrategy) to let kernel threads continue their job.
protected  void setWorkerThreadPool0(java.util.concurrent.ExecutorService threadPool)
           
 void setWorkerThreadPoolConfig(ThreadPoolConfig workerPoolConfig)
          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.
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
configureStandalone, fireIOEvent, getReader, getReader, getWriter, getWriter, notifyTransportError
 

Field Detail

name

protected java.lang.String name
Transport name


isBlocking

protected volatile boolean isBlocking
Transport mode


isStandalone

protected volatile boolean isStandalone

state

protected final StateHolder<Transport.State> state
Transport state controller


processor

protected Processor processor
Transport default Processor


processorSelector

protected ProcessorSelector processorSelector
Transport default ProcessorSelector


strategy

protected IOStrategy strategy
Transport strategy


memoryManager

protected MemoryManager memoryManager
Transport MemoryManager


workerThreadPool

protected java.util.concurrent.ExecutorService workerThreadPool
Worker thread pool


kernelPool

protected java.util.concurrent.ExecutorService kernelPool
Kernel 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


workerPoolConfig

protected ThreadPoolConfig workerPoolConfig

kernelPoolConfig

protected ThreadPoolConfig kernelPoolConfig

managedWorkerPool

protected boolean managedWorkerPool

transportMonitoringConfig

protected final AbstractJmxMonitoringConfig<TransportProbe> transportMonitoringConfig
Transport probes


connectionMonitoringConfig

protected final MonitoringConfigImpl<ConnectionProbe> connectionMonitoringConfig
Connection probes


threadPoolMonitoringConfig

protected final MonitoringConfigImpl<ThreadPoolProbe> threadPoolMonitoringConfig
Thread pool probes

Constructor Detail

AbstractTransport

public AbstractTransport(java.lang.String name)
Method Detail

getName

public java.lang.String getName()
Gets the Transport name.

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

setName

public void setName(java.lang.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.

isStandalone

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

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 particular Connection, this setting could be overridden 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 particular Connection, this setting could be overridden 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 particular Connection, this setting could be overridden 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 particular Connection, this setting could be overridden 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.

isPaused

public boolean isPaused()

Specified by:
isPaused in interface Transport

obtainProcessor

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

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

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.

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

getIOStrategy

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

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

setIOStrategy

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

Specified by:
setIOStrategy in interface Transport
Parameters:
IOStrategy - the IOStrategy 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 java.util.concurrent.ExecutorService getWorkerThreadPool()
Get a thread pool, which will run IOEvent processing (depending on Transport IOStrategy) to let kernel threads continue their job.

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

getKernelThreadPool

public java.util.concurrent.ExecutorService getKernelThreadPool()

Specified by:
getKernelThreadPool in interface Transport
Returns:
ExecutorService responsible for running Transport internal tasks. For example SelectorRunner threads for NIO.

setKernelThreadPool

public void setKernelThreadPool(java.util.concurrent.ExecutorService kernelPool)
Set a thread pool which will run Transport internal tasks. For example SelectorRunner threads for NIO.

Specified by:
setKernelThreadPool in interface Transport
Parameters:
kernelPool - ExecutorService for SelectorRunners

setKernelThreadPoolConfig

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

Specified by:
setKernelThreadPoolConfig in interface Transport
Parameters:
kernelPoolConfig - kernel thread pool configuration.

setWorkerThreadPoolConfig

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

Specified by:
setWorkerThreadPoolConfig in interface Transport
Parameters:
workerPoolConfig - worker thread pool configuration.

getKernelThreadPoolConfig

public ThreadPoolConfig getKernelThreadPoolConfig()

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

public ThreadPoolConfig getWorkerThreadPoolConfig()

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

setWorkerThreadPool

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

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

setWorkerThreadPool0

protected void setWorkerThreadPool0(java.util.concurrent.ExecutorService threadPool)

setKernelPool0

protected void setKernelPool0(java.util.concurrent.ExecutorService kernelPool)

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.

closeConnection

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

Parameters:
connection -
Throws:
java.io.IOException

getConnectionMonitoringConfig

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

Specified by:
getConnectionMonitoringConfig in interface Transport

getMonitoringConfig

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

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

getThreadPoolMonitoringConfig

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

Specified by:
getThreadPoolMonitoringConfig in interface Transport

notifyProbesConfigChanged

protected static void notifyProbesConfigChanged(AbstractTransport transport)
Notify registered TransportProbes about the config changed event.

Parameters:
transport - the Transport event occurred on.

start

public abstract void start()
                    throws java.io.IOException
Starts the transport

Specified by:
start in interface Transport
Throws:
java.io.IOException

stop

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

Specified by:
stop in interface Transport
Throws:
java.io.IOException

pause

public abstract void pause()
                    throws java.io.IOException
Pauses the transport

Specified by:
pause in interface Transport
Throws:
java.io.IOException

resume

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

Specified by:
resume in interface Transport
Throws:
java.io.IOException

createJmxManagementObject

protected abstract JmxObject createJmxManagementObject()
Create the Transport JMX managment object.

Returns:
the Transport JMX managment object.


Copyright © 2011 Oracle Corpration. All Rights Reserved.