|
JavaTM SCTP API DRAFT ea-b10 |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.nio.channels.spi.AbstractInterruptibleChannel
java.nio.channels.SelectableChannel
java.nio.channels.spi.AbstractSelectableChannel
com.sun.nio.sctp.SctpMultiChannel
public abstract class SctpMultiChannel
A selectable channel for message-oriented SCTP sockets.
An SCTP multi channel supports many associations on a single socket.
An SctpMultiChannel is created by invoking the
open method of this class. A newly-created channel is open but
not yet bound. An attempt to invoke the receive method of an
unbound channel will cause the NotYetBoundException
to be thrown. An attempt to invoke the send method of an
unbound channel will cause it to first invoke the bind method.
The address(es) that the channel's socket is bound to can be retrieved by
calling getAllLocalAddresses.
Messages may be sent and received without explicitly setting up an
association with the remote peer. The channel will implicitly setup
a new association whenever it sends or receives a message from a remote
peer if there is not already an association with that peer. Upon successful
association setup, an association changed notification will be put to the SCTP stack with its
event parameter set to COMM_UP. This notification can be received by invoking receive.
Socket options are configured using the
setOption method. An
SctpMultiChannel supports the following options:
and may support additional (implementation specific) options. The list of options supported is obtained by invoking the
Option Name Description SCTP_DISABLE_FRAGMENTSEnables or disables message fragmentation SCTP_EXPLICIT_COMPLETEEnables or disables explicit message completion SCTP_FRAGMENT_INTERLEAVEControls how the presentation of messages occur for the message receiver SCTP_INIT_MAXSTREAMSThe maximum number of streams requested by the local endpoint during association initialization SCTP_NODELAYEnables or disable a Nagle-like algorithm SCTP_PRIMARY_ADDRRequests that the local SCTP stack use the given peer address as the association primary SCTP_SET_PEER_PRIMARY_ADDRRequests that the peer mark the enclosed address as the association primary SO_SNDBUFThe size of the socket send buffer SO_RCVBUFThe size of the socket receive buffer SO_LINGERLinger on close if data is present (when configured in blocking mode only)
options
method.
SCTP one-to-many socket channels are safe for use by multiple concurrent threads. They support concurrent sending and receiving, though at most one thread may be sending and at most one thread may be receiving at any given time.
| Constructor Summary | |
|---|---|
protected |
SctpMultiChannel(SelectorProvider provider)
Initializes a new instance of this class. |
| Method Summary | ||
|---|---|---|
abstract Set<Association> |
associations()
Returns the open associations on this channel's socket. |
|
SctpMultiChannel |
bind(SocketAddress local)
Binds the channel's socket to a local address and configures the socket to listen for connections. |
|
abstract SctpMultiChannel |
bind(SocketAddress local,
int backlog)
Binds the channel's socket to a local address and configures the socket to listen for connections. |
|
abstract SctpMultiChannel |
bindAddress(InetAddress address)
Adds the given address to the bound addresses for the channel's socket. |
|
abstract SctpChannel |
branch(Association association)
Branches off an association. |
|
abstract Set<SocketAddress> |
getAllLocalAddresses()
Returns all of the socket addresses to which this channel's socket is bound. |
|
abstract
|
getOption(SctpSocketOption<T> name,
Association association)
Returns the value of a socket option. |
|
abstract Set<SocketAddress> |
getRemoteAddresses(Association association)
Returns all of the remote addresses to which the given association on this channel's socket is connected. |
|
static SctpMultiChannel |
open()
Opens a one-to-many SCTP socket channel. |
|
abstract Set<SctpSocketOption<?>> |
options()
Returns a set of the socket options supported by this channel. |
|
abstract
|
receive(ByteBuffer buffer,
T attachment,
NotificationHandler<T> handler)
Receives a message and/or handles a notification via this channel. |
|
abstract int |
send(ByteBuffer buffer,
MessageInfo messageInfo)
Sends a message via this channel. |
|
abstract
|
setOption(SctpSocketOption<T> name,
T value,
Association association)
Sets the value of a socket option. |
|
abstract SctpMultiChannel |
shutdown(Association association)
Shutdown an association without closing the channel. |
|
abstract SctpMultiChannel |
unbindAddress(InetAddress address)
Removes the given address from the bound addresses for the channel's socket. |
|
int |
validOps()
Returns an operation set identifying this channel's supported operations. |
|
| Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel |
|---|
blockingLock, configureBlocking, implCloseChannel, implCloseSelectableChannel, implConfigureBlocking, isBlocking, isRegistered, keyFor, provider, register |
| Methods inherited from class java.nio.channels.SelectableChannel |
|---|
register |
| Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel |
|---|
begin, close, end, isOpen |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.nio.channels.Channel |
|---|
close, isOpen |
| Constructor Detail |
|---|
protected SctpMultiChannel(SelectorProvider provider)
provider - The selector provider for this channel| Method Detail |
|---|
public static SctpMultiChannel open()
throws IOException,
UnsupportedOperationException
The new channel is unbound.
UnsupportedOperationException - If the SCTP protocol is not supported
IOException - If an I/O error occurs
public abstract Set<Association> associations()
throws ClosedChannelException,
NotYetBoundException
Only associations whose COMM_UP association change event has been received are included
in the returned set of associations. Associations for which a
COMM_LOST or SHUTDOWN association change
event have been receive are removed from the set of associations.
The returned set of associations is a snapshot of the open associations at the time that this methos is invoked.
Set containing the open associations, or an empty
Set if there are none.
ClosedChannelException - If this channel is closed
NotYetBoundException - If this channel is not yet bound
public abstract SctpMultiChannel bind(SocketAddress local,
int backlog)
throws IOException
This method is used to establish a relationship between the socket
and the local address. Once a relationship is established then
the socket remains bound until the channel is closed. This relationship
may not necesssarily be with the address local as it may be removed
by unbindAddress, but there will always be at least one local
address bound to the channel's socket once an invocation of this method
successfully completes.
An attempt to bind a socket that is already bound throws
AlreadyBoundException. If the local
parameter has the value null then the socket address is
assigned automatically.
Once the channel's socket has been successfully bound more addresses
may be bound to it using bindAddress, or removed using
unbindAddress.
The backlog parameter is the maximum number of pending connections on
the socket. Its exact semantics are implementation specific. An implementation
may impose an implementation specific maximum length or may choose to ignore
the parameter. If the backlog parameter has the value 0, or a negative
value, then an implementation specific default is used.
local - The local address to bind the socket, or null to
bind the socket to an automatically assigned socket addressbacklog - The maximum number number of pending connections
ClosedChannelException - If this channel is closed
AlreadyBoundException - If this channel is already bound
UnsupportedAddressTypeException - If the type of the given address is not supported
SecurityException - If a security manager has been installed and its checkListen method
denies the operation
IOException - If some other I/O error occurs
public final SctpMultiChannel bind(SocketAddress local)
throws IOException
This method works as if invoking it were equivalent to evaluating the expression:
bind(local, 0);
local - The local address to bind the socket, or null to
bind the socket to an automatically assigned socket address
ClosedChannelException - If this channel is closed
AlreadyBoundException - If this channel is already bound
UnsupportedAddressTypeException - If the type of the given address is not supported
SecurityException - If a security manager has been installed and its checkListen method
denies the operation
IOException - If some other I/O error occurs
public abstract SctpMultiChannel bindAddress(InetAddress address)
throws IOException
The channel must be first bound using bind before
invoking this method, otherwise NotYetBoundException is thrown.
The bind method takes a SocketAddress as its
argument which typically contains a port number as well as an address.
Addresses subquently bound using this method are simply addresses as the
SCTP port number remains the same for the lifetime of the channel.
New associations setup after this method successfully completes will be associated with the given address. If the endpoint supports dynamic address reconfiguration then it may send the appropriate message to the peer to change the peers address lists.
address - The address to add to the bound addresses for the socket
ClosedChannelException - If this channel is closed
NotYetBoundException - If this channel is not yet bound
IllegalArgumentException - If address is null
IOException - If some other I/O error occurs
public abstract SctpMultiChannel unbindAddress(InetAddress address)
throws IOException
The channel must be first bound using bind before
invoking this method, otherwise NotYetBoundException is thrown.
If this method is invoked on a channel that does
not have address as one of its bound addresses, or that has only
one local address bound to it, then this method throws
IllegalUnbindException.
The initial address that the channel's socket is bound to using
bind may be removed from the bound addresses for the
channel's socket.
New associations setup after this method successfully completes will not be associated with the given address. If the endpoint supports dynamic address reconfiguration then it may send the appropriate message to the peer to change the peers address lists.
address - The address to remove from the bound addresses for the socket
ClosedChannelException - If this channel is closed
NotYetBoundException - If this channel is not yet bound
IllegalUnbindException - address is not bound to the channel's socket, or the
channel has only one address bound to it
IllegalArgumentException - If address is null
IOException - If some other I/O error occurs
public abstract Set<SocketAddress> getAllLocalAddresses()
throws IOException
Set if the channel's socket is not
bound
ClosedChannelException - If the channel is closed
IOException - If an I/O error occurs
public abstract Set<SocketAddress> getRemoteAddresses(Association association)
throws IOException
Set if the association has been shutdown
ClosedChannelException - If the channel is closed
IOException - If an I/O error occurs
public abstract SctpMultiChannel shutdown(Association association)
throws IOException
association - The association to shutdown
ClosedChannelException - If this channel is closed
IOException - If some other I/O error occurs
public abstract <T> T getOption(SctpSocketOption<T> name,
Association association)
throws IOException
Note that some options are retrieved on the channel's socket,
therefore the association parameter is not applicable and will be
ignored if given. However, if the option is association specific then the
association must be given.
name - The socket optionassociation - The association whose option should be retrieved, or null
if this option should be retrieved at the channel's socket level.
null may be
a valid value for some socket options.
IllegalArgumentException - If the socket option is not supported by this channel
ClosedChannelException - If this channel is closed
IOException - If an I/O error occursSctpStandardSocketOption
public abstract <T> SctpMultiChannel setOption(SctpSocketOption<T> name,
T value,
Association association)
throws IOException
Note that some options are retrieved on the channel's socket,
therefore the association parameter is not applicable and will be
ignored if given. However, if the option is association specific then the
association must be given.
name - The socket optionassociation - The association whose option should be set, or null
if this option should be set at the channel's socket level.value - The value of the socket option. A value of null may be
a valid value for some socket options.
IllegalArgumentException - If the socket option is not supported by this channel, or
the value is not a valid value for this socket option
ClosedChannelException - If this channel is closed
IOException - If an I/O error occursSctpStandardSocketOptionpublic abstract Set<SctpSocketOption<?>> options()
This method will continue to return the set of options even after the channel has been closed.
public final int validOps()
SCTP one-to-many socket channels support reading, and writing, so this
method returns
(SelectionKey.OP_READ | SelectionKey.OP_WRITE).
validOps in class SelectableChannel
public abstract <T> MessageInfo receive(ByteBuffer buffer,
T attachment,
NotificationHandler<T> handler)
throws IOException
If a message or notification is immediately available, or if this
channel is in blocking mode and one eventually becomes available, then
the message or notification is returned or handled, respectively. If this
channel is in non-blocking mode and a message or notification is not
immediately available then this method immediately returns null.
If this method receives a message it is copied into the given byte
buffer and an MessageInfo is returned.
The message is transferred into the given byte buffer starting at its
current position and the buffers position is incremented by the number of
bytes read. If there are fewer bytes remaining in the buffer than are
required to hold the message, or the underlying input buffer does not
contain the complete message, then an invocation of isComplete on the returned MessageInfo will return false, and more invocations of this
method will be necessary to completely consume the messgae. Only
one message at a time will be partially delivered in any stream. The
socket option SCTP_FRAGMENT_INTERLEAVE controls various aspects of what interlacing of
messages occurs.
If this method receives a notification then the appropriate method of
the given handler, if there is one, is invoked. If the handler returns CONTINUE then this method will try to receive another
message/notification, otherwise, if RETURN is returned
this method will return null. If an uncaught exception is thrown by the
handler it will be propagated up the stack through this method.
If a security manager has been installed then for each new association
setup this method verifies that the associations source address and port
number are permitted by the security manager's checkAccept method.
This method may be invoked at any time. If another thread has
already initiated a receive operation upon this channel, then an
invocation of this method will block until the first operation is
complete. The given handler is invoked without holding any locks used
to enforce the above synchronization policy, that way handlers
will not stall other threads from receiving. A handler should not invoke
the receive method of this channel, if it does an
IllegalReceiveException will be thrown.
buffer - The buffer into which bytes are to be transferredattachment - The object to attach to the receive operation; can be
nullhandler - A handler to handle notifications from the SCTP stack, or
null to ignore any notifications.
MessageInfo, null if this channel is in
non-blocking mode and no messages are immediately available or
the notification handler returns RETURN after handling
a notification
ClosedChannelException - If this channel is closed
AsynchronousCloseException - If another thread closes this channel
while the read operation is in progress
ClosedByInterruptException - If another thread interrupts the current thread
while the read operation is in progress, thereby
closing the channel and setting the current thread's
interrupt status
NotYetBoundException - If this channel is not yet bound
IllegalReceiveException - If the given handler invokes the receive method of this
channel
SecurityException - If a security manager has been installed and it does not permit
messages to be accepted from the message's sender
IOException - If some other I/O error occurs
public abstract int send(ByteBuffer buffer,
MessageInfo messageInfo)
throws IOException
If this channel is unbound then this method will invoke bind(null, 0) before sending any data.
If there is no association existing between this channel's socket
and the intended receiver, identified by the address in the given messageInfo, then one
will be automatically setup to the intended receiver. This is considered
to be Implicit Association Setup. Upon successful association setup, an
association changed
notification will be put to the SCTP stack with its event parameter set
to COMM_UP
. This notification can be received by invoking receive.
If this channel is in blocking mode, there is sufficient room in the
underlying output buffer, then the remaining bytes in the given byte
buffer are transmitted as a single message. Sending a message
is atomic unless explicit message completion SCTP_EXPLICIT_COMPLETE
socket option is enabled on this channel's socket.
If this channel is in non-blocking mode, there is sufficient room
in the underlying output buffer, and an implicit association setup is
required, then the remaining bytes in the given byte buffer are
transmitted as a single message, subject to SCTP_EXPLICIT_COMPLETE.
If for any reason the message cannot
be delivered an association
changed notification is put on the SCTP stack with its event parameter set
to CANT_START.
The message is transferred from the byte buffer as if by a regular
write operation.
If a security manager has been installed then for each new association
setup this method verifies that the given remote peers address and port
number are permitted by the security manager's checkConnect method.
This method may be invoked at any time. If another thread has already initiated a send operation upon this channel, then an invocation of this method will block until the first operation is complete.
buffer - The buffer containing the message to be sentmessageInfo - Ancillary data about the message to be sent
InvalidStreamExcepton - If streamNumber is negative, or if an association already
exists and streamNumber is greater than the maximum number
of outgoing streams
ClosedChannelException - If this channel is closed
AsynchronousCloseException - If another thread closes this channel
while the read operation is in progress
ClosedByInterruptException - If another thread interrupts the current thread
while the read operation is in progress, thereby
closing the channel and setting the current thread's
interrupt status
SecurityException - If a security manager has been installed and it does not permit
messages to be accepted from the messages's sender
IOException - If some other I/O error occurs
public abstract SctpChannel branch(Association association)
throws IOException
An application can invoke this method to branch off an association
into a separate channel. The new socket will be a bound and connected
SctpChannel. The branched off association will no longer be
part of this channel.
This is particularly useful when, for instance, the application wishes to have a number of sporadic message senders/receivers remain under the original one-to-many style socket but branch off those associations carrying high volume data traffic into their own separate socket descriptors.
association - The association to branch off
SctpChannel
ClosedChannelException - If this channel is closed
IOException - If some other I/O error occurs
|
JavaTM SCTP API DRAFT ea-b10 |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||