Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.nio

public abstract Class NIOConnection

extends Object
implements Connection<SocketAddress>
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.Connection, org.glassfish.grizzly.monitoring.MonitoringAware, org.glassfish.grizzly.attributes.AttributeStorage, org.glassfish.grizzly.Closeable, org.glassfish.grizzly.Writeable, org.glassfish.grizzly.OutputSink, org.glassfish.grizzly.Readable
Known Direct Subclasses
org.glassfish.grizzly.nio.transport.TCPNIOConnection, org.glassfish.grizzly.nio.transport.UDPNIOConnection
Imports
java.io.IOException, java.net.SocketAddress, java.nio.channels.SelectableChannel, .SelectionKey, java.util.ArrayList, .Collections, .LinkedList, .List, .Map, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, .ExecutionException, .Executor, .TimeUnit, .TimeoutException, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, .AtomicReferenceFieldUpdater, java.util.function.Supplier, java.util.logging.Level, .Logger, org.glassfish.grizzly.Buffer, .CloseReason, .Closeable, .CompletionHandler, .Connection, .ConnectionProbe, .EmptyCompletionHandler, .Grizzly, .GrizzlyFuture, .ICloseType, .IOEvent, .Processor, .ProcessorSelector, .ReadResult, .StandaloneProcessor, .StandaloneProcessorSelector, .Transport, .WriteResult, org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord, .AsyncWriteQueueRecord, .TaskQueue, org.glassfish.grizzly.attributes.AttributeHolder, org.glassfish.grizzly.impl.FutureImpl, org.glassfish.grizzly.memory.Buffers, .MemoryManager, org.glassfish.grizzly.monitoring.DefaultMonitoringConfig, .MonitoringConfig, org.glassfish.grizzly.utils.CompletionHandlerAdapter, .Futures

Common Connection implementation for Java NIO Connections.
Author
Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
NIOConnection.ProcessorStatesMap

Map, which contains Processors and their states related to this Connection.

Field Summary

Modifier and TypeField and Description
private volatile TaskQueue<AsyncReadQueueRecord>
private final TaskQueue<AsyncWriteQueueRecord>
protected final AttributeHolder
protected volatile SelectableChannel
private volatile GrizzlyFuture<CloseReason>
private final List<CloseListener<T extends Closeable, C extends ICloseType>>
private volatile CloseReason
private static final AtomicReferenceFieldUpdater<NIOConnection, CloseReason>
private volatile Object
protected static final AtomicReferenceFieldUpdater<NIOConnection, Object>
connectCloseSemaphoreUpdater

Semaphore responsible for connect/close notification

private static final AtomicLong
private final long
protected volatile boolean
private final AtomicBoolean
isCloseScheduled

closeTypeFlag, "null" value means the connection is open.

private boolean
isInitialReadRequired

Is initial OP_READ enabling required for the connection

protected volatile boolean
private static final Logger
private static final short
protected volatile int
protected final DefaultMonitoringConfig<ConnectionProbe>
monitoringConfig

Connection probes

protected static final Object
protected static final Object
protected volatile Processor<E extends Context>
protected volatile ProcessorSelector
private final NIOConnection.ProcessorStatesMap
processorStateStorage

Storage contains states of different Processors this Connection is associated with.

private final SelectorHandler.Task
protected volatile long
protected volatile SelectionKey
protected volatile SelectorRunner
protected final NIOTransport
private static final boolean
private final SelectorHandler.Task
protected volatile long
protected short

Constructor Summary

AccessConstructor and Description
public
NIOConnection(final NIOTransport transport)

Method Summary

Modifier and TypeMethod and Description
public void
addCloseListener(final CloseListener<T extends Closeable, C extends ICloseType> closeListener)

Implements org.glassfish.grizzly.Connection.addCloseListener.

Add the CloseListener, which will be notified once Connection will be closed.

public void
addCloseListener(Connection.CloseListener closeListener)

Implements org.glassfish.grizzly.Connection.addCloseListener.

References Deprecated Connection.CloseListener is deprecated or references (maybe indirectly) at least one deprecated element.

Add the CloseListener, which will be notified once Connection will be closed.

public void
assertOpen()

Implements org.glassfish.grizzly.Connection.assertOpen.

Checks if this Connection is open and ready to be used.

public void
attachToSelectorRunner(final SelectorRunner selectorRunner)

protected final void
checkEmptyRead(final int size)

public GrizzlyFuture<Closeable>
close()

Implements org.glassfish.grizzly.Connection.close.

