{"id":1964,"date":"2018-04-20T15:32:48","date_gmt":"2018-04-20T19:32:48","guid":{"rendered":"http:\/\/ninecrows.com\/career\/?p=1964"},"modified":"2018-04-27T14:12:24","modified_gmt":"2018-04-27T18:12:24","slug":"looking-at-java-windows-services-and-hosted-javascript","status":"publish","type":"post","link":"https:\/\/ninecrows.com\/career\/2018\/04\/20\/looking-at-java-windows-services-and-hosted-javascript\/","title":{"rendered":"Looking at Java, Windows Services and hosted Javascript"},"content":{"rendered":"<p>This weekend I&#8217;m roaming a bit afield of my normal haunts.<\/p>\n<p>I&#8217;m looking at service hosted JVMs in windows and in particular having such a service interact with the\u00a0<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms685961(v=vs.85).aspx\">SERVICE_CONTROL_PRESHUTDOWN<\/a> 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 <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa376630(v=vs.85).aspx\">AbortSystemShutdown()<\/a>\u00a0 in order to cancel the shutdown.<\/p>\n<p>I&#8217;m looking at the <a href=\"http:\/\/commons.apache.org\/proper\/commons-daemon\/faq.html\">Apache Commons Daemon<\/a> package first as it seem to be common, well regarded and reasonably licensed. At first look it doesn&#8217;t seem to support the extended messaging from the host OS but it seems like an interesting starting point.<!--more--><\/p>\n<p>I was also looking at <a href=\"https:\/\/en.wikipedia.org\/wiki\/Java_Native_Interface\">JNI<\/a> (initially for access to windows file id information for another sandbox project) and that lead me to <a href=\"https:\/\/github.com\/java-native-access\/jna\">jna<\/a> that seems like an attempt to replicate PInvoke from C#. Seems nicer than JNI as it doesn&#8217;t require the hosting code to add in cutom built native assemblies&#8230;just call into the appropriate jna code set to load and run native shared libraries. Need to play with this some more.<\/p>\n<p>The final bit here is on somewhat of a tangent&#8230;I&#8217;m involved in some coding that hosts javascript in a JVM under control of the local java code. I&#8217;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 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Rhino_(JavaScript_engine)\">Rhino<\/a> but that seems to have been supplanted by <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/guides\/scripting\/nashorn\/toc.html\">nashorn<\/a> in java 8 and later.<\/p>\n<p>I&#8217;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.<\/p>\n<p>I&#8217;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.<\/p>\n<p>Interesting&#8230;there is a <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/guides\/scripting\/prog_guide\/index.html\">Java Scripting Programmer&#8217;s Guide<\/a> on the Oracle site&#8230;<\/p>\n<p>&#8230;and an interesting looking <a href=\"http:\/\/winterbe.com\/posts\/2014\/04\/05\/java8-nashorn-tutorial\/\">nashorn tutorial<\/a>&#8230;<\/p>\n<p>I&#8217;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&#8217;m aiming more at trying things out than at building pretty code&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This weekend I&#8217;m roaming a bit afield of my normal haunts. I&#8217;m looking at service hosted JVMs in windows and in particular having such a service interact with the\u00a0SERVICE_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 &hellip; <a href=\"https:\/\/ninecrows.com\/career\/2018\/04\/20\/looking-at-java-windows-services-and-hosted-javascript\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Looking at Java, Windows Services and hosted Javascript<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[9,3,22],"tags":[23,39,38,37,42,41,40],"class_list":["post-1964","post","type-post","status-publish","format-standard","hentry","category-daily-blog","category-ideas","category-sandbox","tag-java","tag-javascript","tag-jna","tag-jni","tag-nashorn","tag-shutdown","tag-windows-service"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7F2Qc-vG","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/1964"}],"collection":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/comments?post=1964"}],"version-history":[{"count":4,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/1964\/revisions"}],"predecessor-version":[{"id":2004,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/1964\/revisions\/2004"}],"wp:attachment":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/media?parent=1964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/categories?post=1964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/tags?post=1964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}