Empyreus / lanterna

Automatically exported from code.google.com/p/lanterna
GNU Lesser General Public License v3.0
0 stars 0 forks source link

GUIScreen event loop can not be externally cancelled #113

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have been wondering about this problem a bit...

I have Lanterna UI served over a network connection and if the client dies / 
network interrupted / disconnects uncleanly the server UI thread is never freed.

GUIScreen.doEventLoop() can only be exited by user action.
Thread.interupt() is eaten and Throwables are caught.
screen.readInput() can not differentiate between no input pending and input 
stream is closed.
There are no obvious options.

Suggestions:
- GUIScreen.doEventLoop() needs to exit when the InputStream to the terminal is 
closed (currently InputDecoder.getNextCharacter() returns null on EOF, same as 
no input waiting).
- GUIScreen.doEventLoop()'s  "while(true)" should be something like 
"while(!this.disposed)" so that the UI thread can be released from a dead 
client session by calling GUIScreen.dispose().

As a more long term idea, I would love it if GUIScreen (or a subclass there of) 
could be used in a more asynchronous way - doEventLoop() becomes public method 
doEvents() (or similar) that the using application should periodically call.
This way a terminal server does not need to allocate an entire thread to each 
connected client.

Would it be possible for some of the internals of GUIScreen to be changed from 
private to protected visibility?
This way I can easily have a go a prototyping an asynchronous subclass of it.

Alterntivly, if you are ok to accept patches I am happy to have a go at fixing 
some of these.

Thanks for the great lib. :)

Original issue reported on code.google.com by AlexHut...@gmail.com on 10 Jul 2014 at 4:57

GoogleCodeExporter commented 9 years ago
How are you serving the content over the network? Are you using 
TelnetTerminalServer in Lanterna 3 or set up something custom?

Original comment by mab...@gmail.com on 12 Jul 2014 at 3:13

GoogleCodeExporter commented 9 years ago
I've added EOF to both 2.1 and 3, making the GUIScreen quit when it gets one of 
those. Also, I added "swallowExceptions" parameter to GUIScreen constructor so 
you can control whether to swallow exceptions inside the event loop or not. 

To enable GUIScreen to quit on EOF in 2.1, not to break API compatibility, 
you'll need to set system property "com.googlecode.lanterna.input.enable-eof" 
to "true". 3.0 has it on by default.

Original comment by mab...@gmail.com on 12 Jul 2014 at 4:15

GoogleCodeExporter commented 9 years ago
Thanks very much!
And answering the first question for completeness:
I am using Apache Mina sshd to server the UI over a network.
My standalone sample of how to do this: https://github.com/haku/Stein
The ideas from which I am now using the build a terminal UI for a media player 
app: https://github.com/haku/MorriganSshUI

Original comment by AlexHut...@gmail.com on 12 Jul 2014 at 7:34