|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.sgs.nio.channels.AsynchronousChannel
com.sun.sgs.nio.channels.AsynchronousSocketChannel
com.sun.sgs.impl.nio.AsyncSocketChannelImpl
class AsyncSocketChannelImpl
An implementation of AsynchronousSocketChannel.
Most interesting methods are delegated to the AsyncKey
returned by this channel's channel group.
| Field Summary | |
|---|---|
(package private) SocketChannel |
channel
The underlying SocketChannel. |
(package private) AsyncKey |
key
The AsyncKey for the underlying channel. |
| Constructor Summary | |
|---|---|
AsyncSocketChannelImpl(AsyncGroupImpl group)
Creates a new instance registered with the given channel group. |
|
AsyncSocketChannelImpl(AsyncGroupImpl group,
SocketChannel channel)
Creates a new instance registered with the given channel group, with the given underlying SocketChannel. |
|
| Method Summary | ||
|---|---|---|
AsyncSocketChannelImpl |
bind(SocketAddress local)
Binds the channel's socket to a local address. |
|
void |
close()
Closes this channel. |
|
|
connect(SocketAddress remote,
A attachment,
CompletionHandler<Void,? super A> handler)
Connects this channel. |
|
SocketAddress |
getConnectedAddress()
Returns the remote address to which this channel's socket is connected, or null if the channel's socket is not connected. |
|
SocketAddress |
getLocalAddress()
Returns the socket address that this channel's socket is bound to, or null if the socket is not bound. |
|
Object |
getOption(SocketOption name)
Returns the value of a socket option. |
|
boolean |
isConnectionPending()
Tells whether or not a connect is pending for this channel. |
|
boolean |
isOpen()
|
|
boolean |
isReadPending()
Tells whether or not a read is pending for this channel. |
|
boolean |
isWritePending()
Tells whether or not a write is pending for this channel. |
|
Set<SocketOption> |
options()
Returns a set of the socket options supported by this channel. |
|
|
read(ByteBuffer[] dsts,
int offset,
int length,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Long,? super A> handler)
Reads a sequence of bytes from this channel into a subsequence of the given buffers. |
|
|
read(ByteBuffer dst,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
Reads a sequence of bytes from this channel into the given buffer. |
|
AsyncSocketChannelImpl |
setOption(SocketOption name,
Object value)
Sets the value of a socket option. |
|
AsyncSocketChannelImpl |
shutdown(ShutdownType how)
Shutdown a connection for reading and/or writing without closing the channel. |
|
String |
toString()
|
|
|
write(ByteBuffer[] srcs,
int offset,
int length,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Long,? super A> handler)
Writes a sequence of bytes to this channel from a subsequence of the given buffers. |
|
|
write(ByteBuffer src,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
Writes a sequence of bytes to this channel from the given buffer. |
|
| Methods inherited from class com.sun.sgs.nio.channels.AsynchronousSocketChannel |
|---|
connect, open, open, read, read, write, write |
| Methods inherited from class com.sun.sgs.nio.channels.AsynchronousChannel |
|---|
provider |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
final SocketChannel channel
SocketChannel.
final AsyncKey key
AsyncKey for the underlying channel.
| Constructor Detail |
|---|
AsyncSocketChannelImpl(AsyncGroupImpl group)
throws IOException
group - the channel group
IOException - if an I/O error occurs
AsyncSocketChannelImpl(AsyncGroupImpl group,
SocketChannel channel)
throws IOException
SocketChannel. Used by an
AsyncServerSocketChannelImpl when a new connection is
accepted.
group - the channel groupchannel - the SocketChannel for this async channel
IOException - if an I/O error occurs| Method Detail |
|---|
public String toString()
toString in class Objectpublic boolean isOpen()
public void close()
throws IOException
Any outstanding asynchronous operations upon this channel will
complete by throwing ExecutionException with cause
AsynchronousCloseException.
This method otherwise behaves exactly as specified by the
Channel interface.
close in interface Closeableclose in interface Channelclose in class AsynchronousChannelIOException - if an I/O error occurs
public AsyncSocketChannelImpl bind(SocketAddress local)
throws IOException
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. An attempt to bind
a socket that is already bound throws AlreadyBoundException.
If the local parameter has the value null then the
socket will be bound to an address that is assigned automatically.
An implementation of this interface should specify if a permission is required when a security manager is installed.
bind in interface NetworkChannelbind in class AsynchronousSocketChannellocal - the address to bind the socket, or null to bind the
socket to an automatically assigned socket address
ClosedChannelException - if the channel is closed
IOException - if some other I/O error occurs
public SocketAddress getLocalAddress()
throws IOException
null if the socket is not bound.
null
if the channel is not open
or the channel's socket is not bound
IOException - if an I/O error occurs
public AsyncSocketChannelImpl setOption(SocketOption name,
Object value)
throws IOException
The name parameter is the name of the socket option.
The value parameter is the value of the option and is of the
type specified by the option. A value of
null may be a valid value for some socket options.
setOption in interface NetworkChannelsetOption in class AsynchronousSocketChannelname - the name of the socket optionvalue - the value of the socket option
ClosedChannelException - if this channel is closed
IOException - if an I/O error occursSocketOption
public Object getOption(SocketOption name)
throws IOException
The return type is specific to the socket option and null
may be a valid value for some socket options.
name - the socket option
ClosedChannelException - if this channel is closed
IOException - if an I/O error occursSocketOptionpublic Set<SocketOption> options()
This method will continue to return the set of options even after the channel has been closed.
public AsyncSocketChannelImpl shutdown(ShutdownType how)
throws IOException
The how parameter specifies if the input, output, or both sides of the connection is shutdown. If the input side of the connection is shutdown then further read operations 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 to shutdown the input side of the connection has no effect. If the output side of the connection is shutdown then further write operations on the channel will complete immediately by throwning ExecutionException with cause ClosedChannelException. If the output side of the connection is already shutdown then invoking this method to shutdown the output side of the connection has no effect.
shutdown in class AsynchronousSocketChannelhow - specifies if the input, output, or both sides of the
connection is shutdown
ClosedChannelException - if this channel is closed
IOException - if some other I/O error occurs
public SocketAddress getConnectedAddress()
throws IOException
getConnectedAddress in class AsynchronousSocketChannelIOException - if an I/O error occurspublic boolean isConnectionPending()
The result of this method is a snapshot of the channel state. It may be invalid when the caller goes to examine the result and should not be used for purposes of coordination.
isConnectionPending in class AsynchronousSocketChannelpublic boolean isReadPending()
The result of this method is a snapshot of the channel state. It may be invalid when the caller goes to examine the result and should not be used for purposes of coordination.
isReadPending in class AsynchronousSocketChannelReadPendingExceptionpublic boolean isWritePending()
The result of this method is a snapshot of the channel state. It may be invalid when the caller goes to examine the result and should not be used for purposes of coordination.
isWritePending in class AsynchronousSocketChannelWritePendingException
public <A> IoFuture<Void,A> connect(SocketAddress remote,
A attachment,
CompletionHandler<Void,? super A> handler)
This method initiates an operation to connect this channel, returning a IoFuture representing the pending result of the operation. If the connection is successfully established then the IoFuture's get method will return null, otherwise it throws ExecutionException with the approach cause.
This method performs exactly the same security checks as the 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.
connect in class AsynchronousSocketChannelA - the attachment typeremote - the remote address to which this channel is to be
connectedattachment - the object to attach to the returned IoFuture
object; can be nullhandler - the handler for consuming the result; can be null
AsynchronousSocketChannel.getConnectedAddress(),
AsynchronousSocketChannel.isConnectionPending()
public <A> IoFuture<Integer,A> read(ByteBuffer dst,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
This method initiates the reading of a sequence of bytes from this channel into the given buffer, returning an IoFuture representing the pending result of the operation. The IoFuture's get method returns the number of bytes read, possibly zero, or -1 if all bytes have been read and channel has reached end-of-stream.
If a timeout is specified and the timeout elapses before the operation completes then it completes with ExecutionException and cause AbortedByTimeoutException. In that case it is guranteed that no bytes have been read from the channel into the given buffer.
Otherwise this method works in the same manner as the AsynchronousByteChannel.read(ByteBuffer,A,CompletionHandler) method.
read in class AsynchronousSocketChannelA - the attachment typedst - the buffer into which bytes are to be transferredtimeout - the timeout, or 0L for no timeoutunit - the time unit of the timeout argumentattachment - the object to attach to the returned IoFuture
object; can be nullhandler - the handler for consuming the result; can be null
public <A> IoFuture<Long,A> read(ByteBuffer[] dsts,
int offset,
int length,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Long,? super A> handler)
This method initiates the reading of a sequence of bytes from this channel into a subsequence of the given buffers, returning an IoFuture representing the pending result of the operation. The IoFuture's get method returns the number of bytes read, possibly zero, or -1 if all bytes have been read and 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()
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.
If a timeout is specified and the timeout elapses before the operation completes then it completes with ExecutionException and cause AbortedByTimeoutException. In that case it is guranteed that no bytes have been read from the channel into the given buffers.
read in class AsynchronousSocketChannelA - the attachment typedsts - the buffers into which bytes are to be transferredoffset - 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.lengthlength - the maximum number of buffers to be accessed; must be
non-negative and no larger than dsts.length - offsettimeout - the timeout, or 0L for no timeoutunit - the time unit of the timeout argumentattachment - the object to attach to the returned IoFuture
object; can be nullhandler - the handler for consuming the result; can be null
public <A> IoFuture<Integer,A> write(ByteBuffer src,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
This method initiates the writing of a sequence of bytes to this channel from the given buffer, returning an IoFuture representing the pending result of the operation. The IoFuture's get method will return the number of bytes written, possibly zero.
If a timeout is specified and the timeout elapses before the operation completes then it completes with ExecutionException and cause AbortedByTimeoutException. In that case it is guranteed that no bytes have written to the channel from the given buffer.
Otherwise this method works in the same manner as the AsynchronousByteChannel.write(ByteBuffer,A,CompletionHandler) method.
write in class AsynchronousSocketChannelA - the attachment typesrc - the buffer from which bytes are to be retrievedtimeout - the timeout, or 0L for no timeoutunit - the time unit of the timeout argumentattachment - the object to attach to the returned IoFuture
object; can be nullhandler - the handler for consuming the result; can be null
public <A> IoFuture<Long,A> write(ByteBuffer[] srcs,
int offset,
int length,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Long,? super A> handler)
This method initiates the writing of a sequence of bytes to this channel from a subsequence of the given buffers, returning an IoFuture representing the pending result of the operation. The IoFuture's get method will return the number of bytes written, possibly zero.
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()
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.
If a timeout is specified and the timeout elapses before the operation completes then it completes with ExecutionException and cause AbortedByTimeoutException. In that case it is guranteed that no bytes have written to the channel from the given buffers.
write in class AsynchronousSocketChannelA - the attachment typesrcs - the buffers from which bytes are to be retrievedoffset - 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 - the maximum number of buffers to be accessed; must be
non-negative and no larger than srcs.length - offsettimeout - the timeout, or 0L for no timeoutunit - the time unit of the timeout argumentattachment - the object to attach to the returned IoFuture
object; can be nullhandler - the handler for consuming the result; can be null
|
RedDwarf, Version 0.10.1 2010-03-14 10:56:12 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||