如何使用JMX从管理应用程序启动java程序

假设我有一个打包在可执行jar中的java程序,我通常使用java -jar myappjar.jar从命令行开始.现在我想开发远程管理应用程序来启动这个java程序,并且一旦启动我希望能够阻止它我的意思是它必须在我的程序中调用一个方法关闭它将执行清理工作并退出程序.

此外,当我启动远程管理应用程序本身时,它应该告诉我我要启动的程序是否已经运行,如果是,则先停止它.

以上所有可能以及如何实现这一目标?特别是最重要的是能够启动尚未运行的程序.

我启动的程序是一个永远运行的服务器,直到手动或通过远程管理应用程序关闭.此服务器绝不应依赖于JMX代理程序或远程管理应用程序,即远程管理应用程序/ JMX代理程序可以关闭,服务器程序仍然保持运行或服务器可以手动启动,以后可以启动远程管理应用程序来检测此服务器程序如此渴望.

解决方法:

你真正需要的是某种Management agent

A Management agent is a software agent that runs on a managed node
and provides an interface to manage it. It can
perform operations on managed objects in the node and can also forward
notifications to the manager.

请看一个例​​子:

在您的情况下,它将是管理工具和应用程序之间的JMX协议.在远程主机上启动并运行代理是一个先决条件.开发基本代理似乎不是一项艰巨的任务,具备以下条件:

>下载/部署应用程序
>启动/停止应用程序
>监控部署的应用程序

Agent是一个非常简单的应用程序,它实现了几个命令(管理操作).

有用链接:Agents in Network Management

更新:glu代理示例

glu is a free/open source deployment and monitoring automation platform. Glu is solving the following problems:

  • deploy (and monitor) applications to an arbitrary large set of nodes:
  • efficiently
  • with minimum/no human interaction
  • securely
  • in a reproducible manner

它基于相同的原则,并在其中有一个代理:

The 07003 is an active process that needs to run on every host
where applications need to be deployed. Its main role is to run glu
scripts. It is the central piece of the deployment automation platform
and is the only required piece of infrastructure. It exposes a REST
api and a command line (which invokes the REST api under the cover).

如果您需要一些额外的评论,请随时询问.

上一篇:java – 更新JMX MBean属性而不向客户端公开方法


下一篇:java – 当达到80%的堆使用时通知