Gracefully close the Connection

public void
close(final CompletionHandler<Closeable> completionHandler)

Implements org.glassfish.grizzly.Connection.close.

Gracefully close the Connection

public GrizzlyFuture<CloseReason>
protected void
closeGracefully0(final CompletionHandler<Closeable> completionHandler, CloseReason closeReason)

public final void
closeSilently()

Implements org.glassfish.grizzly.Connection.closeSilently.

Gracefully close the Connection silently, no notification required on completion or failure.

public void
closeWithReason(final IOException reason)

Implements org.glassfish.grizzly.Connection.closeWithReason.

Gracefully closes the Connection and provides the reason description.

public void
public synchronized void
public void
public final void
protected void
doClose()

Do the actual connection close.

protected void
enableInitialOpRead()

Enables OP_READ if it has never been enabled before.

public final void
public void
executeInEventThread(final IOEvent event, final Runnable runnable)

Implements org.glassfish.grizzly.Connection.executeInEventThread.

Executes the Runnable in the thread, responsible for running the given type of event on this Connection.

public TaskQueue<AsyncReadQueueRecord>
public TaskQueue<AsyncWriteQueueRecord>
public AttributeHolder
public SelectableChannel
public CloseReason
getCloseReason()

Implements org.glassfish.grizzly.Connection.getCloseReason.

Returns CloseReason if this Connection has been closed, or null otherwise.

public long
getId()

Implements org.glassfish.grizzly.Connection.getId.

Returns id of this instance, unique in the context of the JVM and the implementation class.

public int
getMaxAsyncWriteQueueSize()

Implements org.glassfish.grizzly.Connection.getMaxAsyncWriteQueueSize.

Get the max size (in bytes) of asynchronous write queue associated with connection.

public MemoryManager<?>
public final MonitoringConfig<ConnectionProbe>
public Processor<E extends Context>
getProcessor()

Implements org.glassfish.grizzly.Connection.getProcessor.

Gets the default Processor, which will process Connection I/O events.

public ProcessorSelector
getProcessorSelector()

Implements org.glassfish.grizzly.Connection.getProcessorSelector.

Gets the default ProcessorSelector, which will be used to get Processor to process Connection I/O events, in case if this Connection's Processor is null.

public long
getReadTimeout(TimeUnit timeUnit)

Implements org.glassfish.grizzly.Connection.getReadTimeout.

Returns the current value for the blocking read timeout converted to the provided TimeUnit specification.

public SelectionKey
public SelectorRunner
public Transport
getTransport()

Implements org.glassfish.grizzly.Connection.getTransport.

Get the Transport, to which this Connection belongs to.

public long
getWriteTimeout(TimeUnit timeUnit)

Implements org.glassfish.grizzly.Connection.getWriteTimeout.

Returns the current value for the blocking write timeout converted to the provided TimeUnit specification.

private void
invokeCloseListener(final CloseListener<T extends Closeable, C extends ICloseType> closeListener, final CloseType closeType)
References Deprecated CloseType is deprecated or references (maybe indirectly) at least one deprecated element.

public boolean
public boolean
public boolean
public boolean
private void
notifyCloseListeners(final CloseReason closeReason)

Notify all close listeners

public void
notifyConnectionError(Throwable error)

Implements org.glassfish.grizzly.Connection.notifyConnectionError.

Method gets invoked, when error occur during the Connection lifecycle.

protected static void
notifyIOEventDisabled(NIOConnection
the Connection event occurred on.
connection
,
IOEvent
the IOEvent.
ioEvent
)

Notify registered ConnectionProbes about the IO Event disabled event.

protected static void
notifyIOEventEnabled(NIOConnection
the Connection event occurred on.
connection
,
IOEvent
the IOEvent.
ioEvent
)

Notify registered ConnectionProbes about the IO Event enabled event.

protected static void
notifyIOEventReady(NIOConnection
the Connection event occurred on.
connection
,
IOEvent
the IOEvent.
ioEvent
)

Notify registered ConnectionProbes about the IO Event ready event.

protected static void
notifyProbesAccept(final NIOConnection
the server Connection, which accepted the client connection.
serverConnection
,
final NIOConnection
the client Connection.
clientConnection
)

Notify registered ConnectionProbes about the accept event.

protected static void
notifyProbesBind(NIOConnection
the Connection event occurred on.
connection
)

Notify registered ConnectionProbes about the bind event.

protected static void
notifyProbesClose(NIOConnection
the Connection event occurred on.
connection
)

