summaryrefslogtreecommitdiffstats
path: root/libjava/java/nio/channels/spi/AbstractSelectableChannel.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/nio/channels/spi/AbstractSelectableChannel.java')
-rw-r--r--libjava/java/nio/channels/spi/AbstractSelectableChannel.java126
1 files changed, 81 insertions, 45 deletions
diff --git a/libjava/java/nio/channels/spi/AbstractSelectableChannel.java b/libjava/java/nio/channels/spi/AbstractSelectableChannel.java
index a07485df85f..ccc48c93c95 100644
--- a/libjava/java/nio/channels/spi/AbstractSelectableChannel.java
+++ b/libjava/java/nio/channels/spi/AbstractSelectableChannel.java
@@ -43,9 +43,9 @@ import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.LinkedList;
-import java.util.List;
import java.util.ListIterator;
+
public abstract class AbstractSelectableChannel extends SelectableChannel
{
private boolean blocking = true;
@@ -55,8 +55,10 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
/**
* Initializes the channel
+ *
+ * @param provider the provider that created this channel
*/
- protected AbstractSelectableChannel (SelectorProvider provider)
+ protected AbstractSelectableChannel(SelectorProvider provider)
{
this.provider = provider;
}
@@ -64,27 +66,35 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
/**
* Retrieves the object upon which the configureBlocking and register
* methods synchronize.
+ *
+ * @return the blocking lock
*/
- public final Object blockingLock ()
+ public final Object blockingLock()
{
return LOCK;
}
-
+
/**
* Adjusts this channel's blocking mode.
+ *
+ * @param blocking true if blocking should be enabled, false otherwise
+ *
+ * @return this channel
+ *
+ * @exception IOException If an error occurs
*/
- public final SelectableChannel configureBlocking (boolean blocking)
+ public final SelectableChannel configureBlocking(boolean blocking)
throws IOException
{
synchronized (blockingLock())
{
- if (this.blocking != blocking)
- {
- implConfigureBlocking(blocking);
- this.blocking = blocking;
- }
+ if (this.blocking != blocking)
+ {
+ implConfigureBlocking(blocking);
+ this.blocking = blocking;
+ }
}
-
+
return this;
}
@@ -93,25 +103,34 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
*
* @exception IOException If an error occurs
*/
- protected final void implCloseChannel () throws IOException
+ protected final void implCloseChannel() throws IOException
{
- implCloseSelectableChannel ();
+ implCloseSelectableChannel();
}
/**
* Closes this selectable channel.
+ *
+ * @exception IOException If an error occurs
*/
- protected abstract void implCloseSelectableChannel () throws IOException;
-
+ protected abstract void implCloseSelectableChannel()
+ throws IOException;
+
/**
* Adjusts this channel's blocking mode.
+ *
+ * @param blocking true if blocking should be enabled, false otherwise
+ *
+ * @exception IOException If an error occurs
*/
- protected abstract void implConfigureBlocking (boolean block)
+ protected abstract void implConfigureBlocking(boolean blocking)
throws IOException;
/**
* Tells whether or not every I/O operation on this channel will block
* until it completes.
+ *
+ * @return true of this channel is blocking, false otherwise
*/
public final boolean isBlocking()
{
@@ -121,87 +140,104 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
/**
* Tells whether or not this channel is currently registered with
* any selectors.
+ *
+ * @return true if this channel is registered, false otherwise
*/
public final boolean isRegistered()
{
- return !keys.isEmpty();
+ return ! keys.isEmpty();
}
/**
* Retrieves the key representing the channel's registration with the
* given selector.
+ *
+ * @param selector the selector to get a selection key for
+ *
+ * @return the selection key this channel is registered with
*/
public final SelectionKey keyFor(Selector selector)
{
if (! isOpen())
return null;
-
+
try
{
- synchronized(blockingLock())
+ synchronized (blockingLock())
{
- return locate (selector);
+ return locate(selector);
}
}
catch (Exception e)
{
- return null;
+ return null;
}
}
/**
* Returns the provider that created this channel.
+ *
+ * @return the selector provider that created this channel
*/
- public final SelectorProvider provider ()
+ public final SelectorProvider provider()
{
return provider;
}
- private SelectionKey locate (Selector selector)
+ private SelectionKey locate(Selector selector)
{
- ListIterator it = keys.listIterator ();
-
- while (it.hasNext ())
+ ListIterator it = keys.listIterator();
+
+ while (it.hasNext())
{
- SelectionKey key = (SelectionKey) it.next();
-
- if (key.selector() == selector)
- return key;
+ SelectionKey key = (SelectionKey) it.next();
+
+ if (key.selector() == selector)
+ return key;
}
-
+
return null;
}
/**
* Registers this channel with the given selector, returning a selection key.
*
+ * @param selin the seletor to use
+ * @param ops the interested operations
+ * @param att an attachment for the returned selection key
+ *
+ * @return the registered selection key
+ *
* @exception ClosedChannelException If the channel is already closed.
*/
- public final SelectionKey register (Selector selin, int ops, Object att)
+ public final SelectionKey register(Selector selin, int ops, Object att)
throws ClosedChannelException
{
- if (!isOpen ())
+ if (! isOpen())
throw new ClosedChannelException();
+ if ((ops & ~validOps()) != 0)
+ throw new IllegalArgumentException();
+
SelectionKey key = null;
AbstractSelector selector = (AbstractSelector) selin;
synchronized (blockingLock())
{
- key = locate (selector);
+ key = locate(selector);
- if (key != null)
- {
+ if (key != null)
+ {
if (att != null)
- key.attach (att);
- }
- else
- {
- key = selector.register (this, ops, att);
-
- if (key != null)
- addSelectionKey (key);
- }
+ key.attach(att);
+ }
+ else
+ {
+ key = selector.register(this, ops, att);
+
+ if (key != null)
+ addSelectionKey(key);
+ }
}
return key;
OpenPOWER on IntegriCloud