public abstract class AbstractTransport extends Object implements Transport
Transport
.
Implements common transport functionality.Transport.State
Modifier and Type | Field and Description |
---|---|
protected AttributeBuilder |
attributeBuilder
Transport AttributeBuilder, which will be used to create Attributes
|
protected DefaultMonitoringConfig<ConnectionProbe> |
connectionMonitoringConfig
Connection probes
|
protected boolean |
isBlocking
Transport mode
|
protected boolean |
isStandalone |
protected ExecutorService |
kernelPool
Kernel thread pool.
|
protected ThreadPoolConfig |
kernelPoolConfig |
protected boolean |
managedWorkerPool |
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 long |
readTimeout |
protected StateHolder<Transport.State> |
state
Transport state controller
|
protected IOStrategy |
strategy
Transport strategy
|
protected DefaultMonitoringConfig<ThreadPoolProbe> |
threadPoolMonitoringConfig
Thread pool probes
|
protected DefaultMonitoringConfig<TransportProbe> |
transportMonitoringConfig
Transport probes
|
protected ThreadPoolConfig |
workerPoolConfig |
protected ExecutorService |
workerThreadPool
Worker thread pool
|
protected int |
writeBufferSize
Transport default buffer size for write operations
|
protected long |
writeTimeout |
DEFAULT_READ_BUFFER_SIZE, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, DEFAULT_WRITE_TIMEOUT
Constructor and Description |
---|
AbstractTransport(String name) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
closeConnection(Connection connection)
Close the connection, managed by Transport
|
void |
configureBlocking(boolean isBlocking)
Sets the
Transport mode. |
protected abstract Object |
createJmxManagementObject()
Create the Transport JMX management object.
|
AttributeBuilder |
getAttributeBuilder()
Get
Transport associated AttributeBuilder , which will
be used by Transport and its Connection s to store custom
Attribute s. |
MonitoringConfig<ConnectionProbe> |
getConnectionMonitoringConfig()
Get the monitoring configuration for Transport
Connection s. |
IOStrategy |
getIOStrategy()
|
ExecutorService |
getKernelThreadPool() |
ThreadPoolConfig |
getKernelThreadPoolConfig() |
MemoryManager |
getMemoryManager()
Get the
Transport associated MemoryManager , which will
be used by the Transport , its Connection s and by during
processing I/O events, occurred on Connection s. |
MonitoringConfig<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
Buffer s, which will be allocated for
reading data from Transport 's Connection s. |
long |
getReadTimeout(TimeUnit timeUnit)
Returns the current value for the blocking read timeout converted to the
provided
TimeUnit specification. |
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
Buffer s, which will be allocated for
writing data to Transport 's Connection s. |
long |
getWriteTimeout(TimeUnit timeUnit)
Returns the current value for the blocking write timeout converted to the
provided
TimeUnit specification. |
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 |
notifyProbesBeforePause(AbstractTransport transport)
Notify registered
TransportProbe s about the before-pause event. |
protected static void |
notifyProbesBeforeResume(AbstractTransport transport)
Notify registered
TransportProbe s about the before-resume event. |
protected static void |
notifyProbesBeforeStart(AbstractTransport transport)
Notify registered
TransportProbe s about the before-start event. |
protected static void |
notifyProbesBeforeStop(AbstractTransport transport)
Notify registered
TransportProbe s about the before-stop event. |
protected static void |
notifyProbesConfigChanged(AbstractTransport transport)
Notify registered
TransportProbe s about the config changed event. |
protected static void |
notifyProbesPause(AbstractTransport transport)
Notify registered
TransportProbe s about the pause event. |
protected static void |
notifyProbesStop(AbstractTransport transport)
Notify registered
TransportProbe s about the stop event. |
Processor |
obtainProcessor(IOEvent ioEvent,
Connection connection)
Gets the default
Processor , which will process Transport
Connection s I/O events in case, if Connection
doesn't have own Processor preferences. |
void |
setAttributeBuilder(AttributeBuilder attributeBuilder)
Set
Transport associated AttributeBuilder , which will
be used by Transport and its Connection s to store custom
Attribute s. |
void |
setIOStrategy(IOStrategy IOStrategy)
|
protected void |
setKernelPool0(ExecutorService kernelPool) |
void |
setKernelThreadPool(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 Connection s and by during
processing I/O events, occurred on Connection s. |
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
Buffer s, which will be allocated for
reading data from Transport 's Connection s. |
void |
setReadTimeout(long timeout,
TimeUnit timeUnit)
Specifies the timeout for the blocking reads.
|
void |
setWorkerThreadPool(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(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
Buffer s, which will be allocated for
writing data to Transport 's Connection s. |
void |
setWriteTimeout(long timeout,
TimeUnit timeUnit)
Specifies the timeout for the blocking writes.
|
void |
stop()
Deprecated.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addShutdownListener, configureStandalone, fireIOEvent, getReader, getReader, getWriter, getWriter, notifyTransportError, pause, resume, shutdown, shutdown, shutdownNow, start
protected String name
protected volatile boolean isBlocking
protected volatile boolean isStandalone
protected final StateHolder<Transport.State> state
protected Processor processor
protected ProcessorSelector processorSelector
protected IOStrategy strategy
protected MemoryManager memoryManager
protected ExecutorService workerThreadPool
protected ExecutorService kernelPool
protected AttributeBuilder attributeBuilder
protected int readBufferSize
protected int writeBufferSize
protected ThreadPoolConfig workerPoolConfig
protected ThreadPoolConfig kernelPoolConfig
protected boolean managedWorkerPool
protected long writeTimeout
protected long readTimeout
protected final DefaultMonitoringConfig<TransportProbe> transportMonitoringConfig
protected final DefaultMonitoringConfig<ConnectionProbe> connectionMonitoringConfig
protected final DefaultMonitoringConfig<ThreadPoolProbe> threadPoolMonitoringConfig
public AbstractTransport(String name)
public boolean isBlocking()
Transport
mode.
true, if Transport
is operating in blocking mode, or
false otherwise.
Specific Transport
Connection
s may override this setting
by Connection.isBlocking()
.isBlocking
in interface Transport
Transport
mode.
true, if Transport
is operating in blocking mode, or
false otherwise.public void configureBlocking(boolean isBlocking)
Transport
mode.
Specific Transport
Connection
s may override this setting
by Connection.configureBlocking(boolean)
.configureBlocking
in interface Transport
isBlocking
- the Transport
mode. true,
if Transport
should operate in blocking mode, or
false otherwise.public boolean isStandalone()
isStandalone
in interface Transport
public StateHolder<Transport.State> getState()
Transport
state controller. Using the state controller,
it is possible to get/set the Transport
state in thread-safe manner.getState
in interface Transport
StateHolder
state controller.public int getReadBufferSize()
Buffer
s, which will be allocated for
reading data from Transport
's Connection
s.
For particular Connection
, this setting could be overridden by
Connection.getReadBufferSize()
.getReadBufferSize
in interface Transport
Buffer
s, which will be allocated for
reading data from Transport
's Connection
s.public void setReadBufferSize(int readBufferSize)
Buffer
s, which will be allocated for
reading data from Transport
's Connection
s.
For particular Connection
, this setting could be overridden by
Connection.setReadBufferSize(int)
.
If not explicitly configured, this value will be set to
Transport.DEFAULT_READ_BUFFER_SIZE
.setReadBufferSize
in interface Transport
readBufferSize
- the default size of Buffer
s, which will
be allocated for reading data from Transport
's
Connection
s.public int getWriteBufferSize()
Buffer
s, which will be allocated for
writing data to Transport
's Connection
s.
For particular Connection
, this setting could be overridden by
Connection.getWriteBufferSize()
.getWriteBufferSize
in interface Transport
Buffer
s, which will be allocated for
writing data to Transport
's Connection
s.public void setWriteBufferSize(int writeBufferSize)
Buffer
s, which will be allocated for
writing data to Transport
's Connection
s.
For particular Connection
, this setting could be overridden by
Connection.setWriteBufferSize(int)
.setWriteBufferSize
in interface Transport
writeBufferSize
- the default size of Buffer
s, which will
be allocated for writing data to Transport
's
Connection
s.public boolean isStopped()
public Processor obtainProcessor(IOEvent ioEvent, Connection connection)
Processor
, which will process Transport
Connection
s 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)
.obtainProcessor
in interface Transport
Processor
, which will process
Connection
I/O events, if one doesn't have
own Processor
preferences.public Processor getProcessor()
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)
.getProcessor
in interface Transport
Processor
, which will process
Connection
I/O events, if one doesn't have
own Processor
preferences.public void setProcessor(Processor processor)
Processor
, which will process Connection
I/O events in case, if Connection
doesn't have own
Processor
preferences.setProcessor
in interface Transport
processor
- the default Processor
, which will process
Connection
I/O events, if one doesn't have own
Processor
preferences.public ProcessorSelector getProcessorSelector()
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.getProcessorSelector
in interface Transport
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
.public void setProcessorSelector(ProcessorSelector selector)
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.setProcessorSelector
in interface Transport
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
.public IOStrategy getIOStrategy()
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.getIOStrategy
in interface Transport
IOStrategy
implementation, which will be used by
Transport
to process IOEvent
.public void setIOStrategy(IOStrategy IOStrategy)
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.setIOStrategy
in interface Transport
IOStrategy
- the IOStrategy
implementation, which will be used
by Transport
to process IOEvent
.public MemoryManager getMemoryManager()
Transport
associated MemoryManager
, which will
be used by the Transport
, its Connection
s and by during
processing I/O events, occurred on Connection
s.getMemoryManager
in interface Transport
Transport
associated MemoryManager
,
which will be used by the Transport
, its Connection
s
and by during processing I/O events, occurred on Connection
s.public void setMemoryManager(MemoryManager memoryManager)
Transport
associated MemoryManager
, which will
be used by the Transport
, its Connection
s and by during
processing I/O events, occurred on Connection
s.setMemoryManager
in interface Transport
memoryManager
- the Transport
associated
MemoryManager
, which will be used by the Transport
,
its Connection
s and by during processing I/O events, occurred
on Connection
s.public ExecutorService getWorkerThreadPool()
IOStrategy
) to let kernel threads continue
their job.getWorkerThreadPool
in interface Transport
ExecutorService
transport worker thread pool.public ExecutorService getKernelThreadPool()
getKernelThreadPool
in interface Transport
ExecutorService
responsible for running Transport internal
tasks. For example SelectorRunner
threads for NIO.public void setKernelThreadPool(ExecutorService kernelPool)
SelectorRunner
threads for NIO.setKernelThreadPool
in interface Transport
kernelPool
- ExecutorService
for SelectorRunner
spublic void setKernelThreadPoolConfig(ThreadPoolConfig kernelPoolConfig)
ThreadPoolConfig
to be used by the Transport internal
thread pool.setKernelThreadPoolConfig
in interface Transport
kernelPoolConfig
- kernel thread
pool configuration.public void setWorkerThreadPoolConfig(ThreadPoolConfig workerPoolConfig)
ThreadPoolConfig
to be used by the worker thread pool.setWorkerThreadPoolConfig
in interface Transport
workerPoolConfig
- worker thread pool configuration.public ThreadPoolConfig getKernelThreadPoolConfig()
getKernelThreadPoolConfig
in interface Transport
ThreadPoolConfig
that will be used to construct the
ExecutorService
which will run the
Transport
's internal tasks.
For example
SelectorRunner
s for NIO.public ThreadPoolConfig getWorkerThreadPoolConfig()
getWorkerThreadPoolConfig
in interface Transport
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
.public void setWorkerThreadPool(ExecutorService threadPool)
IOStrategy
) to let kernel threads continue
their job.setWorkerThreadPool
in interface Transport
threadPool
- ExecutorService
transport worker thread pool.protected void setWorkerThreadPool0(ExecutorService threadPool)
protected void setKernelPool0(ExecutorService kernelPool)
public AttributeBuilder getAttributeBuilder()
Transport
associated AttributeBuilder
, which will
be used by Transport
and its Connection
s to store custom
Attribute
s.getAttributeBuilder
in interface Transport
Transport
associated AttributeBuilder
, which will
be used by Transport
and its Connection
s to store custom
Attribute
s.public void setAttributeBuilder(AttributeBuilder attributeBuilder)
Transport
associated AttributeBuilder
, which will
be used by Transport
and its Connection
s to store custom
Attribute
s.setAttributeBuilder
in interface Transport
attributeBuilder
- Transport
associated
AttributeBuilder
, which will be used by Transport
and
its Connection
s to store custom Attribute
s.protected abstract void closeConnection(Connection connection) throws IOException
connection
- IOException
public MonitoringConfig<ConnectionProbe> getConnectionMonitoringConfig()
Connection
s.getConnectionMonitoringConfig
in interface Transport
public MonitoringConfig<TransportProbe> getMonitoringConfig()
MonitoringConfig
.getMonitoringConfig
in interface MonitoringAware<TransportProbe>
getMonitoringConfig
in interface Transport
MonitoringConfig
.public MonitoringConfig<ThreadPoolProbe> getThreadPoolMonitoringConfig()
getThreadPoolMonitoringConfig
in interface Transport
public long getReadTimeout(TimeUnit timeUnit)
TimeUnit
specification. If this value hasn't been
explicitly set, it will default to 30 seconds.getReadTimeout
in interface Transport
timeUnit
- the TimeUnit
to convert the returned result to.public void setReadTimeout(long timeout, TimeUnit timeUnit)
setReadTimeout
in interface Transport
timeout
- the new timeout valuetimeUnit
- the specification of the provided value.Connection.setReadTimeout(long, java.util.concurrent.TimeUnit)
public long getWriteTimeout(TimeUnit timeUnit)
TimeUnit
specification. If this value hasn't been
explicitly set, it will default to 30 seconds.getWriteTimeout
in interface Transport
timeUnit
- the TimeUnit
to convert the returned result to.public void setWriteTimeout(long timeout, TimeUnit timeUnit)
setWriteTimeout
in interface Transport
timeout
- the new timeout valuetimeUnit
- the specification of the provided value.Connection.setWriteTimeout(long, java.util.concurrent.TimeUnit)
protected static void notifyProbesBeforeStart(AbstractTransport transport)
TransportProbe
s about the before-start event.transport
- the Transport event occurred on.protected static void notifyProbesBeforeStop(AbstractTransport transport)
TransportProbe
s about the before-stop event.transport
- the Transport event occurred on.protected static void notifyProbesStop(AbstractTransport transport)
TransportProbe
s about the stop event.transport
- the Transport event occurred on.protected static void notifyProbesBeforePause(AbstractTransport transport)
TransportProbe
s about the before-pause event.transport
- the Transport event occurred on.protected static void notifyProbesPause(AbstractTransport transport)
TransportProbe
s about the pause event.transport
- the Transport event occurred on.protected static void notifyProbesBeforeResume(AbstractTransport transport)
TransportProbe
s about the before-resume event.transport
- the Transport event occurred on.protected static void notifyProbesConfigChanged(AbstractTransport transport)
TransportProbe
s about the config changed event.transport
- the Transport event occurred on.@Deprecated public void stop() throws IOException
stop
in interface Transport
IOException
protected abstract Object createJmxManagementObject()
Copyright © 2015 Oracle Corporation. All rights reserved.