How would I define a new type of java.nio.channels.SelectableChannel
(say for serial ports)?
views:
206answers:
2You probably want to extend java.nio.channels.spi.AbstractSelectableChannel
to create the implementation that you need. If you are asking for something different, you need to give a more detailed question. The JDK source code is downloadable under a few different licenses, depending on what version you are downloading. You have the option of viewing the JDK implementations (java.nio.channels.Channel
, java.nio.channels.SocketChannel
, etc...) to fully understand what you need to implement. If you do this, however, be careful not to copy code from the JDK source unless you can obey the license of the source code that you downloaded.
The book Java NIO may help you.
My understanding is that the java implementation is based on the unix select()
c function (I seem to remember that the Windows implementation was slightly different)
Depending on OS (and JVM args!) different native OS functions are called, but what they have in common is that it's native code - the basic functionality is not implemented in Java.
If you want to make a lib that access the select()
(or similar) of the underlying OS (which does indeed rely on filehandles), I think you are pretty much forced to use JNI. I don't believe there are any ways around it.
The Selector/SelectableChannel in Java is really an anemic subset of what select()
can do.