I want to write a small admin tool that can start, stop, and monitor other Java non-GUI programs that either run continuously or are expected to complete? This tool would run on the same server as the backend programs. I would have a web front end for the administrator to use (probably with Jetty). I would most likely want the backend programs to run as their own separate processes.
What if I wanted to communicate with those programs, such as query some detailed status? The backend programs break up their computational work in ticks and between ticks, I could check for commands that come in.
JMX has been a part of JRE since Java 1.5 it can be used to monitor local or remote java application.
Many java libraries/apps such as tomcat, jetty etc. have supported it by registering some JMX services.
If you want to a web front end for the administrator to use, you can try jolokia which is remote JMX with JSON over HTTP. It is fast, simple, polyglot and has unique features.
Related
Let's imagine that your company asked to develop a real-time chat application and wanted it to be finished in hours. Since you already know that it's super duper easy with Node.js, you developed it in Node.js but the company uses Java Application Servers(like WebSphere, JBoss or WebLogic).
So the server administrator expects .EAR files to deploy.
Is there any way to provide an .EAR file that runs your Node.js app behind?
this is so frigging dirty that any sane checks on the released EAR should kill you on place. that being said, yes, it's possible. you have to know a bit of things first.
is the target JVM is enough priviliged to run processes or security on the execute right sufficently lax to enable the JVM to execute shell process by using it's API methods. (i'm talking about Java security, not OS security)
you must know first hand exactly which type of OS the ear container is running on.
the EAR/WAR must be "expanded" to a real filesystem known by the OS.
you must know if the credential under which the ear container have enough privilege to execute a OS command.
once you know exactly those four points, this is no biggie to use the Process java API to execute a Node.js process that the executable (statically linked and OS compatible) is conveniently to a known position...
even as Bruno Grieder said, sharing port is not possible, so you'll just have the web application acting as a front proxy for the "real" application running on Node.js, HTTP or HTTPS being not relevant at all as the final communication between the web application container and the web application itself is no longer encrypted.
awwww... so cute ... :) but, you have to know that using a sneaky method like this in company environment, is not a good thing.
No.
You cannot properly package a "pre-installed" nodeJS inside an ear.
NodeJS installation differs between Windows and Linux; the EAR would not be portable.
On a side note, I would not like to be in your shoes, should the server administrators learn that you are packaging executables not meant to be run on the JVM, inside the EAR.
(note1: as noted in the comments above by #mlan, it would be impossible to share ports between the JVM and nodejs process - faking it would require a fronting reverse proxy dispatching HTTP requests, assuming all traffic is HTTP)
(note2: don't put me wrong, you can put anything in a EAR, including executables that you trigger from Java using ProcessBuilder for instance, but that a last resort workaround)
I'm relatively unexperienced in developing JAVA and I was hoping on getting some advice.
I have a modular JAVA server application setup in which a high level service that acts as a front-end interface which communicates with 8 lower level services.
In production, each service is hosted on its own machine.
I'm looking to profile a standard SE development environment which launches all instances locally. I am currently using eclipse and JVMmonitor.
My current workflow involves manually starting each service, followed by triggering the monitoring process on each service manually through eclipse. This workflow gets the job done, but I'm sure there is a more intelligent solution someone has come across. Most forum postings only solve monitoring one java instance.
Are there any other stand alone JAVA applications that anyone would suggest? I would like to avoid adding profiling code if possible.
Most profilers allow you to profile JVMs without the need to manually start the profiler.
For example, JProfiler calls this "offline profiling" and the integration wizards in the JProfiler GUI have an option for it:
Disclaimer: My company develops JProfiler.
Use visualVM.You can profile from urs local computer to different servers .
http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/applications_remote.html For profiling in different servers you need to define jstatd.all.policy file. For example if you want to monitor to different servers say s1,s2,s3 then in s1,s2,s3 server define jstatd.all.policy file and run statd - Virtual Machine jstat Daemon.Then from yours local computer you can monitor 3 s1,s2,s3 servers.
In very easy to configure it.
1.Run visualVm you can get eclipe pluging for it.
2.Run jstatd -J-Djava.security.policy=D:\jstatd.all.policy // location of yours jstatd.all.policy file in yours servers
3.In jstatd.all.policy define
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
4.Now connect to yours servers and monitor from local .
I have a bunch of shell scripts on every client machine. I need a web interface to provide settings for these scripts and it should invoke these scripts.
If i run a web application from a server to run scripts, it will overload the server due to multiple client requests, so client side web app is preferred.
Applets can solve this. But, it is outdated and I dont like it.
Is there any other new/good technologies to do such client side computing ?
Are you talking about web application or desktop application?
If this is a web application, so as far as I know - no. You must use applet embedded at your web page to run the script.
If desktop application - it can use the API for execution processes at Java.
Another option is maybe to download some small server code that will be used to invoke scripts, and have you web application communicate with it, in order to invoke a process.
The downside of this is that this is not a "straightforward" usage of your web application.
I have an existing Java application running on a linux box that monitors the state of relays and network information. This is a stand-alone device currently.
What I would like to further develop is a web server for the device to remotely monitor, configure, and control the device via an Ethernet connection. To achieve this, I need some way to interface between the web server, which could be configured as enabled/disabled, and the master device, which is always running.
Is there a good way to do this? I have looked at apache w/ tomcat and similar web servers but not sure if this is what I need. The key here is that the web server needs to be able to access the existing java application without interfering with its always running services.
You either develop a webapp, use your Java application's API inside the webapp, and deploy this webapp inside a web container. Or you can do the reverse and embed a web server inside your application (see here for documentation to embed Jetty).
If you want to keep the webapp and the original application in two separate JVMs, you'll need some wey to communicate between both, like sockets, RMI, or even files, but it will be more complex.
You might want to take a look at JMX http://docs.oracle.com/javase/tutorial/jmx/overview/index.html
I need to call a jar which is kept on a shared windows machine.
The JVM also needs to be placed on this shared machine so that anyone with access to the remote location should be able to call this jar.
I need to write a windows script which shall be run using a service user.
Is this possible? If yes, request you to please provide pointers.
Java Management Extensions provides the tools for building Web-based, distributed, dynamic and modular solutions for managing and monitoring devices, applications, and service-driven networks.
see JMX Tutorial
see example with Linux script
see Windows cmd script
You might have some luck using the Tanuki Software Java Service Wrapper. Jetty uses this for their Windows Service Wrapper.
Another option is Apache Commons Procrun, which is what Apache Tomcat uses.
Both work well to set up a Java application as a Windows service. You will need to ensure your application is designed to run well as a service; you should be able to "trigger" events (start, stop, restart, etc.). You might need a lightweight adapter around the application to get it to work right as a service; but that should be a trivial exercise.
Once you have a service set up, make sure appropriate user(s) have rights to start/stop the service [1] [2]. You could even set the service up to run using a specific account. Then you can use the net start, net stop, etc. commands in a batch file.