April 02, 2005

java.nio.channels.FileChannel is not selectable?

Java

Maybe I'm missing something, but I just can't figure this out. With the Java NIO it appears there is no way you can use selectors to asynchronously listen for new data to read on stdin, or any other files for that matter!

I want to write a simple program that opens a serial device file (/dev/ttyS0 for example) on Unix (Linux or MacOS X), and listens to events on the associated file descriptor. These events are bytes written by a physical device connected on serial port. I also want the application to listen on stdin, for characters I may type to change the internal state of the application.

With the Unix select() you can do this easily by passing the two file descriptors to the system call. The Java API however chose to hide this ability, and you can only do selects on sockets. This is really stupid and plain wrong if you ask me, as it basically means I need to write the multithreaded code to handle this simple application.

How could the bunch of Unix heads at Sun that designed the NIO API allow such a thing to happen? Somebody tell me I'm wrong, please!

Update (April 5, 2005): Java is just the wrong language for my application. I've ported everything to Python, and implemented the above functionality in just few lines. Sometimes too many abstractions are just wrong, as in this case. Python exposes everything I need, including device characteristics (serial line speed, parity etc.). The perfect tool for the job!

Posted by ovidiu at April 02, 2005 10:38 PM |
Comments

servus ovidiu,
am obosit sa caut un link de contact sau sa incerc sa-mi dau seama daca permiti comentarii pe romaneste la tine pe blog, asa ca-mi dau drumu aici. poti sa-l stergi (sper:-)) daca nu-ti place.

tre sa-ti marturisesc ca am mai incercat de cateva ori sa-ti citesc blogul pana acum, dar de fiecare data era sa adorm cu capul pe tastatura, si m-am lasat pagubas. stilul tau sec pe engleza si cateva posturi de inalta specialitate peste care am nimerit de fiecare data, m-au gonit.

ai crescut brusc in ochii mei aseara cand am descoperit disclaimerul din footer si am intrebat in stanga si in dreapta si mi s-a adeverit ca lucrezi la google. sunt fan google si ma inraiesc pe zi ce trece. stiu ca n-ar trebui sa te judec dupa asta, dar sunt om, nu algoritm.

doua rugaminti as avea la tine (doar nu credeai ca-ti scriu doar ca sa te felicit ca lucrezi la google):

1. nu repari si tu linkul la picture gallery? sau ce-o fi defect acolo. ca daca imi zici ca ai Canon de ala fainu si nu imi arati nici o poza, asta e tortura curata.
2. nu repari si tu linku la povestea aia cu instalatul agentului KGB, pardon: SSH, pe Windows XP ? ca dupa ce m-am auto-torturat incercand sa instalez unul tare curios is sa citesc ce are de zis conationalul meu care lucreaza la gugăl despre subiect.

mersi.
octi.

Posted by: octiliniu on April 5, 2005 02:28 AM

Servus Octi, vrei SSH in Windows? Ai venit la locul potrivit. ;-) Asta depinde daca te intorci aici, bineinteles.

Cauta pe gugăl la Putty, download si da-i drumul. Cel mai simplu client de SSH in Windows.

Hai noroc. ciao. edi.

Posted by: Eduard on April 7, 2005 12:52 PM

ma intorc, ma intorc, cum sa nu ma intorc, dar nu ma asteptam sa ma intorc asa repede, si tocmai cu autobuzul ăsta:
http://images.google.com/images?q=canon%2020d !!! hm. toate drumurile duc la Roma. :-)

Posted by: octiliniu on April 7, 2005 06:25 PM
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?



 
Copyright © 2002-2016 Ovidiu Predescu.