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.

From-SVN: r79640
This commit is contained in:
Michael Koch 2004-03-18 21:32:22 +00:00 committed by Michael Koch
parent bdb5db66b1
commit 138f5109c1
4 changed files with 44 additions and 17 deletions

View file

@ -1,3 +1,19 @@
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.
2004-03-18 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE> 2004-03-18 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE>
* gnu/java/nio/channels/natFileChannelPosix.cc (mapImpl): Cast * gnu/java/nio/channels/natFileChannelPosix.cc (mapImpl): Cast

View file

@ -51,7 +51,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
private boolean blocking = true; private boolean blocking = true;
private Object LOCK = new Object(); private Object LOCK = new Object();
private SelectorProvider provider; private SelectorProvider provider;
private LinkedList keys; private LinkedList keys = new LinkedList();
/** /**
* Initializes the channel * Initializes the channel
@ -59,7 +59,6 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
protected AbstractSelectableChannel (SelectorProvider provider) protected AbstractSelectableChannel (SelectorProvider provider)
{ {
this.provider = provider; this.provider = provider;
this.keys = new LinkedList();
} }
/** /**
@ -160,9 +159,6 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
private SelectionKey locate (Selector selector) private SelectionKey locate (Selector selector)
{ {
if (keys == null)
return null;
ListIterator it = keys.listIterator (); ListIterator it = keys.listIterator ();
while (it.hasNext ()) while (it.hasNext ())
@ -176,11 +172,6 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
return null; return null;
} }
private void add (SelectionKey key)
{
keys.add (key);
}
/** /**
* Registers this channel with the given selector, returning a selection key. * Registers this channel with the given selector, returning a selection key.
* *
@ -209,10 +200,21 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
key = selector.register (this, ops, att); key = selector.register (this, ops, att);
if (key != null) if (key != null)
add (key); addSelectionKey (key);
} }
} }
return key; return key;
} }
void addSelectionKey(SelectionKey key)
{
keys.add(key);
}
// This method gets called by AbstractSelector.deregister().
void removeSelectionKey(SelectionKey key)
{
keys.remove(key);
}
} }

View file

@ -1,5 +1,5 @@
/* AbstractSelectionKey.java -- /* 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. This file is part of GNU Classpath.
@ -61,8 +61,7 @@ public abstract class AbstractSelectionKey
{ {
if (isValid()) if (isValid())
{ {
// FIXME: implement this. ((AbstractSelector) selector()).cancelKey(this);
//selector().cancelledKeys().add (this);
cancelled = true; cancelled = true;
} }
} }

View file

@ -1,5 +1,5 @@
/* AbstractSelector.java -- /* 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. This file is part of GNU Classpath.
@ -96,11 +96,17 @@ public abstract class AbstractSelector extends Selector
{ {
} }
/**
* Returns the provider for this selector object.
*/
public final SelectorProvider provider () public final SelectorProvider provider ()
{ {
return provider; return provider;
} }
/**
* Returns the cancelled keys set.
*/
protected final Set cancelledKeys() protected final Set cancelledKeys()
{ {
if (!isOpen()) if (!isOpen())
@ -109,11 +115,15 @@ public abstract class AbstractSelector extends Selector
return cancelledKeys; return cancelledKeys;
} }
/**
* Cancels a selection key.
*/
// This method is only called by AbstractSelectionKey.cancel().
final void cancelKey (AbstractSelectionKey key) final void cancelKey (AbstractSelectionKey key)
{ {
synchronized (cancelledKeys) synchronized (cancelledKeys)
{ {
cancelledKeys.remove(key); cancelledKeys.add(key);
} }
} }
@ -127,6 +137,6 @@ public abstract class AbstractSelector extends Selector
protected final void deregister (AbstractSelectionKey key) protected final void deregister (AbstractSelectionKey key)
{ {
// FIXME ((AbstractSelectableChannel) key.channel()).removeSelectionKey(key);
} }
} }