Commit 4e3cb200 by Michael Koch Committed by Michael Koch

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.

From-SVN: r72275
parent 93d04686
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 Tom Tromey <tromey@redhat.com> 2003-10-09 Tom Tromey <tromey@redhat.com>
* java/lang/ClassLoader.java (setSigners): Implemented. * java/lang/ClassLoader.java (setSigners): Implemented.
......
/* AbstractSelectableChannel.java /* AbstractSelectableChannel.java
Copyright (C) 2002 Free Software Foundation, Inc. Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -48,11 +48,11 @@ import java.util.ListIterator; ...@@ -48,11 +48,11 @@ import java.util.ListIterator;
public abstract class AbstractSelectableChannel extends SelectableChannel public abstract class AbstractSelectableChannel extends SelectableChannel
{ {
int registered; private int registered;
boolean blocking = true; private boolean blocking = true;
Object LOCK = new Object (); private Object LOCK = new Object();
SelectorProvider provider; private SelectorProvider provider;
List keys; private LinkedList keys;
/** /**
* Initializes the channel * Initializes the channel
...@@ -60,6 +60,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -60,6 +60,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
protected AbstractSelectableChannel (SelectorProvider provider) protected AbstractSelectableChannel (SelectorProvider provider)
{ {
this.provider = provider; this.provider = provider;
this.keys = new LinkedList();
} }
/** /**
...@@ -122,7 +123,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -122,7 +123,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
*/ */
public final boolean isRegistered() public final boolean isRegistered()
{ {
return registered > 0; return !keys.isEmpty();
} }
/** /**
...@@ -154,28 +155,21 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -154,28 +155,21 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
if (keys == null) if (keys == null)
return null; return null;
SelectionKey k = null;
ListIterator it = keys.listIterator (); ListIterator it = keys.listIterator ();
while (it.hasNext ()) while (it.hasNext ())
{ {
k = (SelectionKey) it.next (); SelectionKey key = (SelectionKey) it.next();
if (k.selector () == selector)
{ if (key.selector() == selector)
return k; return key;
}
} }
return k; return null;
} }
private void add (SelectionKey key) private void add (SelectionKey key)
{ {
if (keys == null)
{
keys = new LinkedList ();
}
keys.add (key); keys.add (key);
} }
...@@ -190,26 +184,26 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -190,26 +184,26 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
if (!isOpen ()) if (!isOpen ())
throw new ClosedChannelException(); throw new ClosedChannelException();
SelectionKey k = null; SelectionKey key = null;
AbstractSelector selector = (AbstractSelector) selin; AbstractSelector selector = (AbstractSelector) selin;
synchronized (LOCK) synchronized (LOCK)
{ {
k = locate (selector); key = locate (selector);
if (k != null) if (key != null)
{ {
k.attach (att); key.attach (att);
} }
else else
{ {
k = selector.register (this, ops, att); key = selector.register (this, ops, att);
if (k != null) if (key != null)
add (k); add (key);
} }
} }
return k; return key;
} }
} }
/* AbstractSelectionKey.java -- /* AbstractSelectionKey.java --
Copyright (C) 2002 Free Software Foundation, Inc. Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -45,7 +45,7 @@ import java.nio.channels.SelectionKey; ...@@ -45,7 +45,7 @@ import java.nio.channels.SelectionKey;
public abstract class AbstractSelectionKey public abstract class AbstractSelectionKey
extends SelectionKey extends SelectionKey
{ {
boolean ok = true; private boolean cancelled = false;
/** /**
* Initializes the key. * Initializes the key.
...@@ -59,10 +59,12 @@ public abstract class AbstractSelectionKey ...@@ -59,10 +59,12 @@ public abstract class AbstractSelectionKey
*/ */
public final void cancel () public final void cancel ()
{ {
if (ok) if (isValid())
selector ().selectedKeys ().add (this); {
// FIXME: implement this.
ok = false; //selector().cancelledKeys().add (this);
cancelled = true;
}
} }
/** /**
...@@ -70,6 +72,6 @@ public abstract class AbstractSelectionKey ...@@ -70,6 +72,6 @@ public abstract class AbstractSelectionKey
*/ */
public final boolean isValid () public final boolean isValid ()
{ {
return ok; return !cancelled;
} }
} }
/* AbstractSelector.java -- /* AbstractSelector.java --
Copyright (C) 2002 Free Software Foundation, Inc. Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -42,11 +42,13 @@ import java.io.IOException; ...@@ -42,11 +42,13 @@ 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.Set; import java.util.Set;
import java.util.HashSet;
public abstract class AbstractSelector extends Selector public abstract class AbstractSelector extends Selector
{ {
boolean closed = false; private boolean closed = false;
SelectorProvider provider; private SelectorProvider provider;
private HashSet cancelledKeys;
/** /**
* Initializes the slector. * Initializes the slector.
...@@ -54,16 +56,10 @@ public abstract class AbstractSelector extends Selector ...@@ -54,16 +56,10 @@ public abstract class AbstractSelector extends Selector
protected AbstractSelector (SelectorProvider provider) protected AbstractSelector (SelectorProvider provider)
{ {
this.provider = provider; this.provider = provider;
this.cancelledKeys = new HashSet();
} }
/** /**
* Marks the beginning of an I/O operation that might block indefinitely.
*/
protected final void begin ()
{
}
/**
* Closes the channel. * Closes the channel.
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
...@@ -73,8 +69,8 @@ public abstract class AbstractSelector extends Selector ...@@ -73,8 +69,8 @@ public abstract class AbstractSelector extends Selector
if (closed) if (closed)
return; return;
implCloseSelector();
closed = true; closed = true;
implCloseSelector ();
} }
/** /**
...@@ -85,11 +81,16 @@ public abstract class AbstractSelector extends Selector ...@@ -85,11 +81,16 @@ public abstract class AbstractSelector extends Selector
return ! closed; 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() protected final void end()
{ {
} }
...@@ -101,7 +102,12 @@ public abstract class AbstractSelector extends Selector ...@@ -101,7 +102,12 @@ public abstract class AbstractSelector extends Selector
protected final Set cancelledKeys() protected final Set cancelledKeys()
{ {
return null; return cancelledKeys;
}
final void cancelKey (AbstractSelectionKey key)
{
cancelledKeys.remove (key);
} }
/** /**
...@@ -111,4 +117,9 @@ public abstract class AbstractSelector extends Selector ...@@ -111,4 +117,9 @@ public abstract class AbstractSelector extends Selector
protected abstract SelectionKey register (AbstractSelectableChannel ch, protected abstract SelectionKey register (AbstractSelectableChannel ch,
int ops, Object att); int ops, Object att);
protected final void deregister (AbstractSelectionKey key)
{
// FIXME
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment