Andrew Zhang wrote:
Seems strange.
Following test fails against RI.
The spec of SelectableChannel.register() says: "IllegalSelectorExceptoin
-- If this channel was not created by the same provider as the given
selector".
Same instance or same SelectorProvider subclass?
I suggest follow spec for this case. Thanks!
public void test_channel() throws Exception {
SelectorProvider provider = SelectorProvider.provider();
Selector selector = Selector.open();
MockChannel channel = new MockChannel(provider);
channel.configureBlocking(false);
assertSame(channel.provider(), selector.provider());
// test fails here against RI, IllegalSelectorException is thrown
channel.register(selector, SelectionKey.OP_READ);
selector.select();
}
class MockChannel extends SocketChannel {
protected MockChannel(SelectorProvider arg0) {
super(arg0);
}
public Socket socket() {
return null;
}
public boolean isConnected() {
return false;
}
public boolean isConnectionPending() {
return false;
}
public boolean connect(SocketAddress arg0) throws IOException {
return false;
}
public boolean finishConnect() throws IOException {
return false;
}
public int read(ByteBuffer arg0) throws IOException {
return 0;
}
public long read(ByteBuffer[] arg0, int arg1, int arg2) throws
IOException {
return 0;
}
public int write(ByteBuffer arg0) throws IOException {
return 0;
}
public long write(ByteBuffer[] arg0, int arg1, int arg2) throws
IOException {
return 0;
}
protected void implCloseSelectableChannel() throws IOException {
}
protected void implConfigureBlocking(boolean arg0) throws
IOException {
}
}
On 7/27/06, Jimmy, Jing Lv <[EMAIL PROTECTED]> wrote:
Hi:
I find that RI behaves strange in
java.nio.channels.SelectableChannel.register. in NIO, channels and
selector must be created by Provider. The doc reads: (Invoking
register() should throw) "IllegalSelectorException - If this channel was
not created by the same provider as the given selector". To check if the
two providers are the same, Harmony use
"if(selector.provider()==selector.provider)... ", however it seems not
correct.
If we mock a channel extends SelectableChannel, put the same
provider of selector as its provider, and register this channel to
selector, RI fails with a IllegalSelectorException though two providers
are the same. I have no idea if how RI do without checking providers are
the same?
Another thing is that if a selector has no channels register on it,
invoke an operation of select() surely has nothing to do. In this way,
Harmony returns immediately even invoking a block select(), however RI
wait forever there, for nothing. I think Harmony's behavior is logical,
but not compatible with RI. It seems a bug of RI, I suggest keep it as
it is.
--
Best Regards!
Jimmy, Jing Lv
China Software Development Lab, IBM
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Paulex Yang
China Software Development Lab
IBM
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]