Notify registered ConnectionProbes about the close event.

protected static void
notifyProbesConnect(NIOConnection
the Connection event occurred on.
connection
)

Notify registered ConnectionProbes about the connect event.

protected static void
notifyProbesError(NIOConnection
the Connection event occurred on.
connection
,
Throwable error)

Notify registered ConnectionProbes about the error.

protected static void
notifyProbesRead(NIOConnection connection, Buffer data, int size)

Notify registered ConnectionProbes about the read event.

protected static void
notifyProbesWrite(NIOConnection connection, Buffer data, long size)

Notify registered ConnectionProbes about the write event.

public Processor<E extends Context>
obtainProcessor(IOEvent ioEvent)

Implements org.glassfish.grizzly.Connection.obtainProcessor.

Gets the Processor, which will process Connection I/O event.

public <E> E
obtainProcessorState(final Processor<E extends Context> processor, final Supplier<E> factory)

Implements org.glassfish.grizzly.Connection.obtainProcessorState.

Returns the Processor state associated with this Connection.

pack-priv final void
onSelectionKeyUpdated(final SelectionKey newSelectionKey)

protected void
public <M> GrizzlyFuture<ReadResult<M, SocketAddress>>
read()

Implements org.glassfish.grizzly.Readable.read.

Method reads data.

public <M> void
public boolean
public boolean
removeCloseListener(Connection.CloseListener closeListener)

Implements org.glassfish.grizzly.Connection.removeCloseListener.

References Deprecated Connection.CloseListener is deprecated or references (maybe indirectly) at least one deprecated element.

Remove the CloseListener.

protected void
public void
setMaxAsyncWriteQueueSize(int maxAsyncWriteQueueSize)

Implements org.glassfish.grizzly.Connection.setMaxAsyncWriteQueueSize.

Set the max size (in bytes) of asynchronous write queue associated with connection.

pack-priv void
setMonitoringProbes(final ConnectionProbe[] monitoringProbes)

Set the monitoringProbes array directly.

public void
setProcessor(Processor<E extends Context> preferableProcessor)

Implements org.glassfish.grizzly.Connection.setProcessor.

Sets the default Processor, which will process Connection I/O events.

public void
setProcessorSelector(final ProcessorSelector preferableProcessorSelector)

Implements org.glassfish.grizzly.Connection.setProcessorSelector.

Sets the default ProcessorSelector, which will be used to get Processor to process Connection I/O events, in case if this Connection's Processor is null.

public void
setReadTimeout(long timeout, TimeUnit timeUnit)

Implements org.glassfish.grizzly.Connection.setReadTimeout.

Specifies the timeout for the blocking reads.

protected void
protected void
public void
setWriteTimeout(long timeout, TimeUnit timeUnit)

Implements org.glassfish.grizzly.Connection.setWriteTimeout.

Specifies the timeout for the blocking writes.

public void
public GrizzlyFuture<Closeable>
protected void
terminate0(final CompletionHandler<Closeable> completionHandler, final CloseReason reason)

public void
terminateSilently()

Implements org.glassfish.grizzly.Connection.terminateSilently.

Close the Connection silently, no notification required on completion or failure.

public void
terminateWithReason(final IOException reason)

Implements org.glassfish.grizzly.Connection.terminateWithReason.

Closes the Connection and provides the reason description.

public <M> GrizzlyFuture<WriteResult<M, SocketAddress>>
write(final M message)

Implements org.glassfish.grizzly.Writeable.write.

Method writes the buffer.

public <M> void
write(final M message, final CompletionHandler<WriteResult<M, SocketAddress>> completionHandler)

Implements org.glassfish.grizzly.Writeable.write.

Method writes the buffer.

public <M> void
write(final M message, CompletionHandler<WriteResult<M, SocketAddress>> completionHandler, PushBackHandler pushbackHandler)

Implements org.glassfish.grizzly.Writeable.write.

Deprecated

Method writes the buffer.

public <M> void
write(final SocketAddress dstAddress, final M message, final CompletionHandler<WriteResult<M, SocketAddress>> completionHandler)

Implements org.glassfish.grizzly.Writeable.write.

Method writes the buffer to the specific address.

public <M> void
write(final SocketAddress dstAddress, final M message, final CompletionHandler<WriteResult<M, SocketAddress>> completionHandler, final PushBackHandler pushbackHandler)

Implements org.glassfish.grizzly.Writeable.write.

Deprecated

Method writes the buffer to the specific address.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait