AlreadyConnectedException.java: Removed unneeded import.
2002-11-13 Michael Koch <konqueror@gmx.de> * java/nio/channels/AlreadyConnectedException.java: Removed unneeded import. (AlreadyConnectedException): Documentation added. * java/nio/channels/Pipe.java (SinkChannel.SinkChannel): Documentation added. (SinkChannel.validOps): New method. (SourceChannel.SourceChannel): Documentation added. (SourceChannel.validOps): New method. (Pipe): Documentation added. (open): Documentation added. (SinkChannel.channel): Documentation added. (SourceChannel.channel): Documentation added. * java/nio/channel/SelectableChannel.java (SelectableChannel): Documentation added. (blockingLock): Documentation added. (configureBlocking):Documentation added. (isBlocking):Documentation added. (isRegistered):Documentation added. (keyFor):Documentation added. (provider):Documentation added. (register): Documentation added. (validOps): Documentation added. * jaba/nio/channels/SelectionKey.java (SelectionKey): Documentation added. (attach): Documentation added. (attachment): Documentation added. (isAcceptable): Documentation added. (isConnetable): Documentation added. (isReadable): Documentation added. (isWritable): Documentation added. (cancel): Documentation added. (channel): Documentation added. (interestOps): Documentation added. (isValid): Documentation added. (readyOps): Documentation added. (selector): Documentation added. * jaba/nio/channels/Selector.java (Selector): Documentation added. (open): Documentation added. (close): Documentation added. (isOpen): Documentation added. (keys): Documentation added. (provider): Documentation added. (select): Documentation added. (selectedKeys): Documentation added. (selectNow): Documentation added. (wakeup): Documentation added. * java/nio/channels/spi/AbstractInterruptibleChannel.java (AbstractInterruptibleChannel): Documentation added. (opened): Default to true; (begin): Documentation added. (close): Set opened to false, documentation added. (isOpen): Documentation added. * java/nio/channels/spi/AbstractSelectionKey.java (AbstractSelectionKey): Documentation added. (cancel): Documentation added. (isValid): Documentation added. * java/nio/channels/spi/AbstractSelector.java (AbstractSelector): Documentation added. (begin): Documentation added. (close): Documentation added. (isOpen): Documentation added. (deregister): Documentation added. (end): Documentation added. (provider): Documentation added. (implCloseSelector): Documentation added. (register): Documentation added. * java/nio/channels/spi/SelectorProvider.java (SelectorProvider): Documentation added. (openDatagramChannel): Documentation added. (openPipe): Documentation added. (openSelector): Documentation added. (openServerSocketChannel): Documentation added. (openSocketChannel): Documentation added. (provider): Documentation added. From-SVN: r59077
This commit is contained in:
parent
e6179f4596
commit
70c73a4d1d
10 changed files with 457 additions and 146 deletions
|
@ -1,3 +1,81 @@
|
||||||
|
2002-11-13 Michael Koch <konqueror@gmx.de>
|
||||||
|
|
||||||
|
* java/nio/channels/AlreadyConnectedException.java:
|
||||||
|
Removed unneeded import.
|
||||||
|
(AlreadyConnectedException): Documentation added.
|
||||||
|
* java/nio/channels/Pipe.java
|
||||||
|
(SinkChannel.SinkChannel): Documentation added.
|
||||||
|
(SinkChannel.validOps): New method.
|
||||||
|
(SourceChannel.SourceChannel): Documentation added.
|
||||||
|
(SourceChannel.validOps): New method.
|
||||||
|
(Pipe): Documentation added.
|
||||||
|
(open): Documentation added.
|
||||||
|
(SinkChannel.channel): Documentation added.
|
||||||
|
(SourceChannel.channel): Documentation added.
|
||||||
|
* java/nio/channel/SelectableChannel.java
|
||||||
|
(SelectableChannel): Documentation added.
|
||||||
|
(blockingLock): Documentation added.
|
||||||
|
(configureBlocking):Documentation added.
|
||||||
|
(isBlocking):Documentation added.
|
||||||
|
(isRegistered):Documentation added.
|
||||||
|
(keyFor):Documentation added.
|
||||||
|
(provider):Documentation added.
|
||||||
|
(register): Documentation added.
|
||||||
|
(validOps): Documentation added.
|
||||||
|
* jaba/nio/channels/SelectionKey.java
|
||||||
|
(SelectionKey): Documentation added.
|
||||||
|
(attach): Documentation added.
|
||||||
|
(attachment): Documentation added.
|
||||||
|
(isAcceptable): Documentation added.
|
||||||
|
(isConnetable): Documentation added.
|
||||||
|
(isReadable): Documentation added.
|
||||||
|
(isWritable): Documentation added.
|
||||||
|
(cancel): Documentation added.
|
||||||
|
(channel): Documentation added.
|
||||||
|
(interestOps): Documentation added.
|
||||||
|
(isValid): Documentation added.
|
||||||
|
(readyOps): Documentation added.
|
||||||
|
(selector): Documentation added.
|
||||||
|
* jaba/nio/channels/Selector.java
|
||||||
|
(Selector): Documentation added.
|
||||||
|
(open): Documentation added.
|
||||||
|
(close): Documentation added.
|
||||||
|
(isOpen): Documentation added.
|
||||||
|
(keys): Documentation added.
|
||||||
|
(provider): Documentation added.
|
||||||
|
(select): Documentation added.
|
||||||
|
(selectedKeys): Documentation added.
|
||||||
|
(selectNow): Documentation added.
|
||||||
|
(wakeup): Documentation added.
|
||||||
|
* java/nio/channels/spi/AbstractInterruptibleChannel.java
|
||||||
|
(AbstractInterruptibleChannel): Documentation added.
|
||||||
|
(opened): Default to true;
|
||||||
|
(begin): Documentation added.
|
||||||
|
(close): Set opened to false, documentation added.
|
||||||
|
(isOpen): Documentation added.
|
||||||
|
* java/nio/channels/spi/AbstractSelectionKey.java
|
||||||
|
(AbstractSelectionKey): Documentation added.
|
||||||
|
(cancel): Documentation added.
|
||||||
|
(isValid): Documentation added.
|
||||||
|
* java/nio/channels/spi/AbstractSelector.java
|
||||||
|
(AbstractSelector): Documentation added.
|
||||||
|
(begin): Documentation added.
|
||||||
|
(close): Documentation added.
|
||||||
|
(isOpen): Documentation added.
|
||||||
|
(deregister): Documentation added.
|
||||||
|
(end): Documentation added.
|
||||||
|
(provider): Documentation added.
|
||||||
|
(implCloseSelector): Documentation added.
|
||||||
|
(register): Documentation added.
|
||||||
|
* java/nio/channels/spi/SelectorProvider.java
|
||||||
|
(SelectorProvider): Documentation added.
|
||||||
|
(openDatagramChannel): Documentation added.
|
||||||
|
(openPipe): Documentation added.
|
||||||
|
(openSelector): Documentation added.
|
||||||
|
(openServerSocketChannel): Documentation added.
|
||||||
|
(openSocketChannel): Documentation added.
|
||||||
|
(provider): Documentation added.
|
||||||
|
|
||||||
2002-11-12 Michael Koch <konqueror@gmx.de>
|
2002-11-12 Michael Koch <konqueror@gmx.de>
|
||||||
|
|
||||||
* java/nio/Buffer.java: Implemented.
|
* java/nio/Buffer.java: Implemented.
|
||||||
|
|
|
@ -37,11 +37,11 @@ exception statement from your version. */
|
||||||
|
|
||||||
package java.nio.channels;
|
package java.nio.channels;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class AlreadyConnectedException extends IllegalStateException
|
public class AlreadyConnectedException extends IllegalStateException
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Creates the exception
|
||||||
|
*/
|
||||||
public AlreadyConnectedException()
|
public AlreadyConnectedException()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,40 +40,82 @@ package java.nio.channels;
|
||||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||||
import java.nio.channels.spi.SelectorProvider;
|
import java.nio.channels.spi.SelectorProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Michael Koch
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
public abstract class Pipe
|
public abstract class Pipe
|
||||||
{
|
{
|
||||||
public abstract static class SinkChannel
|
public abstract static class SinkChannel
|
||||||
extends AbstractSelectableChannel
|
extends AbstractSelectableChannel
|
||||||
implements WritableByteChannel, GatheringByteChannel
|
implements WritableByteChannel, GatheringByteChannel
|
||||||
{
|
{
|
||||||
protected SinkChannel(SelectorProvider provider)
|
/**
|
||||||
|
* Initializes the channel.
|
||||||
|
*/
|
||||||
|
protected SinkChannel (SelectorProvider provider)
|
||||||
{
|
{
|
||||||
super (provider);
|
super (provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an operation set that is valid on this channel.
|
||||||
|
*
|
||||||
|
* The only valid operation on this channel is @see SelectionKey.OP_WRITE.
|
||||||
|
*/
|
||||||
|
public final int validOps ()
|
||||||
|
{
|
||||||
|
return SelectionKey.OP_WRITE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract static class SourceChannel
|
public abstract static class SourceChannel
|
||||||
extends AbstractSelectableChannel
|
extends AbstractSelectableChannel
|
||||||
implements ReadableByteChannel, ScatteringByteChannel
|
implements ReadableByteChannel, ScatteringByteChannel
|
||||||
{
|
{
|
||||||
protected SourceChannel(SelectorProvider provider)
|
/**
|
||||||
|
* Initializes the channel.
|
||||||
|
*/
|
||||||
|
protected SourceChannel (SelectorProvider provider)
|
||||||
{
|
{
|
||||||
super (provider);
|
super (provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an operation set that is valid on this channel.
|
||||||
|
*
|
||||||
|
* The only valid operation on this channel is @see SelectionKey.OP_READ.
|
||||||
|
*/
|
||||||
|
public final int validOps ()
|
||||||
|
{
|
||||||
|
return SelectionKey.OP_READ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the pipe.
|
||||||
|
*/
|
||||||
protected Pipe()
|
protected Pipe()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Opens a pipe.
|
||||||
|
*
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
public static Pipe open()
|
public static Pipe open()
|
||||||
{
|
{
|
||||||
return null;
|
return SelectorProvider.provider ().openPipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pipe's sink channel.
|
||||||
|
*/
|
||||||
public abstract Pipe.SinkChannel sink();
|
public abstract Pipe.SinkChannel sink();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pipe's source channel
|
||||||
|
*/
|
||||||
public abstract Pipe.SourceChannel source();
|
public abstract Pipe.SourceChannel source();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,50 +40,99 @@ package java.nio.channels;
|
||||||
import java.nio.channels.spi.AbstractInterruptibleChannel;
|
import java.nio.channels.spi.AbstractInterruptibleChannel;
|
||||||
import java.nio.channels.spi.SelectorProvider;
|
import java.nio.channels.spi.SelectorProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Michael Koch
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
public abstract class SelectableChannel
|
public abstract class SelectableChannel
|
||||||
extends AbstractInterruptibleChannel
|
extends AbstractInterruptibleChannel
|
||||||
{
|
{
|
||||||
protected SelectableChannel()
|
/**
|
||||||
|
* Initializes the channel.
|
||||||
|
*/
|
||||||
|
protected SelectableChannel ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Object blockingLock();
|
/**
|
||||||
|
* Returns the lock of this channel.
|
||||||
|
*/
|
||||||
|
public abstract Object blockingLock ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception ClosedChannelException FIXME
|
* Adjusts this channel's blocking mode.
|
||||||
* @exception IllegalBlockingModeException FIXME
|
*
|
||||||
* @exception IOException FIXME
|
* @exception ClosedChannelException If this channel is closed.
|
||||||
|
* @exception IllegalBlockingModeException If block is true and this channel
|
||||||
|
* is registered with one or more selectors.
|
||||||
|
* @exception IOException If an error occurs.
|
||||||
*/
|
*/
|
||||||
public abstract SelectableChannel configureBlocking(boolean block);
|
public abstract SelectableChannel configureBlocking (boolean block);
|
||||||
|
|
||||||
public abstract boolean isBlocking();
|
|
||||||
|
|
||||||
public abstract boolean isRegistered();
|
|
||||||
|
|
||||||
public abstract SelectionKey keyFor(Selector sel);
|
|
||||||
|
|
||||||
public abstract SelectorProvider provider();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception CancelledKeyException FIXME
|
* Tells whether this channel is blocking or not.
|
||||||
* @exception ClosedChannelException FIXME
|
|
||||||
* @exception IllegalArgumentException FIXME
|
|
||||||
* @exception IllegalBlockingModeException FIXME
|
|
||||||
* @exception IllegalSelectorException FIXME
|
|
||||||
*/
|
*/
|
||||||
public final SelectionKey register(Selector sel, int ops) throws java.nio.channels.ClosedChannelException
|
public abstract boolean isBlocking ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether or not this channel is currently registered with
|
||||||
|
* any selectors.
|
||||||
|
*/
|
||||||
|
public abstract boolean isRegistered ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the key representing the channel's registration with
|
||||||
|
* the given selector.
|
||||||
|
*/
|
||||||
|
public abstract SelectionKey keyFor (Selector sel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the provider that created this channel.
|
||||||
|
*/
|
||||||
|
public abstract SelectorProvider provider ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers this channel with the given selector,
|
||||||
|
* returning a selection key.
|
||||||
|
*
|
||||||
|
* @exception CancelledKeyException If this channel is currently registered
|
||||||
|
* with the given selector but the corresponding key has already been cancelled
|
||||||
|
* @exception ClosedChannelException If this channel is closed.
|
||||||
|
* @exception IllegalArgumentException If a bit in ops does not correspond
|
||||||
|
* to an operation that is supported by this channel, that is, if
|
||||||
|
* set & ~validOps() != 0.
|
||||||
|
* @exception IllegalBlockingModeException If block is true and this channel
|
||||||
|
* is registered with one or more selectors.
|
||||||
|
* @exception IllegalSelectorException If this channel was not created by
|
||||||
|
* the same provider as the given selector.
|
||||||
|
*/
|
||||||
|
public final SelectionKey register (Selector sel, int ops)
|
||||||
|
throws ClosedChannelException
|
||||||
{
|
{
|
||||||
return register(sel, ops, null);
|
return register (sel, ops, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception CancelledKeyException FIXME
|
* Registers this channel with the given selector,
|
||||||
* @exception ClosedChannelException FIXME
|
* returning a selection key.
|
||||||
* @exception IllegalArgumentException FIXME
|
*
|
||||||
* @exception IllegalBlockingModeException FIXME
|
* @exception CancelledKeyException If this channel is currently registered
|
||||||
* @exception IllegalSelectorException FIXME
|
* with the given selector but the corresponding key has already been
|
||||||
|
* cancelled.
|
||||||
|
* @exception ClosedChannelException If this channel is closed.
|
||||||
|
* @exception IllegalArgumentException If a bit in ops does not correspond
|
||||||
|
* to an operation that is supported by this channel, that is, if
|
||||||
|
* set & ~validOps() != 0.
|
||||||
|
* @exception IllegalBlockingModeException If block is true and this channel
|
||||||
|
* is registered with one or more selectors.
|
||||||
|
* @exception IllegalSelectorException If this channel was not created by
|
||||||
|
* the same provider as the given selector.
|
||||||
*/
|
*/
|
||||||
public abstract SelectionKey register(Selector sel, int ops, Object att) throws java.nio.channels.ClosedChannelException;
|
public abstract SelectionKey register (Selector sel, int ops, Object att)
|
||||||
|
throws ClosedChannelException;
|
||||||
|
|
||||||
public abstract int validOps();
|
/**
|
||||||
|
* Returns a set of valid operations on this channel.
|
||||||
|
*/
|
||||||
|
public abstract int validOps();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,10 @@ exception statement from your version. */
|
||||||
|
|
||||||
package java.nio.channels;
|
package java.nio.channels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Michael Koch
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
public abstract class SelectionKey
|
public abstract class SelectionKey
|
||||||
{
|
{
|
||||||
public static final int OP_ACCEPT = 1<<0;
|
public static final int OP_ACCEPT = 1<<0;
|
||||||
|
@ -46,75 +50,115 @@ public abstract class SelectionKey
|
||||||
|
|
||||||
Object attached;
|
Object attached;
|
||||||
|
|
||||||
protected SelectionKey()
|
/**
|
||||||
|
* Initializes the selection key.
|
||||||
|
*/
|
||||||
|
protected SelectionKey ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Object attach(Object obj)
|
/**
|
||||||
|
* Attaches obj to the key and returns the old attached object.
|
||||||
|
*/
|
||||||
|
public final Object attach (Object obj)
|
||||||
{
|
{
|
||||||
Object old = attached;
|
Object old = attached;
|
||||||
attached = obj;
|
attached = obj;
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Object attachment()
|
/**
|
||||||
|
* Returns the object attached to the key.
|
||||||
|
*/
|
||||||
|
public final Object attachment ()
|
||||||
{
|
{
|
||||||
return attached;
|
return attached;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception CancelledKeyException FIXME
|
* Tests if the channel attached to this key is ready to accept
|
||||||
|
* a new socket connection.
|
||||||
|
*
|
||||||
|
* @exception CancelledKeyException If this key has been cancelled
|
||||||
*/
|
*/
|
||||||
public final boolean isAcceptable()
|
public final boolean isAcceptable ()
|
||||||
{
|
{
|
||||||
return (readyOps() & OP_ACCEPT) != 0;
|
return (readyOps () & OP_ACCEPT) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception CancelledKeyException FIXME
|
* Tests whether this key's channel has either finished,
|
||||||
|
* or failed to finish, its socket-connection operation.
|
||||||
|
*
|
||||||
|
* @exception CancelledKeyException If this key has been cancelled
|
||||||
*/
|
*/
|
||||||
public final boolean isConnectable()
|
public final boolean isConnectable ()
|
||||||
{
|
{
|
||||||
return (readyOps() & OP_CONNECT) != 0;
|
return (readyOps () & OP_CONNECT) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception CancelledKeyException FIXME
|
* Tests if the channel attached to the key is readable.
|
||||||
|
*
|
||||||
|
* @exception CancelledKeyException If this key has been cancelled
|
||||||
*/
|
*/
|
||||||
public final boolean isReadable()
|
public final boolean isReadable ()
|
||||||
{
|
{
|
||||||
return (readyOps() & OP_READ) != 0;
|
return (readyOps () & OP_READ) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception CancelledKeyException FIXME
|
* Tests if the channel attached to the key is writable.
|
||||||
|
*
|
||||||
|
* @exception CancelledKeyException If this key has been cancelled
|
||||||
*/
|
*/
|
||||||
public final boolean isWritable()
|
public final boolean isWritable ()
|
||||||
{
|
{
|
||||||
return (readyOps() & OP_WRITE) != 0;
|
return (readyOps () & OP_WRITE) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void cancel();
|
/**
|
||||||
|
* Requests that the registration of this key's channel with
|
||||||
public abstract SelectableChannel channel();
|
* its selector be cancelled.
|
||||||
|
*/
|
||||||
|
public abstract void cancel ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception CancelledKeyException FIXME
|
* return the channel attached to the key.
|
||||||
*/
|
*/
|
||||||
public abstract int interestOps();
|
public abstract SelectableChannel channel ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception CancelledKeyException FIXME
|
* Returns the key's interest set.
|
||||||
* @exception IllegalArgumentException FIXME
|
*
|
||||||
|
* @exception CancelledKeyException If this key has been cancelled
|
||||||
*/
|
*/
|
||||||
public abstract SelectionKey interestOps(int ops);
|
public abstract int interestOps ();
|
||||||
|
|
||||||
public abstract boolean isValid();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception CancelledKeyException FIXME
|
* Sets this key's interest set to the given value.
|
||||||
|
*
|
||||||
|
* @exception CancelledKeyException If this key has been cancelled
|
||||||
|
* @exception IllegalArgumentException If a bit in the set does not
|
||||||
|
* correspond to an operation that is supported by this key's channel,
|
||||||
|
* that is, if set & ~(channel().validOps()) != 0
|
||||||
*/
|
*/
|
||||||
public abstract int readyOps();
|
public abstract SelectionKey interestOps (int ops);
|
||||||
|
|
||||||
public abstract Selector selector();
|
/**
|
||||||
|
* Tells whether or not this key is valid.
|
||||||
|
*/
|
||||||
|
public abstract boolean isValid ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves this key's ready-operation set.
|
||||||
|
*
|
||||||
|
* @exception CancelledKeyException If this key has been cancelled
|
||||||
|
*/
|
||||||
|
public abstract int readyOps ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the selector for which this key was created.
|
||||||
|
*/
|
||||||
|
public abstract Selector selector ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,60 +37,97 @@ exception statement from your version. */
|
||||||
|
|
||||||
package java.nio.channels;
|
package java.nio.channels;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.io.IOException;
|
||||||
import java.nio.channels.spi.SelectorProvider;
|
import java.nio.channels.spi.SelectorProvider;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Michael Koch
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
public abstract class Selector
|
public abstract class Selector
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Initializes the selector.
|
||||||
|
*/
|
||||||
protected Selector()
|
protected Selector()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Opens a selector.
|
||||||
|
*
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
public static Selector open()
|
public static Selector open ()
|
||||||
{
|
{
|
||||||
return SelectorProvider.provider().openSelector();
|
return SelectorProvider.provider ().openSelector ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Closes the selector.
|
||||||
|
*
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
public abstract void close();
|
public abstract void close () throws IOException;
|
||||||
|
|
||||||
public abstract boolean isOpen();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception ClosedSelectorException FIXME
|
* Tells whether the selector is open or not.
|
||||||
*/
|
*/
|
||||||
public abstract Set keys();
|
public abstract boolean isOpen ();
|
||||||
|
|
||||||
public abstract SelectorProvider provider();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception ClosedSelectorException FIXME
|
* Returns this selector's key set.
|
||||||
|
*
|
||||||
|
* @exception ClosedSelectorException If this selector is closed.
|
||||||
|
*/
|
||||||
|
public abstract Set keys ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the SelectorProvider that created the selector.
|
||||||
|
*/
|
||||||
|
public abstract SelectorProvider provider ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects a set of keys whose corresponding channels are ready
|
||||||
|
* for I/O operations.
|
||||||
|
*
|
||||||
|
* @exception ClosedSelectorException If this selector is closed.
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
public abstract int select();
|
public abstract int select () throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception ClosedSelectorException FIXME
|
* Selects a set of keys whose corresponding channels are ready
|
||||||
* @exception IllegalArgumentException FIXME
|
* for I/O operations.
|
||||||
|
*
|
||||||
|
* @param timeout The timeout to use.
|
||||||
|
*
|
||||||
|
* @exception ClosedSelectorException If this selector is closed.
|
||||||
|
* @exception IllegalArgumentException If the timeout value is negative.
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
public abstract int select(long timeout);
|
public abstract int select (long timeout) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception ClosedSelectorException FIXME
|
* Returns this selector's selected-key set.
|
||||||
|
*
|
||||||
|
* @exception ClosedSelectorException If this selector is closed.
|
||||||
*/
|
*/
|
||||||
public abstract Set selectedKeys();
|
public abstract Set selectedKeys ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception ClosedSelectorException FIXME
|
* Selects a set of keys whose corresponding channels are ready
|
||||||
|
* for I/O operations.
|
||||||
|
*
|
||||||
|
* @exception ClosedSelectorException If this selector is closed.
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
public abstract int selectNow();
|
public abstract int selectNow () throws IOException;
|
||||||
|
|
||||||
public abstract Selector wakeup();
|
/**
|
||||||
|
* Causes the first selection operation that has not yet returned to
|
||||||
|
* return immediately.
|
||||||
|
*/
|
||||||
|
public abstract Selector wakeup ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,47 +41,64 @@ import java.io.IOException;
|
||||||
import java.nio.channels.Channel;
|
import java.nio.channels.Channel;
|
||||||
import java.nio.channels.InterruptibleChannel;
|
import java.nio.channels.InterruptibleChannel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Michael Koch
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
public abstract class AbstractInterruptibleChannel
|
public abstract class AbstractInterruptibleChannel
|
||||||
implements Channel, InterruptibleChannel
|
implements Channel, InterruptibleChannel
|
||||||
{
|
{
|
||||||
boolean opened = false;
|
boolean opened = true;
|
||||||
|
|
||||||
protected AbstractInterruptibleChannel()
|
/**
|
||||||
|
* Initializes the channel.
|
||||||
|
*/
|
||||||
|
protected AbstractInterruptibleChannel ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void begin()
|
|
||||||
{
|
|
||||||
// Marks the beginning of an I/O operation that might block indefinitely.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Marks the beginning of an I/O operation that might block indefinitely.
|
||||||
|
*/
|
||||||
|
protected final void begin ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the channel.
|
||||||
|
*
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
public final void close() throws IOException
|
public final void close () throws IOException
|
||||||
{
|
{
|
||||||
// Closes this channel.
|
opened = false;
|
||||||
implCloseChannel();
|
implCloseChannel ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception AsynchronousCloseException FIXME
|
* Marks the end of an I/O operation that might block indefinitely.
|
||||||
* @exception ClosedByInterruptException FIXME
|
*
|
||||||
|
* @exception AsynchronousCloseException If the channel was asynchronously
|
||||||
|
* closed.
|
||||||
|
* @exception ClosedByInterruptException If the thread blocked in the
|
||||||
|
* I/O operation was interrupted.
|
||||||
*/
|
*/
|
||||||
protected final void end(boolean completed)
|
protected final void end (boolean completed)
|
||||||
{
|
{
|
||||||
// Marks the end of an I/O operation that might block indefinitely.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Closes the channel.
|
||||||
|
*
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
protected abstract void implCloseChannel() throws IOException;
|
protected abstract void implCloseChannel () throws IOException;
|
||||||
|
|
||||||
public final boolean isOpen()
|
/**
|
||||||
|
* Tells whether or not this channel is open.
|
||||||
|
*/
|
||||||
|
public final boolean isOpen ()
|
||||||
{
|
{
|
||||||
// Tells whether or not this channel is open.
|
|
||||||
return opened;
|
return opened;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,28 +39,37 @@ package java.nio.channels.spi;
|
||||||
|
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
public abstract class AbstractSelectionKey
|
public abstract class AbstractSelectionKey
|
||||||
extends SelectionKey
|
extends SelectionKey
|
||||||
{
|
{
|
||||||
boolean ok = true;
|
boolean ok = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the key.
|
||||||
|
*/
|
||||||
protected AbstractSelectionKey ()
|
protected AbstractSelectionKey ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels this key.
|
||||||
|
*/
|
||||||
public final void cancel ()
|
public final void cancel ()
|
||||||
{
|
{
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
selector ().selectedKeys ().add (this);
|
||||||
selector ().selectedKeys ().add (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether this key is valid or not.
|
||||||
|
*/
|
||||||
public final boolean isValid ()
|
public final boolean isValid ()
|
||||||
{
|
{
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ exception statement from your version. */
|
||||||
|
|
||||||
package java.nio.channels.spi;
|
package java.nio.channels.spi;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.Selector;
|
import java.nio.channels.Selector;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -44,44 +45,56 @@ import java.util.Set;
|
||||||
|
|
||||||
public abstract class AbstractSelector extends Selector
|
public abstract class AbstractSelector extends Selector
|
||||||
{
|
{
|
||||||
boolean closed = true;
|
boolean closed = false;
|
||||||
SelectorProvider provider;
|
SelectorProvider provider;
|
||||||
|
|
||||||
protected AbstractSelector(SelectorProvider provider)
|
/**
|
||||||
|
* Initializes the slector.
|
||||||
|
*/
|
||||||
|
protected AbstractSelector (SelectorProvider provider)
|
||||||
{
|
{
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void begin()
|
/**
|
||||||
|
* Marks the beginning of an I/O operation that might block indefinitely.
|
||||||
|
*/
|
||||||
|
protected final void begin ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Closes the channel.
|
||||||
|
*
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
public final void close()
|
public final void close () throws IOException
|
||||||
{
|
{
|
||||||
if (closed)
|
if (closed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
closed = true;
|
closed = true;
|
||||||
implCloseSelector();
|
implCloseSelector ();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void deregister(AbstractSelectionKey key)
|
/**
|
||||||
|
* Tells whether this channel is open or not.
|
||||||
|
*/
|
||||||
|
public final boolean isOpen ()
|
||||||
{
|
{
|
||||||
cancelledKeys().remove(key);
|
return ! closed;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void deregister (AbstractSelectionKey key)
|
||||||
|
{
|
||||||
|
cancelledKeys ().remove (key);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void end()
|
protected final void end()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isOpen()
|
public final SelectorProvider provider ()
|
||||||
{
|
|
||||||
return ! closed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final SelectorProvider provider()
|
|
||||||
{
|
{
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
@ -92,9 +105,10 @@ public abstract class AbstractSelector extends Selector
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exception IOException If an error occurs
|
* Closes the channel.
|
||||||
*/
|
*/
|
||||||
protected abstract void implCloseSelector();
|
protected abstract void implCloseSelector () throws IOException;
|
||||||
|
|
||||||
protected abstract SelectionKey register(AbstractSelectableChannel ch, int ops, Object att);
|
protected abstract SelectionKey register (AbstractSelectableChannel ch,
|
||||||
|
int ops, Object att);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* SelectorProvider.java --
|
/* SelectorProvider.java
|
||||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GNU Classpath.
|
This file is part of GNU Classpath.
|
||||||
|
@ -37,12 +37,14 @@ exception statement from your version. */
|
||||||
|
|
||||||
package java.nio.channels.spi;
|
package java.nio.channels.spi;
|
||||||
|
|
||||||
|
/* import gnu.java.nio.channels.SelectorProviderImpl; */
|
||||||
import java.nio.channels.DatagramChannel;
|
import java.nio.channels.DatagramChannel;
|
||||||
import java.nio.channels.Pipe;
|
import java.nio.channels.Pipe;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Michael Koch
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
public abstract class SelectorProvider
|
public abstract class SelectorProvider
|
||||||
|
@ -50,33 +52,52 @@ public abstract class SelectorProvider
|
||||||
static SelectorProvider pr;
|
static SelectorProvider pr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the <code>SelectorProvider<code> object
|
* Initializes the selector provider.
|
||||||
*
|
*
|
||||||
* @exception SecurityException If a security manager has been installed and
|
* @exception SecurityException If a security manager has been installed and
|
||||||
* it denies RuntimePermission("selectorProvider")
|
* it denies @see RuntimePermission ("selectorProvider").
|
||||||
*/
|
*/
|
||||||
protected SelectorProvider()
|
protected SelectorProvider ()
|
||||||
{
|
{
|
||||||
SecurityManager sm = System.getSecurityManager ();
|
SecurityManager sm = System.getSecurityManager ();
|
||||||
if (sm != null)
|
if (sm != null)
|
||||||
sm.checkPermission (new RuntimePermission ("selectorProvider"));
|
sm.checkPermission (new RuntimePermission ("selectorProvider"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract DatagramChannel openDatagramChannel();
|
/**
|
||||||
|
* Opens a datagram channel.
|
||||||
public abstract Pipe openPipe();
|
*/
|
||||||
|
public abstract DatagramChannel openDatagramChannel ();
|
||||||
public abstract AbstractSelector openSelector();
|
|
||||||
|
|
||||||
public abstract ServerSocketChannel openServerSocketChannel();
|
|
||||||
|
|
||||||
public abstract SocketChannel openSocketChannel();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the global <code>SelectorProvider</code> object
|
* Opens a pipe.
|
||||||
*/
|
*/
|
||||||
public static SelectorProvider provider()
|
public abstract Pipe openPipe ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a selector.
|
||||||
|
*/
|
||||||
|
public abstract AbstractSelector openSelector ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a server socket channel.
|
||||||
|
*/
|
||||||
|
public abstract ServerSocketChannel openServerSocketChannel ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a socket channel.
|
||||||
|
*/
|
||||||
|
public abstract SocketChannel openSocketChannel ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the system-wide default selector provider for this invocation
|
||||||
|
* of the Java virtual machine.
|
||||||
|
*/
|
||||||
|
public static SelectorProvider provider ()
|
||||||
{
|
{
|
||||||
|
/* if (pr == null) */
|
||||||
|
/* pr = new SelectorProviderImpl (); */
|
||||||
|
|
||||||
return pr;
|
return pr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue