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, 9 Oct 2003 19:38:22 +0200
- Subject: FYI: Patch: java.nio.channels.spi
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I commited the attached patch to improve java.nio.
Michael
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQE/hZ0UWSOgCCdjSDsRApaIAKCQMvPjyTquET3MBdo5qZwrR7sINgCfYnsa
Ww1AlOqaaJXQFheluIPuHms=
=iIre
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2229
diff -u -b -B -r1.2229 ChangeLog
--- ChangeLog 9 Oct 2003 15:20:23 -0000 1.2229
+++ ChangeLog 9 Oct 2003 17:28:05 -0000
@@ -1,5 +1,30 @@
2003-10-09 Michael Koch <konqueror@gmx.de>
+ * java/nio/channels/spi/AbstractSelectableChannel.java
+ (registered): Made private.
+ (blocking): Likewise.
+ (LOCK): Likewise.
+ (provider): Likewise.
+ (keys): Made it a private LinkedList.
+ (AbstractSelectableChannel): Initialize keys.
+ (isRegistered): New implementation.
+ (locate): Rewritten.
+ (register): Rewritten.
+ * java/nio/channels/spi/AbstractSelectionKey.java
+ (ok): Removed.
+ (cancelled): New member variable.
+ (cancel): Rewritten.
+ (isValid): Rewritten.
+ * java/nio/channels/spi/AbstractSelector.java:
+ Some methods moved.
+ (closed): Make private.
+ (provider): Likewise.
+ (cancelledKeys): New member variable.
+ (AbstractSelector): Initialize cancelledKeys.
+ (cancelKey): New method.
+
+2003-10-09 Michael Koch <konqueror@gmx.de>
+
* java/rmi/server/RMIClassLoader.java:
Removed unused imports, little reformatings.
(getClassLoader): New method, implementation was part of old loadCLass
Index: java/nio/channels/spi/AbstractSelectableChannel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/spi/AbstractSelectableChannel.java,v
retrieving revision 1.5
diff -u -b -B -r1.5 AbstractSelectableChannel.java
--- java/nio/channels/spi/AbstractSelectableChannel.java 11 Feb 2003 06:48:53 -0000 1.5
+++ java/nio/channels/spi/AbstractSelectableChannel.java 9 Oct 2003 17:28:05 -0000
@@ -1,5 +1,5 @@
/* AbstractSelectableChannel.java
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -48,11 +48,11 @@
public abstract class AbstractSelectableChannel extends SelectableChannel
{
- int registered;
- boolean blocking = true;
- Object LOCK = new Object ();
- SelectorProvider provider;
- List keys;
+ private int registered;
+ private boolean blocking = true;
+ private Object LOCK = new Object();
+ private SelectorProvider provider;
+ private LinkedList keys;
/**
* Initializes the channel
@@ -60,6 +60,7 @@
protected AbstractSelectableChannel (SelectorProvider provider)
{
this.provider = provider;
+ this.keys = new LinkedList();
}
/**
@@ -122,7 +123,7 @@
*/
public final boolean isRegistered()
{
- return registered > 0;
+ return !keys.isEmpty();
}
/**
@@ -154,28 +155,21 @@
if (keys == null)
return null;
- SelectionKey k = null;
ListIterator it = keys.listIterator ();
while (it.hasNext ())
{
- k = (SelectionKey) it.next ();
- if (k.selector () == selector)
- {
- return k;
- }
+ SelectionKey key = (SelectionKey) it.next();
+
+ if (key.selector() == selector)
+ return key;
}
- return k;
+ return null;
}
private void add (SelectionKey key)
{
- if (keys == null)
- {
- keys = new LinkedList ();
- }
-
keys.add (key);
}
@@ -190,26 +184,26 @@
if (!isOpen ())
throw new ClosedChannelException();
- SelectionKey k = null;
+ SelectionKey key = null;
AbstractSelector selector = (AbstractSelector) selin;
synchronized (LOCK)
{
- k = locate (selector);
+ key = locate (selector);
- if (k != null)
+ if (key != null)
{
- k.attach (att);
+ key.attach (att);
}
else
{
- k = selector.register (this, ops, att);
+ key = selector.register (this, ops, att);
- if (k != null)
- add (k);
+ if (key != null)
+ add (key);
}
}
- return k;
+ return key;
}
}
Index: java/nio/channels/spi/AbstractSelectionKey.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/spi/AbstractSelectionKey.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 AbstractSelectionKey.java
--- java/nio/channels/spi/AbstractSelectionKey.java 13 Nov 2002 13:52:47 -0000 1.2
+++ java/nio/channels/spi/AbstractSelectionKey.java 9 Oct 2003 17:28:05 -0000
@@ -1,5 +1,5 @@
/* AbstractSelectionKey.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -45,7 +45,7 @@
public abstract class AbstractSelectionKey
extends SelectionKey
{
- boolean ok = true;
+ private boolean cancelled = false;
/**
* Initializes the key.
@@ -59,10 +59,12 @@
*/
public final void cancel ()
{
- if (ok)
- selector ().selectedKeys ().add (this);
-
- ok = false;
+ if (isValid())
+ {
+ // FIXME: implement this.
+ //selector().cancelledKeys().add (this);
+ cancelled = true;
+ }
}
/**
@@ -70,6 +72,6 @@
*/
public final boolean isValid ()
{
- return ok;
+ return !cancelled;
}
}
Index: java/nio/channels/spi/AbstractSelector.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/spi/AbstractSelector.java,v
retrieving revision 1.3
diff -u -b -B -r1.3 AbstractSelector.java
--- java/nio/channels/spi/AbstractSelector.java 11 Jun 2003 10:38:58 -0000 1.3
+++ java/nio/channels/spi/AbstractSelector.java 9 Oct 2003 17:28:05 -0000
@@ -1,5 +1,5 @@
/* AbstractSelector.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,11 +42,13 @@
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.Set;
+import java.util.HashSet;
public abstract class AbstractSelector extends Selector
{
- boolean closed = false;
- SelectorProvider provider;
+ private boolean closed = false;
+ private SelectorProvider provider;
+ private HashSet cancelledKeys;
/**
* Initializes the slector.
@@ -54,13 +56,7 @@
protected AbstractSelector (SelectorProvider provider)
{
this.provider = provider;
- }
-
- /**
- * Marks the beginning of an I/O operation that might block indefinitely.
- */
- protected final void begin ()
- {
+ this.cancelledKeys = new HashSet();
}
/**
@@ -73,8 +69,8 @@
if (closed)
return;
+ implCloseSelector();
closed = true;
- implCloseSelector ();
}
/**
@@ -85,11 +81,16 @@
return ! closed;
}
- protected final void deregister (AbstractSelectionKey key)
+ /**
+ * Marks the beginning of an I/O operation that might block indefinitely.
+ */
+ protected final void begin()
{
- cancelledKeys ().remove (key);
}
+ /**
+ * Marks the end of an I/O operation that might block indefinitely.
+ */
protected final void end()
{
}
@@ -101,7 +102,12 @@
protected final Set cancelledKeys()
{
- return null;
+ return cancelledKeys;
+ }
+
+ final void cancelKey (AbstractSelectionKey key)
+ {
+ cancelledKeys.remove (key);
}
/**
@@ -111,4 +117,9 @@
protected abstract SelectionKey register (AbstractSelectableChannel ch,
int ops, Object att);
+
+ protected final void deregister (AbstractSelectionKey key)
+ {
+ // FIXME
+ }
}