harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paulex Yang <paulex.y...@gmail.com>
Subject Re: [classlib] imcompatible with RI?
Date Fri, 28 Jul 2006 02:32:46 GMT
Andrew Zhang wrote:
> On 7/27/06, Mikhail Fursov <mike.fursov@gmail.com> wrote:
>>
>> If API says (from the forst message message):
>> "If this channel was not created by the same provider as the given
>> selector"
>> then the way you create the channel but not provider is important.
>> ?
>
>
> Do you mean we should focus on the creator of selector?
>
> In fact,  Selector.open() uses SelectorProvider().provider() to create 
> a new
> selector.
>
> No matter what the logic is, "assertSame(channel.provider(),
> selector.provider());" clearly shows the channel was created by the same
> provider as the selector, right?
> Then the channel can be registered onto the selector. But RI throws
> exception.
IIUC, Mikhail meant how the Selector is created is not the key, but how 
channel is created, i.e., common way of get selectable channel instance 
is SelectorProvider.openXXXX(), so that the SelectorProvider should know 
exactly the implementation class what the channel is, but the 
MockChannel may break the contract.
>
> Am I missing something?
> Thanks!
>
>
> On 7/27/06, Andrew Zhang <zhanghuangzhu@gmail.com> wrote:
>> >
>> > On 7/27/06, Paulex Yang <paulex.yang@gmail.com> wrote:
>> > >
>> > > 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 think it's same instance. As you may notice, I use "assertSame(
>> > channel.provider(), selector.provider());" in the test.
>> >
>> > RI passes this assert statement and fails at channel.register(...)
>> because
>> > of IllegalSelectorException.
>> >
>> > That's why I think RI is illogical in this case.
>> >
>> > Any comments?
>> >
>> > >
>> > > > 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 <firepure@gmail.com> 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:
>> harmony-dev-unsubscribe@incubator.apache.org
>> > > >> For additional commands, e-mail:
>> > harmony-dev-help@incubator.apache.org
>> > > >>
>> > > >>
>> > > >
>> > > >
>> > >
>> > >
>> > > --
>> > > Paulex Yang
>> > > China Software Development Lab
>> > > IBM
>> > >
>> > >
>> > >
>> > > 
>> ---------------------------------------------------------------------
>> > > Terms of use : http://incubator.apache.org/harmony/mailing.html
>> > > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
>> > > For additional commands, e-mail: 
>> harmony-dev-help@incubator.apache.org
>> > >
>> > >
>> >
>> >
>> > --
>> > Andrew Zhang
>> > China Software Development Lab, IBM
>> >
>> >
>>
>>
>> -- 
>> Mikhail Fursov
>>
>>
>
>


-- 
Paulex Yang
China Software Development Lab
IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message