8

我可以获得已安装应用程序的列表,但如何使用 Jython 获得状态?

4

4 回答 4

14

我认为没有任何直接的方法可以获取应用程序运行状态,您可以使用以下代码从 AdminControl 获取对象

serverstatus = AdminControl.completeObjectName('type=Application,name='your_application_name',*')
print serverstatus

如果serverstatus返回 null,则应用程序未运行,如果应用程序正在运行,则将打印应用程序的详细信息。

于 2011-11-19T12:42:45.857 回答
6

这是我根据 Snehan 的回答使用的。

import string

def getAppStatus(appName):
    # If objectName is blank, then the application is not running.
    objectName = AdminControl.completeObjectName('type=Application,name=' + appName + ',*')
    if objectName == "":
        appStatus = 'Stopped'
    else:
        appStatus = 'Running'
    return appStatus

def appStatusInfo():
    appsString = AdminApp.list()
    appList = string.split(appsString, '\r\n')

    print '============================'
    print ' Status |    Application   '
    print '============================'

    # Print apps and their status
    for x in appList:
        print getAppStatus(x) + ' | ' + x

    print '============================'



appStatusInfo()

样本输出

============================
 Status |    Application
============================
Running | DefaultApplication
Running | IBMUTC
Stopped | some-ear
Running | another-ear
============================
于 2014-01-08T13:41:31.183 回答
4

以下 IBM 文档应该会有所帮助:

总而言之,如果应用程序在应用程序服务器上运行,则将注册一个ApplicationMBean 。为了确定应用程序是否正在运行,您可以查询这些 MBean 是否存在。

于 2011-11-18T18:39:45.650 回答
1

在 Cormier 的剧本 Matthieu 中还需要进行一些修改。

开始了。

它适用于任何行分隔符。通常AdminApp.list()将使用“\”作为行分隔符

import string

def getAppStatus(appName):
    # If objectName is blank, then the application is not running.
    objectName = AdminControl.completeObjectName('type=Application,name='+ appName+',*')
    if objectName == "":
        appStatus = 'Stopped'
    else:
        appStatus = 'Running'
    return appStatus

def appStatusInfo():
    Apps=AdminApp.list().split(java.lang.System.getProperty("line.separator"))

    print '============================'
    print ' Status |    Application   '
    print '============================'

    # Print apps and their status
    for x in Apps:
        print "X value", x
        print getAppStatus(x) + ' | ' + x

    print '============================'



appStatusInfo()
于 2015-11-26T13:37:44.383 回答