Looking at Java, Windows Services and hosted Javascript

This weekend I’m roaming a bit afield of my normal haunts.

I’m looking at service hosted JVMs in windows and in particular having such a service interact with the SERVICE_CONTROL_PRESHUTDOWN message. Handling this message allows a service to defer shutdown while handling activities that it needs to complete before the actual shutdown processing begins. I suspect it may also allow that service to call AbortSystemShutdown()  in order to cancel the shutdown.

I’m looking at the Apache Commons Daemon package first as it seem to be common, well regarded and reasonably licensed. At first look it doesn’t seem to support the extended messaging from the host OS but it seems like an interesting starting point.

I was also looking at JNI (initially for access to windows file id information for another sandbox project) and that lead me to jna that seems like an attempt to replicate PInvoke from C#. Seems nicer than JNI as it doesn’t require the hosting code to add in cutom built native assemblies…just call into the appropriate jna code set to load and run native shared libraries. Need to play with this some more.

The final bit here is on somewhat of a tangent…I’m involved in some coding that hosts javascript in a JVM under control of the local java code. I’ve done this stuff from C++ and C# but never yet from java so another bit of technology to dig into. The old version of this technology was Rhino but that seems to have been supplanted by nashorn in java 8 and later.

I’m going to look at the hosting interfaces and capabilities to see what i can do with this. Generally I expect to be able to inject methods into the javascript environment from the hosting environment and then control things outside of javascript by calling into those methods.

I’ll be particularly happy if there is a debugging capability in the hosted javascript environment as my experience with javascript code in C# and C++ has been made more challenging by limitations on transparent debugging into the javascript environment and back out.

Interesting…there is a Java Scripting Programmer’s Guide on the Oracle site…

…and an interesting looking nashorn tutorial

I’ll post more as I get some code wrapped together and then push the code onto github for sharing. As with most sandbox projects I’m aiming more at trying things out than at building pretty code…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.