This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
FYI: Patch: java.nio.channels.spi.*
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Thu, 18 Mar 2004 22:33:01 +0100
- Subject: FYI: Patch: java.nio.channels.spi.*
Hi list,
I commited the attached patch to implement cancelling of selection keys
correctly.
Michael
2004-03-18 Michael Koch <konqueror@gmx.de>
* java/nio/channels/spi/AbstractSelectableChannel.java
(keys): Initialize at declaration.
(locate): keys cant be null.
(add): Removed.
(addSelectionKey): New method.
(removeSelectionKey): New method.
* java/nio/channels/spi/AbstractSelectionKey.java
(cancel): Call AbstractSelector.cancelKey(SelectionKey key).
* java/nio/channels/spi/AbstractSelector.java
(provider): Javadoc added.
(cancelledKeys): Javadoc added.
(cancelKey): Javadoc added, add key to cancelledKeys.
(deregister): Implemented.
Index: java/nio/channels/spi/AbstractSelectableChannel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/spi/AbstractSelectableChannel.java,v
retrieving revision 1.9
diff -u -b -B -r1.9 AbstractSelectableChannel.java
--- java/nio/channels/spi/AbstractSelectableChannel.java 26 Feb 2004 19:45:51 -0000 1.9
+++ java/nio/channels/spi/AbstractSelectableChannel.java 18 Mar 2004 21:31:20 -0000
@@ -51,7 +51,7 @@
private boolean blocking = true;
private Object LOCK = new Object();
private SelectorProvider provider;
- private LinkedList keys;
+ private LinkedList keys = new LinkedList();
/**
* Initializes the channel
@@ -59,7 +59,6 @@
protected AbstractSelectableChannel (SelectorProvider provider)
{
this.provider = provider;
- this.keys = new LinkedList();
}
/**
@@ -160,9 +159,6 @@
private SelectionKey locate (Selector selector)
{
- if (keys == null)
- return null;
-
ListIterator it = keys.listIterator ();
while (it.hasNext ())
@@ -176,11 +172,6 @@
return null;
}
- private void add (SelectionKey key)
- {
- keys.add (key);
- }
-
/**
* Registers this channel with the given selector, returning a selection key.
*
@@ -209,10 +200,21 @@
key = selector.register (this, ops, att);
if (key != null)
- add (key);
+ addSelectionKey (key);
}
}
return key;
+ }
+
+ void addSelectionKey(SelectionKey key)
+ {
+ keys.add(key);
+ }
+
+ // This method gets called by AbstractSelector.deregister().
+ void removeSelectionKey(SelectionKey key)
+ {
+ keys.remove(key);
}
}
Index: java/nio/channels/spi/AbstractSelectionKey.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/spi/AbstractSelectionKey.java,v
retrieving revision 1.3
diff -u -b -B -r1.3 AbstractSelectionKey.java
--- java/nio/channels/spi/AbstractSelectionKey.java 9 Oct 2003 17:34:10 -0000 1.3
+++ java/nio/channels/spi/AbstractSelectionKey.java 18 Mar 2004 21:31:20 -0000
@@ -1,5 +1,5 @@
/* AbstractSelectionKey.java --
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -61,8 +61,7 @@
{
if (isValid())
{
- // FIXME: implement this.
- //selector().cancelledKeys().add (this);
+ ((AbstractSelector) selector()).cancelKey(this);
cancelled = true;
}
}
Index: java/nio/channels/spi/AbstractSelector.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/spi/AbstractSelector.java,v
retrieving revision 1.5
diff -u -b -B -r1.5 AbstractSelector.java
--- java/nio/channels/spi/AbstractSelector.java 20 Dec 2003 15:33:24 -0000 1.5
+++ java/nio/channels/spi/AbstractSelector.java 18 Mar 2004 21:31:20 -0000
@@ -1,5 +1,5 @@
/* AbstractSelector.java --
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -96,11 +96,17 @@
{
}
+ /**
+ * Returns the provider for this selector object.
+ */
public final SelectorProvider provider ()
{
return provider;
}
+ /**
+ * Returns the cancelled keys set.
+ */
protected final Set cancelledKeys()
{
if (!isOpen())
@@ -109,11 +115,15 @@
return cancelledKeys;
}
+ /**
+ * Cancels a selection key.
+ */
+ // This method is only called by AbstractSelectionKey.cancel().
final void cancelKey (AbstractSelectionKey key)
{
synchronized (cancelledKeys)
{
- cancelledKeys.remove(key);
+ cancelledKeys.add(key);
}
}
@@ -127,6 +137,6 @@
protected final void deregister (AbstractSelectionKey key)
{
- // FIXME
+ ((AbstractSelectableChannel) key.channel()).removeSelectionKey(key);
}
}