B4J Question How to correctly exit a Non-UI Application?

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

for my WeatherCubeOne project, currently working on a B4J Non-UI MQTT client to run as a process on a Raspberry Pi. The client will publish messages to the TinkerForge LCD display and the Domoticz Sensors. Got the first prototype up and running well.
MQTT = Great Technology - the solution is so much simpler then the previous - No need for complex JavaObjects / Inline Java / httpjobs as subscribe and publish messages handles the flow of data.
It also enables to build UI clients, like for B4J and B4A with almost the same code.

Question:
How to correctly stop the non-ui client to ensure mqtt is properly closed and settings are updated?

Usage: When rebooting the Pi or killing the process while testing.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Check out my jFileWatcher library. It allows you to watch folders for creations, modifications or deletions and raises events accordingly. When I have non-UI applications that need to close gracefully (saving settings, releasing resources, etc...), I have the application create a DeleteThisFileToExitApp.txt file in File.DirApp and then watch that directory for the deletion of that file. When that file is deleted by the user, it raises a _Deleted event and you can gracefully close your app from within that event sub.

Another option I use when I have a console window open is asynchronous console input via my jColorLogger library. You can set it up so that you can type in "exit" into the console window and then your application will gracefully shut down.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Many thanks both. Have changed the application to ensure data is written when changed.
Noticed the MQTT special topic and used as well.

FYI: Latest developments WeatherCubeOne v2 based on MQTT here.
 
Upvote 0
Top