Top Description Inners Fields Constructors Methods
sun.nio.ch

pack-priv abstract Class AsynchronousSocketChannelImpl

extends AsynchronousSocketChannel
implements Cancellable, Groupable
Class Inheritance
All Implemented Interfaces
sun.nio.ch.Groupable, sun.nio.ch.Cancellable
Known Direct Subclasses
sun.nio.ch.UnixAsynchronousSocketChannelImpl
Imports
java.nio.ByteBuffer, java.nio.channels.*, java.net.SocketOption, .StandardSocketOptions, .SocketAddress, .InetSocketAddress, java.io.IOException, .FileDescriptor, java.util.Set, .HashSet, .Objects, .Collections, java.util.concurrent.*, java.util.concurrent.locks.*, sun.net.NetHooks, sun.net.ext.ExtendedSocketOptions

Base implementation of AsynchronousSocketChannel

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private volatile boolean
private final ReadWriteLock
protected final FileDescriptor
private boolean
protected volatile InetSocketAddress
private boolean
private boolean
private final Object
private boolean
protected volatile InetSocketAddress
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
protected volatile int
protected final Object
private boolean
private final Object
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv final void
begin()

Marks beginning of access to file descriptor/handle

public final AsynchronousSocketChannel
bind(SocketAddress
The address to bind the socket, or null to bind the socket to an automatically assigned socket address
local
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.bind.

Implements java.nio.channels.NetworkChannel.bind.

Binds the channel's socket to a local address.

public final void
public final Future<Void>
connect(SocketAddress
The remote address to which this channel is to be connected
remote
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.connect.

Connects this channel.

public final <A> void
connect(SocketAddress
The remote address to which this channel is to be connected
remote
,
A
The object to attach to the I/O operation; can be null
attachment
,
CompletionHandler<Void, ? super A>
The handler for consuming the result
handler
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.connect.

Connects this channel.

pack-priv final void
enableReading(boolean killed)

pack-priv final void
pack-priv final void
enableWriting(boolean killed)

pack-priv final void
pack-priv final void
end()

Marks end of access to file descriptor/handle

public final SocketAddress
getLocalAddress()

Implements abstract java.nio.channels.AsynchronousSocketChannel.getLocalAddress.

Implements java.nio.channels.NetworkChannel.getLocalAddress.

Returns the socket address that this channel's socket is bound to.

public final <T> T
getOption(SocketOption<T>
The socket option
name
)

Implements java.nio.channels.NetworkChannel.getOption.

Returns the value of a socket option.

public final SocketAddress
getRemoteAddress()

Implements abstract java.nio.channels.AsynchronousSocketChannel.getRemoteAddress.

Returns the remote address to which this channel's socket is connected.

pack-priv abstract void
implClose()

Invoked to close socket and release other resources.

pack-priv abstract <A> Future<Void>
implConnect(SocketAddress remote, A attachment, CompletionHandler<Void, ? super A> handler)

Invoked by connect to initiate the connect operation.

pack-priv abstract <V extends Number, A> Future<V>
implRead(boolean isScatteringRead, ByteBuffer dst, ByteBuffer[] dsts, long timeout, TimeUnit unit, A attachment, CompletionHandler<V, ? super A> handler)

Invoked by read to initiate the I/O operation.

pack-priv abstract <V extends Number, A> Future<V>
implWrite(boolean isGatheringWrite, ByteBuffer src, ByteBuffer[] srcs, long timeout, TimeUnit unit, A attachment, CompletionHandler<V, ? super A> handler)

Invoked by write to initiate the I/O operation.

public final boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

pack-priv final void
pack-priv final void
pack-priv final void
private <V extends Number, A> Future<V>
read(boolean isScatteringRead, ByteBuffer dst, ByteBuffer[] dsts, long timeout, TimeUnit unit, A att, CompletionHandler<V, ? super A> handler)

public final Future<Integer>
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.read.

Implements java.nio.channels.AsynchronousByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

public final <A> void
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
,
long
The maximum time for the I/O operation to complete
timeout
,
TimeUnit
The time unit of the timeout argument
unit
,
A
The object to attach to the I/O operation; can be null
attachment
,
CompletionHandler<Integer, ? super A>
The handler for consuming the result
handler
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

public final <A> void
read(ByteBuffer[]
The buffers into which bytes are to be transferred
dsts
,
int
The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than dsts.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.length - offset
length
,
long
The maximum time for the I/O operation to complete
timeout
,
TimeUnit
The time unit of the timeout argument
unit
,
A
The object to attach to the I/O operation; can be null
attachment
,
CompletionHandler<Long, ? super A>
The handler for consuming the result
handler
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.read.

Reads a sequence of bytes from this channel into a subsequence of the given buffers.

public final <T> AsynchronousSocketChannel
setOption(SocketOption<T>
The socket option
name
,
T
The value of the socket option. A value of null may be a valid value for some socket options.
value
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.setOption.

Implements java.nio.channels.NetworkChannel.setOption.

Sets the value of a socket option.

public final AsynchronousSocketChannel
shutdownInput()

Implements abstract java.nio.channels.AsynchronousSocketChannel.shutdownInput.

Shutdown the connection for reading without closing the channel.

public final AsynchronousSocketChannel
shutdownOutput()

Implements abstract java.nio.channels.AsynchronousSocketChannel.shutdownOutput.

Shutdown the connection for writing without closing the channel.

public final Set<SocketOption<?>>
supportedOptions()

Implements java.nio.channels.NetworkChannel.supportedOptions.

Returns a set of the socket options supported by this channel.

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private <V extends Number, A> Future<V>
write(boolean isGatheringWrite, ByteBuffer src, ByteBuffer[] srcs, long timeout, TimeUnit unit, A att, CompletionHandler<V, ? super A> handler)

public final Future<Integer>
write(ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.write.

Implements java.nio.channels.AsynchronousByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

public final <A> void
write(ByteBuffer
The buffer from which bytes are to be retrieved
src
,
long
The maximum time for the I/O operation to complete
timeout
,
TimeUnit
The time unit of the timeout argument
unit
,
A
The object to attach to the I/O operation; can be null
attachment
,
CompletionHandler<Integer, ? super A>
The handler for consuming the result
handler
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

public final <A> void
write(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
int
The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
,
long
The maximum time for the I/O operation to complete
timeout
,
TimeUnit
The time unit of the timeout argument
unit
,
A
The object to attach to the I/O operation; can be null
attachment
,
CompletionHandler<Long, ? super A>
The handler for consuming the result
handler
)

Implements abstract java.nio.channels.AsynchronousSocketChannel.write.

Writes a sequence of bytes to this channel from a subsequence of the given buffers.

Inherited from java.nio.channels.AsynchronousSocketChannel:
openopenproviderreadwrite

Field Detail

closedback to summary
private volatile boolean closed
closeLockback to summary
private final ReadWriteLock closeLock
fdback to summary
protected final FileDescriptor fd
isReuseAddressback to summary
private boolean isReuseAddress
localAddressback to summary
protected volatile InetSocketAddress localAddress
readingback to summary
private boolean reading
readKilledback to summary
private boolean readKilled
readLockback to summary
private final Object readLock
readShutdownback to summary
private boolean readShutdown
remoteAddressback to summary
protected volatile InetSocketAddress remoteAddress
ST_CONNECTEDback to summary
pack-priv static final int ST_CONNECTED
ST_PENDINGback to summary
pack-priv static final int ST_PENDING
ST_UNCONNECTEDback to summary
pack-priv static final int ST_UNCONNECTED
ST_UNINITIALIZEDback to summary
pack-priv static final int ST_UNINITIALIZED
stateback to summary
protected volatile int state
stateLockback to summary
protected final Object stateLock
writeKilledback to summary
private boolean writeKilled
writeLockback to summary
private final Object writeLock
writeShutdownback to summary
private boolean writeShutdown
writingback to summary
private boolean writing

Constructor Detail

AsynchronousSocketChannelImplback to summary
pack-priv AsynchronousSocketChannelImpl(AsynchronousChannelGroupImpl group) throws IOException
AsynchronousSocketChannelImplback to summary
pack-priv AsynchronousSocketChannelImpl(AsynchronousChannelGroupImpl group, FileDescriptor fd, InetSocketAddress remote) throws IOException

Method Detail

beginback to summary
pack-priv final void begin() throws IOException

Marks beginning of access to file descriptor/handle

bindback to summary
public final AsynchronousSocketChannel bind(SocketAddress local) throws IOException

Implements abstract java.nio.channels.AsynchronousSocketChannel.bind.

Implements java.nio.channels.NetworkChannel.bind.

Doc from java.nio.channels.NetworkChannel.bind.

Binds the channel's socket to a local address.

This method is used to establish an association between the socket and a local address. Once an association is established then the socket remains bound until the channel is closed. If the local parameter has the value null then the socket will be bound to an address that is assigned automatically.

Parameters
local:SocketAddress

The address to bind the socket, or null to bind the socket to an automatically assigned socket address

Returns:AsynchronousSocketChannel

This channel

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.channels.AsynchronousSocketChannel.bind.

If some other I/O error occurs

closeback to summary
public final void close() throws IOException

Implements java.nio.channels.AsynchronousChannel.close, java.nio.channels.Channel.close.

Doc from java.nio.channels.AsynchronousChannel.close.

Closes this channel.

Any outstanding asynchronous operations upon this channel will complete with the exception AsynchronousCloseException. After a channel is closed, further attempts to initiate asynchronous I/O operations complete immediately with cause ClosedChannelException.

This method otherwise behaves exactly as specified by the Channel interface.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
connectback to summary
public final Future<Void> connect(SocketAddress remote)

Implements abstract java.nio.channels.AsynchronousSocketChannel.connect.

Doc from java.nio.channels.AsynchronousSocketChannel.connect.

Connects this channel.

This method initiates an operation to connect this channel. This method behaves in exactly the same manner as the connect(SocketAddress, Object, CompletionHandler) method except that instead of specifying a completion handler, this method returns a Future representing the pending result. The Future's get method returns null on successful completion.

Parameters
remote:SocketAddress

The remote address to which this channel is to be connected

Returns:Future<Void>

A Future object representing the pending result

Annotations
@Override
connectback to summary
public final <A> void connect(SocketAddress remote, A attachment, CompletionHandler<Void, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousSocketChannel.connect.

Doc from java.nio.channels.AsynchronousSocketChannel.connect.

Connects this channel.

This method initiates an operation to connect this channel. The handler parameter is a completion handler that is invoked when the connection is successfully established or connection cannot be established. If the connection cannot be established then the channel is closed.

This method performs exactly the same security checks as the java.net.Socket class. That is, if a security manager has been installed then this method verifies that its checkConnect method permits connecting to the address and port number of the given remote endpoint.

Parameters
<A>
The type of the attachment
remote:SocketAddress

The remote address to which this channel is to be connected

attachment:A

The object to attach to the I/O operation; can be null

handler:CompletionHandler<Void, ? super A>

The handler for consuming the result

Annotations
@Override
enableReadingback to summary
pack-priv final void enableReading(boolean killed)
enableReadingback to summary
pack-priv final void enableReading()
enableWritingback to summary
pack-priv final void enableWriting(boolean killed)
enableWritingback to summary
pack-priv final void enableWriting()
endback to summary
pack-priv final void end()

Marks end of access to file descriptor/handle

getLocalAddressback to summary
public final SocketAddress getLocalAddress() throws IOException

Implements abstract java.nio.channels.AsynchronousSocketChannel.getLocalAddress.

Implements java.nio.channels.NetworkChannel.getLocalAddress.

Doc from java.nio.channels.AsynchronousSocketChannel.getLocalAddress.

Returns the socket address that this channel's socket is bound to.

Where the channel is bound to an Internet Protocol socket address then the return value from this method is of type java.net.InetSocketAddress.

If there is a security manager set, its checkConnect method is called with the local address and -1 as its arguments to see if the operation is allowed. If the operation is not allowed, a SocketAddress representing the loopback address and the local port of the channel's socket is returned.

Returns:SocketAddress

The SocketAddress that the socket is bound to, or the SocketAddress representing the loopback address if denied by the security manager, or null if the channel's socket is not bound

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
getOptionback to summary
public final <T> T getOption(SocketOption<T> name) throws IOException

Implements java.nio.channels.NetworkChannel.getOption.

Doc from java.nio.channels.NetworkChannel.getOption.

Returns the value of a socket option.

Parameters
<T>
The type of the socket option value
name:SocketOption<T>

The socket option

Returns:T

The value of the socket option. A value of null may be a valid value for some socket options.

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
IOException:
If an I/O error occurs
getRemoteAddressback to summary
public final SocketAddress getRemoteAddress() throws IOException

Implements abstract java.nio.channels.AsynchronousSocketChannel.getRemoteAddress.

Doc from java.nio.channels.AsynchronousSocketChannel.getRemoteAddress.

Returns the remote address to which this channel's socket is connected.

Where the channel is bound and connected to an Internet Protocol socket address then the return value from this method is of type java.net.InetSocketAddress.

Returns:SocketAddress

The remote address; null if the channel's socket is not connected

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
implCloseback to summary
pack-priv abstract void implClose() throws IOException

Invoked to close socket and release other resources.

implConnectback to summary
pack-priv abstract <A> Future<Void> implConnect(SocketAddress remote, A attachment, CompletionHandler<Void, ? super A> handler)

Invoked by connect to initiate the connect operation.

implReadback to summary
pack-priv abstract <V extends Number, A> Future<V> implRead(boolean isScatteringRead, ByteBuffer dst, ByteBuffer[] dsts, long timeout, TimeUnit unit, A attachment, CompletionHandler<V, ? super A> handler)

Invoked by read to initiate the I/O operation.

implWriteback to summary
pack-priv abstract <V extends Number, A> Future<V> implWrite(boolean isGatheringWrite, ByteBuffer src, ByteBuffer[] srcs, long timeout, TimeUnit unit, A attachment, CompletionHandler<V, ? super A> handler)

Invoked by write to initiate the I/O operation.

isOpenback to summary
public final boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

Annotations
@Override
killConnectback to summary
pack-priv final void killConnect()
killReadingback to summary
pack-priv final void killReading()
killWritingback to summary
pack-priv final void killWriting()
readback to summary
private <V extends Number, A> Future<V> read(boolean isScatteringRead, ByteBuffer dst, ByteBuffer[] dsts, long timeout, TimeUnit unit, A att, CompletionHandler<V, ? super A> handler)
Annotations
@SuppressWarnings:unchecked
readback to summary
public final Future<Integer> read(ByteBuffer dst)

Implements abstract java.nio.channels.AsynchronousSocketChannel.read.

Implements java.nio.channels.AsynchronousByteChannel.read.

Doc from java.nio.channels.AsynchronousByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

This method initiates an asynchronous read operation to read a sequence of bytes from this channel into the given buffer. The method behaves in exactly the same manner as the read(ByteBuffer,Object,CompletionHandler) method except that instead of specifying a completion handler, this method returns a Future representing the pending result. The Future's get method returns the number of bytes read or -1 if no bytes could be read because the channel has reached end-of-stream.

Parameters
dst:ByteBuffer

The buffer into which bytes are to be transferred

Returns:Future<Integer>

A Future representing the result of the operation

Annotations
@Override
readback to summary
public final <A> void read(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousSocketChannel.read.

Doc from java.nio.channels.AsynchronousSocketChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

This method initiates an asynchronous read operation to read a sequence of bytes from this channel into the given buffer. The handler parameter is a completion handler that is invoked when the read operation completes (or fails). The result passed to the completion handler is the number of bytes read or -1 if no bytes could be read because the channel has reached end-of-stream.

If a timeout is specified and the timeout elapses before the operation completes then the operation completes with the exception InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been read, or will not be read from the channel into the given buffer, then further attempts to read from the channel will cause an unspecific runtime exception to be thrown.

Otherwise this method works in the same manner as the AsynchronousByteChannel#read(ByteBuffer, Object, CompletionHandler) method.

Parameters
<A>
The type of the attachment
dst:ByteBuffer

The buffer into which bytes are to be transferred

timeout:long

The maximum time for the I/O operation to complete

unit:TimeUnit

The time unit of the timeout argument

attachment:A

The object to attach to the I/O operation; can be null

handler:CompletionHandler<Integer, ? super A>

The handler for consuming the result

Annotations
@Override
readback to summary
public final <A> void read(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousSocketChannel.read.

Doc from java.nio.channels.AsynchronousSocketChannel.read.

Reads a sequence of bytes from this channel into a subsequence of the given buffers. This operation, sometimes called a scattering read, is often useful when implementing network protocols that group data into segments consisting of one or more fixed-length headers followed by a variable-length body. The handler parameter is a completion handler that is invoked when the read operation completes (or fails). The result passed to the completion handler is the number of bytes read or -1 if no bytes could be read because the channel has reached end-of-stream.

This method initiates a read of up to r bytes from this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,

dsts[offset].remaining() + dsts[offset+1].remaining() + ... + dsts[offset+length-1].remaining()
dsts[offset].remaining()
    + dsts[offset+1].remaining()
    + ... + dsts[offset+length-1].remaining()
at the moment that the read is attempted.

Suppose that a byte sequence of length n is read, where 0 < n <= r. Up to the first dsts[offset].remaining() bytes of this sequence are transferred into buffer dsts[offset], up to the next dsts[offset+1].remaining() bytes are transferred into buffer dsts[offset+1], and so forth, until the entire byte sequence is transferred into the given buffers. As many bytes as possible are transferred into each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit. The underlying operating system may impose a limit on the number of buffers that may be used in an I/O operation. Where the number of buffers (with bytes remaining), exceeds this limit, then the I/O operation is performed with the maximum number of buffers allowed by the operating system.

If a timeout is specified and the timeout elapses before the operation completes then it completes with the exception InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been read, or will not be read from the channel into the given buffers, then further attempts to read from the channel will cause an unspecific runtime exception to be thrown.

Parameters
<A>
The type of the attachment
dsts:ByteBuffer[]

The buffers into which bytes are to be transferred

offset:int

The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than dsts.length

length:int

The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.length - offset

timeout:long

The maximum time for the I/O operation to complete

unit:TimeUnit

The time unit of the timeout argument

attachment:A

The object to attach to the I/O operation; can be null

handler:CompletionHandler<Long, ? super A>

The handler for consuming the result

Annotations
@Override
setOptionback to summary
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value) throws IOException

Implements abstract java.nio.channels.AsynchronousSocketChannel.setOption.

Implements java.nio.channels.NetworkChannel.setOption.

Doc from java.nio.channels.NetworkChannel.setOption.

Sets the value of a socket option.

Parameters
<T>
The type of the socket option value
name:SocketOption<T>

The socket option

value:T

The value of the socket option. A value of null may be a valid value for some socket options.

Returns:AsynchronousSocketChannel

This channel

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.channels.AsynchronousSocketChannel.setOption.

If an I/O error occurs

shutdownInputback to summary
public final AsynchronousSocketChannel shutdownInput() throws IOException

Implements abstract java.nio.channels.AsynchronousSocketChannel.shutdownInput.

Doc from java.nio.channels.AsynchronousSocketChannel.shutdownInput.

Shutdown the connection for reading without closing the channel.

Once shutdown for reading then further reads on the channel will return -1, the end-of-stream indication. If the input side of the connection is already shutdown then invoking this method has no effect. The effect on an outstanding read operation is system dependent and therefore not specified. The effect, if any, when there is data in the socket receive buffer that has not been read, or data arrives subsequently, is also system dependent.

Returns:AsynchronousSocketChannel

The channel

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
shutdownOutputback to summary
public final AsynchronousSocketChannel shutdownOutput() throws IOException

Implements abstract java.nio.channels.AsynchronousSocketChannel.shutdownOutput.

Doc from java.nio.channels.AsynchronousSocketChannel.shutdownOutput.

Shutdown the connection for writing without closing the channel.

Once shutdown for writing then further attempts to write to the channel will throw ClosedChannelException. If the output side of the connection is already shutdown then invoking this method has no effect. The effect on an outstanding write operation is system dependent and therefore not specified.

Returns:AsynchronousSocketChannel

The channel

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
supportedOptionsback to summary
public final Set<SocketOption<?>> supportedOptions()

Implements java.nio.channels.NetworkChannel.supportedOptions.

Doc from java.nio.channels.NetworkChannel.supportedOptions.

Returns a set of the socket options supported by this channel.

This method will continue to return the set of options even after the channel has been closed.

Returns:Set<SocketOption<?>>

A set of the socket options supported by this channel

Annotations
@Override
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
writeback to summary
private <V extends Number, A> Future<V> write(boolean isGatheringWrite, ByteBuffer src, ByteBuffer[] srcs, long timeout, TimeUnit unit, A att, CompletionHandler<V, ? super A> handler)
Annotations
@SuppressWarnings:unchecked
writeback to summary
public final Future<Integer> write(ByteBuffer src)

Implements abstract java.nio.channels.AsynchronousSocketChannel.write.

Implements java.nio.channels.AsynchronousByteChannel.write.

Doc from java.nio.channels.AsynchronousByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

This method initiates an asynchronous write operation to write a sequence of bytes to this channel from the given buffer. The method behaves in exactly the same manner as the write(ByteBuffer,Object,CompletionHandler) method except that instead of specifying a completion handler, this method returns a Future representing the pending result. The Future's get method returns the number of bytes written.

Parameters
src:ByteBuffer

The buffer from which bytes are to be retrieved

Returns:Future<Integer>

A Future representing the result of the operation

Annotations
@Override
writeback to summary
public final <A> void write(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousSocketChannel.write.

Doc from java.nio.channels.AsynchronousSocketChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

This method initiates an asynchronous write operation to write a sequence of bytes to this channel from the given buffer. The handler parameter is a completion handler that is invoked when the write operation completes (or fails). The result passed to the completion handler is the number of bytes written.

If a timeout is specified and the timeout elapses before the operation completes then it completes with the exception InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been written, or will not be written to the channel from the given buffer, then further attempts to write to the channel will cause an unspecific runtime exception to be thrown.

Otherwise this method works in the same manner as the AsynchronousByteChannel#write(ByteBuffer, Object, CompletionHandler) method.

Parameters
<A>
The type of the attachment
src:ByteBuffer

The buffer from which bytes are to be retrieved

timeout:long

The maximum time for the I/O operation to complete

unit:TimeUnit

The time unit of the timeout argument

attachment:A

The object to attach to the I/O operation; can be null

handler:CompletionHandler<Integer, ? super A>

The handler for consuming the result

Annotations
@Override
writeback to summary
public final <A> void write(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousSocketChannel.write.

Doc from java.nio.channels.AsynchronousSocketChannel.write.

Writes a sequence of bytes to this channel from a subsequence of the given buffers. This operation, sometimes called a gathering write, is often useful when implementing network protocols that group data into segments consisting of one or more fixed-length headers followed by a variable-length body. The handler parameter is a completion handler that is invoked when the write operation completes (or fails). The result passed to the completion handler is the number of bytes written.

This method initiates a write of up to r bytes to this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,

srcs[offset].remaining() + srcs[offset+1].remaining() + ... + srcs[offset+length-1].remaining()
srcs[offset].remaining()
    + srcs[offset+1].remaining()
    + ... + srcs[offset+length-1].remaining()
at the moment that the write is attempted.

Suppose that a byte sequence of length n is written, where 0 < n <= r. Up to the first srcs[offset].remaining() bytes of this sequence are written from buffer srcs[offset], up to the next srcs[offset+1].remaining() bytes are written from buffer srcs[offset+1], and so forth, until the entire byte sequence is written. As many bytes as possible are written from each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit. The underlying operating system may impose a limit on the number of buffers that may be used in an I/O operation. Where the number of buffers (with bytes remaining), exceeds this limit, then the I/O operation is performed with the maximum number of buffers allowed by the operating system.

If a timeout is specified and the timeout elapses before the operation completes then it completes with the exception InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been written, or will not be written to the channel from the given buffers, then further attempts to write to the channel will cause an unspecific runtime exception to be thrown.

Parameters
<A>
The type of the attachment
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

offset:int

The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length

length:int

The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset

timeout:long

The maximum time for the I/O operation to complete

unit:TimeUnit

The time unit of the timeout argument

attachment:A

The object to attach to the I/O operation; can be null

handler:CompletionHandler<Long, ? super A>

The handler for consuming the result

Annotations
@Override
sun.nio.ch back to summary

private Class AsynchronousSocketChannelImpl.DefaultOptionsHolder

extends Object
Class Inheritance
  • java.lang.Object
  • sun.nio.ch.AsynchronousSocketChannelImpl.DefaultOptionsHolder

Field Summary

Modifier and TypeField and Description
pack-priv static final Set<SocketOption<?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static Set<SocketOption<?>>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultOptionsback to summary
pack-priv static final Set<SocketOption<?>> defaultOptions

Constructor Detail

DefaultOptionsHolderback to summary
private DefaultOptionsHolder()

Method Detail

defaultOptionsback to summary
private static Set<SocketOption<?>> defaultOptions()