Top Description Inners Fields Constructors Methods
org.glassfish.tyrus.container.jdk.client

pack-priv Class TransportFilter

extends Filter
Class Inheritance
Imports
java.io.IOException, java.net.InetAddress, .InetSocketAddress, .SocketAddress, java.nio.Buffer, .ByteBuffer, java.nio.channels.AsynchronousChannelGroup, .AsynchronousCloseException, .AsynchronousSocketChannel, .CompletionHandler, .UnresolvedAddressException, .UnsupportedAddressTypeException, java.security.AccessController, .PrivilegedAction, java.util.Queue, java.util.concurrent.ExecutorService, .Executors, .LinkedBlockingDeque, .RejectedExecutionException, .ScheduledExecutorService, .ScheduledFuture, .SynchronousQueue, .ThreadFactory, .ThreadPoolExecutor, .TimeUnit, java.util.concurrent.atomic.AtomicInteger, java.util.logging.Level, .Logger, org.glassfish.tyrus.client.ThreadPoolConfig

Writes and reads data to and from a socket. Only one write(java.nio.ByteBuffer, org.glassfish.tyrus.spi.CompletionHandler) method call can be processed at a time. Only one _read(java.nio.ByteBuffer) operation is supported at a time, another one is started only after the previous one has completed. Blocking in onRead(java.nio.ByteBuffer) or onConnect() method will result in data not being read from a socket until these methods have completed.
Author
Petr Janouch

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
TransportFilter.QueuingExecutor

A thread pool executor that prefers creating new worker threads over queueing tasks until the maximum poll size has been reached, after which it will start queueing tasks.

private static class

Field Summary

Modifier and TypeField and Description
private final InetAddress
private static volatile AsynchronousChannelGroup
private static volatile ScheduledFuture<?>
private static final ScheduledExecutorService
private final Integer
private static volatile Integer
currentContainerIdleTimeout

Idle timeout that will be used when closing current channelGroup

private static volatile ThreadPoolConfig
private static final int
private final int
private static final Logger
private static final AtomicInteger
private volatile AsynchronousSocketChannel
private final ThreadPoolConfig
Inherited from org.glassfish.tyrus.container.jdk.client.Filter:
downstreamFilterupstreamFilter

Constructor Summary

AccessConstructor and Description
pack-priv
TransportFilter(int
size of buffer to be allocated for reading data from a socket.
inputBufferSize
,
ThreadPoolConfig
thread pool configuration used for creating thread pool.
threadPoolConfig
,
Integer
idle time after which the shared thread pool will be destroyed. If null default value will be used. The default value is 30 seconds.
containerIdleTimeout
,
InetAddress
local address to bind sockets (socketChannel) when they are created. Binding is done only if not null.
bindingAddress
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private void
_read(final ByteBuffer inputBuffer)

pack-priv synchronized void
close()

Overrides org.glassfish.tyrus.container.jdk.client.Filter.close.

Close the filter, invokes close operation on the next filter in the filter chain.

public void
handleConnect(SocketAddress
an address where to connect (server or proxy).
serverAddress
,
Filter
a filter positioned upstream.
upstreamFilter
)

Overrides org.glassfish.tyrus.container.jdk.client.Filter.handleConnect.

Handle connect(SocketAddress, Filter).

private void
private void
pack-priv void
startSsl()

Overrides org.glassfish.tyrus.container.jdk.client.Filter.startSsl.

Signal to turn on SSL, it is passed on in the filter chain until a filter responsible for SSL is reached.

private void
pack-priv void
write(ByteBuffer
on which write operation is performed.
data
,
final CompletionHandler<ByteBuffer>
will be invoked when the write operation is completed or has failed.
completionHandler
)

Overrides org.glassfish.tyrus.container.jdk.client.Filter.write.

Perform write operation for this filter and invokes write method on the next filter in the filter chain.

Inherited from org.glassfish.tyrus.container.jdk.client.Filter:
connectonConnectonConnectionClosedonErroronReadonSslHandshakeCompletedprocessConnectprocessConnectionClosedprocessErrorprocessReadprocessSslHandshakeCompleted

Field Detail

bindingAddressback to summary
private final InetAddress bindingAddress
channelGroupback to summary
private static volatile AsynchronousChannelGroup channelGroup
closeWaitTaskback to summary
private static volatile ScheduledFuture<?> closeWaitTask
connectionCloseSchedulerback to summary
private static final ScheduledExecutorService connectionCloseScheduler
containerIdleTimeoutback to summary
private final Integer containerIdleTimeout
currentContainerIdleTimeoutback to summary
private static volatile Integer currentContainerIdleTimeout

Idle timeout that will be used when closing current channelGroup

currentThreadPoolConfigback to summary
private static volatile ThreadPoolConfig currentThreadPoolConfig

org.glassfish.tyrus.client.ThreadPoolConfig current channelGroup has been created with.

DEFAULT_CONNECTION_CLOSE_WAITback to summary
private static final int DEFAULT_CONNECTION_CLOSE_WAIT
inputBufferSizeback to summary
private final int inputBufferSize
LOGGERback to summary
private static final Logger LOGGER
openedConnectionsback to summary
private static final AtomicInteger openedConnections
socketChannelback to summary
private volatile AsynchronousSocketChannel socketChannel
threadPoolConfigback to summary
private final ThreadPoolConfig threadPoolConfig

Constructor Detail

TransportFilterback to summary
pack-priv TransportFilter(int inputBufferSize, ThreadPoolConfig threadPoolConfig, Integer containerIdleTimeout, InetAddress bindingAddress)

Constructor.

If the channel group is not active (all connections have been closed and the shutdown timeout is running) and a new transport is created with tread pool configuration different from the one of the current thread pool, the current thread pool will be shut down and a new one created with the new configuration.

Parameters
inputBufferSize:int

size of buffer to be allocated for reading data from a socket.

threadPoolConfig:ThreadPoolConfig

thread pool configuration used for creating thread pool.

containerIdleTimeout:Integer

idle time after which the shared thread pool will be destroyed. If null default value will be used. The default value is 30 seconds.

bindingAddress:InetAddress

local address to bind sockets (socketChannel) when they are created. Binding is done only if not null.

Method Detail

_readback to summary
private void _read(final ByteBuffer inputBuffer)
closeback to summary
pack-priv synchronized void close()

Overrides org.glassfish.tyrus.container.jdk.client.Filter.close.

Doc from org.glassfish.tyrus.container.jdk.client.Filter.close.

Close the filter, invokes close operation on the next filter in the filter chain.

The filter is expected to clean up any allocated resources and pass the invocation to downstream filter.

Annotations
@Override
handleConnectback to summary
public void handleConnect(SocketAddress serverAddress, Filter upstreamFilter)

Overrides org.glassfish.tyrus.container.jdk.client.Filter.handleConnect.

Doc from org.glassfish.tyrus.container.jdk.client.Filter.handleConnect.

Handle connect(SocketAddress, Filter).

Parameters
serverAddress:SocketAddress

an address where to connect (server or proxy).

upstreamFilter:Filter

a filter positioned upstream.

Annotations
@Override
initializeChannelGroupback to summary
private void initializeChannelGroup() throws IOException
scheduleCloseback to summary
private void scheduleClose()
startSslback to summary
pack-priv void startSsl()

Overrides org.glassfish.tyrus.container.jdk.client.Filter.startSsl.

Doc from org.glassfish.tyrus.container.jdk.client.Filter.startSsl.

Signal to turn on SSL, it is passed on in the filter chain until a filter responsible for SSL is reached.

Annotations
@Override
updateThreadPoolConfigback to summary
private void updateThreadPoolConfig()
writeback to summary
pack-priv void write(ByteBuffer data, final CompletionHandler<ByteBuffer> completionHandler)

Overrides org.glassfish.tyrus.container.jdk.client.Filter.write.

Doc from org.glassfish.tyrus.container.jdk.client.Filter.write.

Perform write operation for this filter and invokes write method on the next filter in the filter chain.

Parameters
data:ByteBuffer

on which write operation is performed.

completionHandler:CompletionHandler<ByteBuffer>

will be invoked when the write operation is completed or has failed.

Annotations
@Override
org.glassfish.tyrus.container.jdk.client back to summary

private Class TransportFilter.QueuingExecutor

extends ThreadPoolExecutor
Class Inheritance

A thread pool executor that prefers creating new worker threads over queueing tasks until the maximum poll size has been reached, after which it will start queueing tasks.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
TransportFilter.QueuingExecutor.HandOffQueue

Synchronous queue that tries to empty taskQueue before it blocks waiting for new tasks to be submitted.

Field Summary

Modifier and TypeField and Description
private final Queue<Runnable>
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
QueuingExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, Queue<Runnable> taskQueue, boolean
indicates if taskQueue is thread safe or not.
threadSafeQueue
,
ThreadFactory threadFactory)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
execute(Runnable
to be executed.
task
)

Overrides java.util.concurrent.ThreadPoolExecutor.execute.

Implements java.util.concurrent.Executor.execute.

Submit a task for execution, if the maximum thread limit has been reached and all the threads are occupied, enqueue the task.

Inherited from java.util.concurrent.ThreadPoolExecutor:
afterExecuteallowCoreThreadTimeOutallowsCoreThreadTimeOutawaitTerminationbeforeExecutefinalizegetActiveCountgetCompletedTaskCountgetCorePoolSizegetKeepAliveTimegetLargestPoolSizegetMaximumPoolSizegetPoolSizegetQueuegetRejectedExecutionHandlergetTaskCountgetThreadFactoryisShutdownisTerminatedisTerminatingprestartAllCoreThreadsprestartCoreThreadpurgeremovesetCorePoolSizesetKeepAliveTimesetMaximumPoolSizesetRejectedExecutionHandlersetThreadFactoryshutdownshutdownNowterminatedtoString

Field Detail

taskQueueback to summary
private final Queue<Runnable> taskQueue
threadSafeQueueback to summary
private final boolean threadSafeQueue

Constructor Detail

QueuingExecutorback to summary
pack-priv QueuingExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, Queue<Runnable> taskQueue, boolean threadSafeQueue, ThreadFactory threadFactory)

Constructor.

Parameters
threadSafeQueue:boolean

indicates if taskQueue is thread safe or not.

Method Detail

executeback to summary
public void execute(Runnable task)

Overrides java.util.concurrent.ThreadPoolExecutor.execute.

Implements java.util.concurrent.Executor.execute.

Submit a task for execution, if the maximum thread limit has been reached and all the threads are occupied, enqueue the task. The task is not executed by the current thread, but by a thread from the thread pool.

Parameters
task:Runnable

to be executed.

Annotations
@Override
org.glassfish.tyrus.container.jdk.client back to summary

private Class TransportFilter.QueuingExecutor.HandOffQueue

extends SynchronousQueue<Runnable>
Class Inheritance

Synchronous queue that tries to empty taskQueue before it blocks waiting for new tasks to be submitted. It is passed to ThreadPoolExecutor, where it is used used to hand off tasks from task-submitting thread to worker threads.

Field Summary

Modifier and TypeField and Description
private static final long
private final Queue<Runnable>
private final boolean

Constructor Summary

AccessConstructor and Description
private
HandOffQueue(Queue<Runnable> taskQueue, boolean threadSafeQueue)

Method Summary

Modifier and TypeMethod and Description
public Runnable
poll(long
how long to wait before giving up, in units of unit
timeout
,
TimeUnit
a TimeUnit determining how to interpret the timeout parameter
unit
)

Overrides java.util.concurrent.SynchronousQueue.poll.

Implements java.util.concurrent.BlockingQueue.poll.

Retrieves and removes the head of this queue, waiting if necessary up to the specified wait time, for another thread to insert it.

public Runnable
take()

Overrides java.util.concurrent.SynchronousQueue.take.

Implements java.util.concurrent.BlockingQueue.take.

Retrieves and removes the head of this queue, waiting if necessary for another thread to insert it.

Inherited from java.util.concurrent.SynchronousQueue:
clearcontainscontainsAlldrainTodrainToisEmptyiteratorofferofferpeekpollputremainingCapacityremoveremoveAllretainAllsizespliteratortoArraytoArraytoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.SynchronousQueue.serialVersionUID.

taskQueueback to summary
private final Queue<Runnable> taskQueue
threadSafeQueueback to summary
private final boolean threadSafeQueue

Constructor Detail

HandOffQueueback to summary
private HandOffQueue(Queue<Runnable> taskQueue, boolean threadSafeQueue)

Method Detail

pollback to summary
public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException

Overrides java.util.concurrent.SynchronousQueue.poll.

Implements java.util.concurrent.BlockingQueue.poll.

Doc from java.util.concurrent.SynchronousQueue.poll.

Retrieves and removes the head of this queue, waiting if necessary up to the specified wait time, for another thread to insert it.

Parameters
timeout:long

Doc from java.util.concurrent.BlockingQueue.poll.

how long to wait before giving up, in units of unit

unit:TimeUnit

Doc from java.util.concurrent.BlockingQueue.poll.

a TimeUnit determining how to interpret the timeout parameter

Returns:Runnable

the head of this queue, or null if the specified waiting time elapses before an element is present

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
takeback to summary
public Runnable take() throws InterruptedException

Overrides java.util.concurrent.SynchronousQueue.take.

Implements java.util.concurrent.BlockingQueue.take.

Doc from java.util.concurrent.SynchronousQueue.take.

Retrieves and removes the head of this queue, waiting if necessary for another thread to insert it.

Returns:Runnable

the head of this queue

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
org.glassfish.tyrus.container.jdk.client back to summary

private Class TransportFilter.TransportThreadFactory

extends Object
implements ThreadFactory
Class Inheritance
  • java.lang.Object
  • org.glassfish.tyrus.container.jdk.client.TransportFilter.TransportThreadFactory
All Implemented Interfaces
java.util.concurrent.ThreadFactory

A default thread factory that gets used if org.glassfish.tyrus.client.ThreadPoolConfig#getThreadFactory() is not specified.

Field Summary

Modifier and TypeField and Description
private static final String
private static final AtomicInteger
private final ThreadPoolConfig

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Thread
newThread(Runnable
a runnable to be executed by new thread instance
r
)

Implements java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

THREAD_NAME_BASEback to summary
private static final String THREAD_NAME_BASE
threadCounterback to summary
private static final AtomicInteger threadCounter
threadPoolConfigback to summary
private final ThreadPoolConfig threadPoolConfig

Constructor Detail

TransportThreadFactoryback to summary
pack-priv TransportThreadFactory(ThreadPoolConfig threadPoolConfig)

Method Detail

newThreadback to summary
public Thread newThread(Runnable r)

Implements java.util.concurrent.ThreadFactory.newThread.

Doc from java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Parameters
r:Runnable

a runnable to be executed by new thread instance

Returns:Thread

constructed thread, or null if the request to create a thread is rejected

Annotations
@Override