|
||||||||||
| 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.AsynchronousDatagramChannel
com.sun.sgs.impl.nio.AsyncDatagramChannelImpl
class AsyncDatagramChannelImpl
An implementation of AsynchronousDatagramChannel.
Most interesting methods are delegated to the AsyncKey
returned by this channel's channel group.
Also implements the creation and management of multicast
MembershipKeys for this channel.
| Nested Class Summary | |
|---|---|
(package private) class |
AsyncDatagramChannelImpl.MembershipKeyImpl
A simple multicast membership key for datagram channels. |
| Field Summary | |
|---|---|
(package private) DatagramChannel |
channel
The underlying DatagramChannel. |
(package private) AtomicBoolean |
connectionPending
Indicates whether a connect operation is pending on this channel. |
(package private) static ProtocolFamily |
DEFAULT_PROTOCOL_FAMILY
The default protocol family if none is specified: StandardProtocolFamily.INET |
(package private) AsyncKey |
key
The AsyncKey for the underlying channel. |
(package private) ConcurrentHashMap<AsyncDatagramChannelImpl.MembershipKeyImpl,AsyncDatagramChannelImpl.MembershipKeyImpl> |
mcastKeys
The set of multicast membership keys for this channel. |
(package private) ProtocolFamily |
protocolFamily
The ProtocolFamily for this channel. |
| Constructor Summary | |
|---|---|
AsyncDatagramChannelImpl(ProtocolFamily pf,
AsyncGroupImpl group)
Creates a new instance registered with the given channel group. |
|
| Method Summary | ||
|---|---|---|
AsynchronousDatagramChannel |
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. |
|
|
disconnect(A attachment,
CompletionHandler<Void,? super A> handler)
Disconnects this channel. |
|
SocketAddress |
getConnectedAddress()
Returns the remote address to which this channel is connected, or null if the channel 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 |
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. |
|
MembershipKey |
join(InetAddress group,
NetworkInterface interf)
Joins a multicast group to begin receiving all datagrams sent to the group, returning a membership key. |
|
MembershipKey |
join(InetAddress group,
NetworkInterface interf,
InetAddress source)
Joins a multicast group to begin receiving datagrams sent to the group from a given source address. |
|
Set<SocketOption> |
options()
Returns a set of the socket options supported by this channel. |
|
|
read(ByteBuffer dst,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
Receives a datagram via this channel. |
|
|
receive(ByteBuffer dst,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<SocketAddress,? super A> handler)
Receives a datagram via this channel. |
|
|
send(ByteBuffer src,
SocketAddress target,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
Sends a datagram via this channel. |
|
AsyncDatagramChannelImpl |
setOption(SocketOption name,
Object value)
Sets the value of a socket option. |
|
String |
toString()
|
|
|
write(ByteBuffer src,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
Writes a datagram to this channel. |
|
| Methods inherited from class com.sun.sgs.nio.channels.AsynchronousDatagramChannel |
|---|
connect, disconnect, open, open, read, read, receive, receive, send, send, 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 |
|---|
static final ProtocolFamily DEFAULT_PROTOCOL_FAMILY
StandardProtocolFamily.INET
final DatagramChannel channel
DatagramChannel.
final AsyncKey key
AsyncKey for the underlying channel.
final ProtocolFamily protocolFamily
ProtocolFamily for this channel.
final ConcurrentHashMap<AsyncDatagramChannelImpl.MembershipKeyImpl,AsyncDatagramChannelImpl.MembershipKeyImpl> mcastKeys
final AtomicBoolean connectionPending
| Constructor Detail |
|---|
AsyncDatagramChannelImpl(ProtocolFamily pf,
AsyncGroupImpl group)
throws IOException
null
is specified as the protocol family, the default family is used.
group - the channel grouppf - the protocol family, or null for the default
protocol family
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 AsynchronousDatagramChannel 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.
This method performs exactly the same security checks as the bind method of the DatagramSocket class. That is, if a security manager has been installed then this method verifies that its checkListen method permits waiting for a connection request on the specified local port number.
bind in interface NetworkChannelbind in class AsynchronousDatagramChannellocal - the address to bind the socket, or null to bind the
socket to an automatically assigned socket address
SecurityException - if a security manager exists and its
checkListen method
doesn't allow the operation.
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 AsyncDatagramChannelImpl 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 AsynchronousDatagramChannelname - 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 MembershipKey join(InetAddress group,
NetworkInterface interf)
throws IOException
If this channel is currently a member of the group on the given
interface to receive all datagrams then the membership key,
representing that membership, is returned. Otherwise this channel
joins the group and the resulting new membership key is returned. The
resulting membership key is not
source-specific.
A multicast channel may join several multicast groups, including the same group on more than one interface. An implementation may impose a limit on the number of groups that may be joined at the same time.
group - the multicast address to joininterf - the network interface on which to join the group
ClosedChannelException - if this channel is closed
IOException - if an I/O error occurs
public MembershipKey join(InetAddress group,
NetworkInterface interf,
InetAddress source)
throws IOException
If this channel is currently a member of the group on the given
interface to receive datagrams from the given source address then the
membership key, representing that membership, is returned. Otherwise
this channel joins the group and the resulting new membership key is
returned. The resulting membership key is
source-specific.
Membership is accumulative and this method may be invoked again
with the same group and interface to allow receiving datagrams sent by
other source addresses to the group. This method fails, by throwing
IllegalStateException, if the channel is currently a member to
receive all datagrams sent to the group on the interface.
This implementation always throws UnsupportedOperationException.
group - the multicast address to joininterf - the network interface on which to join the groupsource - the source address
ClosedChannelException - if this channel is closed
IOException - if an I/O error occurs
public SocketAddress getConnectedAddress()
throws IOException
getConnectedAddress in class AsynchronousDatagramChannelIOException - if an I/O error occurs
public <A> IoFuture<Void,A> connect(SocketAddress remote,
A attachment,
CompletionHandler<Void,? super A> handler)
This method initiates an operation to configure the channel so that
it only receives datagrams from, and sends datagrams to, the given
remote peer address. Once connected, datagrams may not be
received from or sent to any other address. The channel remains
connected until it is
disconnected or until
it is closed. This method returns an IoFuture representing
the pending result of the operation. The get
method returns null upon successful completion.
This method performs exactly the same security checks as the
connect
method of the DatagramSocket class. That is, if a security
manager has been installed then this method verifies that its
checkAccept and
checkConnect
methods permit datagrams to be received from and sent to,
respectively, the given remote address.
This method may be invoked at any time and may thus affect read or write operations that are already in progress at the moment that the socket is connected.
connect in class AsynchronousDatagramChannelA - 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
IoFuture object representing the pending result
public <A> IoFuture<Void,A> disconnect(A attachment,
CompletionHandler<Void,? super A> handler)
This method initiates an operation to configure the channel so that
it can receive datagrams from, and sends datagrams to, any remote
address so long as the security manager, if installed, permits it.
This method returns an IoFuture representing
the pending result of the operation. The get
method returns null upon successful completion.
This method may be invoked at any time and may thus affect read or write operations that are already in progress at the moment that the socket is disconnected.
If this channel's is not connected then the operation completes
succesfully (meaning that the completion handler is invoked, and the
IoFuture's get method returns null).
disconnect in class AsynchronousDatagramChannelA - the attachment typeattachment - the object to attach to the
returned IoFuture object; can be nullhandler - the handler for consuming the result; can be
null
IoFuture object representing the pending resultpublic 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 AsynchronousDatagramChannelReadPendingExceptionpublic 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 AsynchronousDatagramChannelWritePendingException
public <A> IoFuture<SocketAddress,A> receive(ByteBuffer dst,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<SocketAddress,? super A> handler)
This method initiates the receiving of a datagram, returning an
IoFuture representing the pending result of the operation.
The IoFuture's get method returns the
source address of the datagram upon successful completion.
The datagram is transferred into the given byte buffer starting at
its current position, as if by a regular read
operation. If there are fewer bytes remaining in the buffer than are
required to hold the datagram then the remainder of the datagram is
silently discarded.
When a security manager has been installed and the channel is not
connected, then it verifies that the source's address and port number
are permitted by the security manager's
checkAccept method. The
permission check is performed with privileges that are restricted by
the calling context of this method. If the permission check fails
then the operation completes by throwing ExecutionException
with cause SecurityException. The overhead of this security
check can be avoided by first connecting the socket via the
connect
method.
receive in class AsynchronousDatagramChannelA - the attachment typedst - the buffer into which the datagram is 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
IoFuture object representing the pending result
public <A> IoFuture<Integer,A> send(ByteBuffer src,
SocketAddress target,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
This method initiates sending of a datagram, returning an
IoFuture representing the pending result of the operation.
The operation sends the remaining bytes in the given buffer as a
single datagram to the given target address. The result of the
operation, obtained by invoking the IoFuture's
get method, is the number of bytes sent. The
number of bytes sent is either the number of bytes that were
remaining in the buffer or zero if there was insufficient room for
the datagram in the underlying output buffer.
The datagram is transferred from the byte buffer as if by a regular
write
operation.
If there is a security manager installed and the the channel is not
connected then this method verifies that the target address and port
number are permitted by the security manager's
checkConnect
method. The overhead of this security check can be avoided by first
connecting the socket via the
connect
method.
send in class AsynchronousDatagramChannelA - the attachment typesrc - the buffer containing the datagram to be senttarget - the address to which the datagram is to be senttimeout - 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
IoFuture object representing the pending result
public <A> IoFuture<Integer,A> read(ByteBuffer dst,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
This method initiates the receiving of a datagram, returning an
IoFuture representing the pending result of the operation.
The IoFuture's get method returns the
the number of bytes transferred upon successful completion.
This method may only be invoked if this channel is connected, and it
only accepts datagrams from the peer that the channel is connected
too. The datagram is transferred into the given byte buffer starting
at its current position and exactly as specified in the
AsynchronousByteChannel interface. If there are fewer bytes
remaining in the buffer than are required to hold the datagram then
the remainder of the datagram is silently discarded.
read in class AsynchronousDatagramChannelA - the attachment typedst - the buffer into which the datagram is 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
IoFuture object representing the pending result
public <A> IoFuture<Integer,A> write(ByteBuffer src,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
This method initiates sending of a datagram, returning an
IoFuture representing the pending result of the operation.
The operation sends the remaining bytes in the given buffer as a
single datagram. The result of the
operation, obtained by invoking the IoFuture's
get method, is the number of bytes sent. The
number of bytes sent is either the number of bytes that were
remaining in the buffer or zero if there was insufficient room for
the datagram in the underlying output buffer.
The datagram is transferred from the byte buffer as if by a regular
write
operation.
This method may only be invoked if this channel is connected, in
which case it sends datagrams directly to the socket's peer.
Otherwise it behaves exactly as specified in the
AsynchronousByteChannel interface.
write in class AsynchronousDatagramChannelA - the attachment typesrc - the buffer containing the datagram to be senttimeout - 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
IoFuture object representing the pending result
|
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 | |||||||||