diff options
Diffstat (limited to 'libjava/java/nio/channels/spi')
4 files changed, 113 insertions, 52 deletions
diff --git a/libjava/java/nio/channels/spi/AbstractInterruptibleChannel.java b/libjava/java/nio/channels/spi/AbstractInterruptibleChannel.java index 235b995d2..855087b 100644 --- a/libjava/java/nio/channels/spi/AbstractInterruptibleChannel.java +++ b/libjava/java/nio/channels/spi/AbstractInterruptibleChannel.java @@ -41,47 +41,64 @@ import java.io.IOException; import java.nio.channels.Channel; import java.nio.channels.InterruptibleChannel; +/** + * @author Michael Koch + * @since 1.4 + */ public abstract class AbstractInterruptibleChannel 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. + */ + protected final void begin () { - // Marks the beginning of an I/O operation that might block indefinitely. } /** + * Closes the channel. + * * @exception IOException If an error occurs */ - public final void close() throws IOException + public final void close () throws IOException { - // Closes this channel. - implCloseChannel(); + opened = false; + implCloseChannel (); } /** - * @exception AsynchronousCloseException FIXME - * @exception ClosedByInterruptException FIXME + * Marks the end of an I/O operation that might block indefinitely. + * + * @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 */ - 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; } } - diff --git a/libjava/java/nio/channels/spi/AbstractSelectionKey.java b/libjava/java/nio/channels/spi/AbstractSelectionKey.java index e14e3b3..01ea4f3 100644 --- a/libjava/java/nio/channels/spi/AbstractSelectionKey.java +++ b/libjava/java/nio/channels/spi/AbstractSelectionKey.java @@ -39,28 +39,37 @@ package java.nio.channels.spi; import java.nio.channels.SelectionKey; +/** + * @since 1.4 + */ public abstract class AbstractSelectionKey extends SelectionKey { boolean ok = true; + /** + * Initializes the key. + */ protected AbstractSelectionKey () { } - + + /** + * Cancels this key. + */ public final void cancel () { if (ok) - { - selector ().selectedKeys ().add (this); - } + selector ().selectedKeys ().add (this); ok = false; } + /** + * Tells whether this key is valid or not. + */ public final boolean isValid () { return ok; } } - diff --git a/libjava/java/nio/channels/spi/AbstractSelector.java b/libjava/java/nio/channels/spi/AbstractSelector.java index 033a8d7..fc0aeca3 100644 --- a/libjava/java/nio/channels/spi/AbstractSelector.java +++ b/libjava/java/nio/channels/spi/AbstractSelector.java @@ -37,6 +37,7 @@ exception statement from your version. */ package java.nio.channels.spi; +import java.io.IOException; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.util.List; @@ -44,57 +45,70 @@ import java.util.Set; public abstract class AbstractSelector extends Selector { - boolean closed = true; + boolean closed = false; SelectorProvider provider; - protected AbstractSelector(SelectorProvider provider) + /** + * Initializes the slector. + */ + protected AbstractSelector (SelectorProvider 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 */ - public final void close() + public final void close () throws IOException { if (closed) return; + 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 end() + + protected final void deregister (AbstractSelectionKey key) { + cancelledKeys ().remove (key); } - public final boolean isOpen() + protected final void end() { - return ! closed; } - public final SelectorProvider provider() + public final SelectorProvider provider () { return provider; } - + protected final Set cancelledKeys() { return null; } - + /** - * @exception IOException If an error occurs + * Closes the channel. */ - protected abstract void implCloseSelector(); - - protected abstract SelectionKey register(AbstractSelectableChannel ch, int ops, Object att); + protected abstract void implCloseSelector () throws IOException; + + protected abstract SelectionKey register (AbstractSelectableChannel ch, + int ops, Object att); } diff --git a/libjava/java/nio/channels/spi/SelectorProvider.java b/libjava/java/nio/channels/spi/SelectorProvider.java index 93ea537..06017f7 100644 --- a/libjava/java/nio/channels/spi/SelectorProvider.java +++ b/libjava/java/nio/channels/spi/SelectorProvider.java @@ -1,4 +1,4 @@ -/* SelectorProvider.java -- +/* SelectorProvider.java Copyright (C) 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,12 +37,14 @@ exception statement from your version. */ package java.nio.channels.spi; +/* import gnu.java.nio.channels.SelectorProviderImpl; */ import java.nio.channels.DatagramChannel; import java.nio.channels.Pipe; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; /** + * @author Michael Koch * @since 1.4 */ public abstract class SelectorProvider @@ -50,33 +52,52 @@ public abstract class SelectorProvider static SelectorProvider pr; /** - * Creates the <code>SelectorProvider<code> object + * Initializes the selector provider. * * @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 (); if (sm != null) sm.checkPermission (new RuntimePermission ("selectorProvider")); } - - public abstract DatagramChannel openDatagramChannel(); - - public abstract Pipe openPipe(); - public abstract AbstractSelector openSelector(); + /** + * Opens a datagram channel. + */ + public abstract DatagramChannel openDatagramChannel (); + + /** + * Opens a pipe. + */ + public abstract Pipe openPipe (); + + /** + * Opens a selector. + */ + public abstract AbstractSelector openSelector (); - public abstract ServerSocketChannel openServerSocketChannel(); + /** + * Opens a server socket channel. + */ + public abstract ServerSocketChannel openServerSocketChannel (); - public abstract SocketChannel openSocketChannel(); - /** - * Returns the global <code>SelectorProvider</code> object + * Opens a socket channel. */ - public static SelectorProvider provider() + 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; } } |