As you observed, I use SocketChannel, and I believe one should be able to get away with using SelectableChannel, in order to accomodate both DatagramChannel and SocketChannel. If you do this refactoring, I'd be immensely grateful and can roll it in.
I am happy to do that. But whilst testing to implement MulticastSocket
function, I encountered a problem.
At receiving side (e.g. MulticastSocket.receive()), it keeps throwing
message e.g.
java.nio.channels.IllegalSelectorException
at sun.nio.ch.SelectorImpl.register(SelectorImpl.java:111)
at
java.nio.channels.spi.AbstractSelectableChannel.register(AbstractSelectable Channel.java:
180)
at
java.nio.channels.SelectableChannel.register(SelectableChannel.java:
254)
at kilim.nio.NioSelectorScheduler
$RegistrationTask.execute(NioSelectorScheduler.java:324)
at kilim.Task._runExecute(Task.java:432)
at kilim.nio.NioSelectorScheduler
$SelectorThread.run(NioSelectorScheduler.java:198)
when receiving packet from the client.
After checking the code, looks like it is issued by SelectorImpl.java
in which
protected final SelectionKey register(AbstractSelectableChannel ch,
int ops,
Object attachment)
{
if (!(ch instanceof SelChImpl))
throw new IllegalSelectorException();
...
}
it checks the channel passed in required to implement SelChImpl.
Unfortunately, SelChImpl is not public, resulting
in the compiler complains `... <subclass that extends > ... cannot
access its superinterface sun.nio.ch.SelChImpl,'
if trying to implements SelChImpl class.
This message comes from my code (PollSelectorProvider) where to open
the Multicast Socket function, e.g.
public static AbstractSelectableChannel open(int port) throws
IOException{
return new AbstractMulticastSocket(new
sun.nio.ch.PollSelectorProvider(), port);
}
However, I think because I am not familiar with this I do not have any
good idea on how to get around it. Is there any chance
to provide any hint or advice? Or point me to where there may contain
related resource/ doc?
> As you observed, I use SocketChannel, and I believe one should be able
> to get away with using SelectableChannel, in order to accomodate both
> DatagramChannel and SocketChannel. If you do this refactoring, I'd be
> immensely grateful and can roll it in.
The basic issue is that you need to receive multicast sockets and work with Kilim tasks. Most likely you have just the single multicast socket, one reasonable alternative -- at least for now -- is to have a separate thread blocked on that multicast socket? Whenever you receive a packet, put it in some task's mailbox and return to blocking on that socket.
> I am happy to do that. But whilst testing to implement MulticastSocket > function, I encountered a problem.
> At receiving side (e.g. MulticastSocket.receive()), it keeps throwing > message e.g.
> java.nio.channels.IllegalSelectorException > at sun.nio.ch.SelectorImpl.register(SelectorImpl.java:111) > at > java > .nio > .channels > .spi > .AbstractSelectableChannel.register(AbstractSelectableChannel.java: > 180) > at > java.nio.channels.SelectableChannel.register(SelectableChannel.java: > 254) > at kilim.nio.NioSelectorScheduler > $RegistrationTask.execute(NioSelectorScheduler.java:324) > at kilim.Task._runExecute(Task.java:432) > at kilim.nio.NioSelectorScheduler > $SelectorThread.run(NioSelectorScheduler.java:198)
> when receiving packet from the client.
> After checking the code, looks like it is issued by SelectorImpl.java > in which
> protected final SelectionKey register(AbstractSelectableChannel ch, > int ops, > Object attachment) > { > if (!(ch instanceof SelChImpl)) > throw new IllegalSelectorException(); > ... > }
> it checks the channel passed in required to implement SelChImpl. > Unfortunately, SelChImpl is not public, resulting > in the compiler complains `... <subclass that extends > ... cannot > access its superinterface sun.nio.ch.SelChImpl,' > if trying to implements SelChImpl class.
> This message comes from my code (PollSelectorProvider) where to open > the Multicast Socket function, e.g.
> public static AbstractSelectableChannel open(int port) throws > IOException{ > return new AbstractMulticastSocket(new > sun.nio.ch.PollSelectorProvider(), port); > }
> However, I think because I am not familiar with this I do not have any > good idea on how to get around it. Is there any chance > to provide any hint or advice? Or point me to where there may contain > related resource/ doc?
> On Sep 14, 4:03 am, Sriram Srinivasan <ki...@malhar.net> wrote: >> On Sep 13, 2010, at 2:00 AM, newbie wrote:
>>> Is multicast supported in kilim?
>> No, there is no multicast support in kilim/nio.
>> As you observed, I use SocketChannel, and I believe one should be >> able >> to get away with using SelectableChannel, in order to accomodate both >> DatagramChannel and SocketChannel. If you do this refactoring, I'd >> be >> immensely grateful and can roll it in.
I switch to use a separate Task receiving incoming packet and
basically looks like it works. But an message is thrown once the
socket received a packet saying
java.net.SocketException: Address already in use
at java.net.PlainDatagramSocketImpl.join(Native Method)
at java.net.PlainDatagramSocketImpl.join(PlainDatagramSocketImpl.java:
172)
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:277)
at
kilim.nio.MulticastSocketWrapper.joinGroup(MulticastSocketWrapper.java:
61)
at kilim.nio.NioSelectorScheduler
$MulticastListenTask.execute(NioSelectorScheduler.java:245)
at kilim.Task._runExecute(Task.java:432)
at kilim.nio.NioSelectorScheduler
$SelectorThread.run(NioSelectorScheduler.java:198)
And this cause the server would only receive packet once only.
My guess is because RegistrationTask registers channel with a
SlectionKey returned; therefore, the SelectorThread can select channel
with different key. Unfortunately,
the separate task uses MulticastSocket instead of Channel instance so
the register() function in RegistrationTask won't actually perform
register procedure as channel
passed in is null.
I notice that seems can be modified by customizing
SelectorImpl.register() function, but again a similar issue as
previous one would happen again (The default implementation
can not be reused if I am correct). Before doing this, I would like to
double check if this is the right direction (because some more detail
I may not be aware of, though I've dug a
bit into the source), or there is an alternative way to get around
this issue.
> The basic issue is that you need to receive multicast sockets and work
> with Kilim tasks. Most likely you have just the single multicast
> socket, one reasonable alternative -- at least for now -- is to have
> a separate thread blocked on that multicast socket? Whenever you
> receive a packet, put it in some task's mailbox and return to blocking
> on that socket.
> --sriram.
> On Sep 21, 2010, at 3:40 AM, newbie wrote:
> > Hi Sriram,
> > I am happy to do that. But whilst testing to implement MulticastSocket
> > function, I encountered a problem.
> > At receiving side (e.g. MulticastSocket.receive()), it keeps throwing
> > message e.g.
> > java.nio.channels.IllegalSelectorException
> > at sun.nio.ch.SelectorImpl.register(SelectorImpl.java:111)
> > at
> > java
> > .nio
> > .channels
> > .spi
> > .AbstractSelectableChannel.register(AbstractSelectableChannel.java:
> > 180)
> > at
> > java.nio.channels.SelectableChannel.register(SelectableChannel.java:
> > 254)
> > at kilim.nio.NioSelectorScheduler
> > $RegistrationTask.execute(NioSelectorScheduler.java:324)
> > at kilim.Task._runExecute(Task.java:432)
> > at kilim.nio.NioSelectorScheduler
> > $SelectorThread.run(NioSelectorScheduler.java:198)
> > when receiving packet from the client.
> > After checking the code, looks like it is issued by SelectorImpl.java
> > in which
> > protected final SelectionKey register(AbstractSelectableChannel ch,
> > int ops,
> > Object attachment)
> > {
> > if (!(ch instanceof SelChImpl))
> > throw new IllegalSelectorException();
> > ...
> > }
> > it checks the channel passed in required to implement SelChImpl.
> > Unfortunately, SelChImpl is not public, resulting
> > in the compiler complains `... <subclass that extends > ... cannot
> > access its superinterface sun.nio.ch.SelChImpl,'
> > if trying to implements SelChImpl class.
> > This message comes from my code (PollSelectorProvider) where to open
> > the Multicast Socket function, e.g.
> > However, I think because I am not familiar with this I do not have any
> > good idea on how to get around it. Is there any chance
> > to provide any hint or advice? Or point me to where there may contain
> > related resource/ doc?
> > On Sep 14, 4:03 am, Sriram Srinivasan <ki...@malhar.net> wrote:
> >> On Sep 13, 2010, at 2:00 AM, newbie wrote:
> >>> Is multicast supported in kilim?
> >> No, there is no multicast support in kilim/nio.
> >> As you observed, I use SocketChannel, and I believe one should be
> >> able
> >> to get away with using SelectableChannel, in order to accomodate both
> >> DatagramChannel and SocketChannel. If you do this refactoring, I'd
> >> be
> >> immensely grateful and can roll it in.
From a _very_ cursory look at the source, I'm puzzled by one conspicuous omission: there is no import of DatagramChannel. Perhaps that is the key to the solution.
I just submitted a patch through github, but not very sure if that's
the formal way (I can't find something e.g. issue tracking to create
an issue and add patch as attachment.)
Please let me know if ant issue relates.
Many thanks.
On 9月23日, 下午10時06分, Sriram Srinivasan <ki...@malhar.net> wrote:
> From a _very_ cursory look at the source, I'm puzzled by one
> conspicuous omission: there is no import of DatagramChannel.
> Perhaps that is the key to the solution.
> See also Alan Bateman's blog entry on this topic:
> I just submitted a patch through github, but not very sure if that's > the formal way (I can't find something e.g. issue tracking to create > an issue and add patch as attachment.)