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
This commit is contained in:
parent
93d046861d
commit
4e3cb200a5
@ -1,3 +1,28 @@
|
||||
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>
|
||||
|
||||
* java/lang/ClassLoader.java (setSigners): Implemented.
|
||||
|
@ -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 @@ import java.util.ListIterator;
|
||||
|
||||
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 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
|
||||
protected AbstractSelectableChannel (SelectorProvider provider)
|
||||
{
|
||||
this.provider = provider;
|
||||
this.keys = new LinkedList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,7 +123,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
|
||||
*/
|
||||
public final boolean isRegistered()
|
||||
{
|
||||
return registered > 0;
|
||||
return !keys.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,28 +155,21 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
|
||||
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 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ import java.nio.channels.SelectionKey;
|
||||
public abstract class AbstractSelectionKey
|
||||
extends SelectionKey
|
||||
{
|
||||
boolean ok = true;
|
||||
private boolean cancelled = false;
|
||||
|
||||
/**
|
||||
* Initializes the key.
|
||||
@ -59,10 +59,12 @@ public abstract class AbstractSelectionKey
|
||||
*/
|
||||
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 abstract class AbstractSelectionKey
|
||||
*/
|
||||
public final boolean isValid ()
|
||||
{
|
||||
return ok;
|
||||
return !cancelled;
|
||||
}
|
||||
}
|
||||
|
@ -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.io.IOException;
|
||||
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,15 +56,9 @@ public abstract class AbstractSelector extends Selector
|
||||
protected AbstractSelector (SelectorProvider 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.
|
||||
*
|
||||
@ -73,8 +69,8 @@ public abstract class AbstractSelector extends Selector
|
||||
if (closed)
|
||||
return;
|
||||
|
||||
implCloseSelector();
|
||||
closed = true;
|
||||
implCloseSelector ();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,11 +81,16 @@ public abstract class AbstractSelector extends Selector
|
||||
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 @@ public abstract class AbstractSelector extends Selector
|
||||
|
||||
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
|
||||
|
||||
protected abstract SelectionKey register (AbstractSelectableChannel ch,
|
||||
int ops, Object att);
|
||||
|
||||
protected final void deregister (AbstractSelectionKey key)
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user