WAS Jacl脚本分析-启动MDB监听器

写WAS的Jacl脚本是一件极其费神的事,API匪夷所思的诡异,直接导致门槛之高,幸好IBM即时的转变成了Jython风格的脚本,但是对于我们的产品,基本上还是Jacl的脚本在Install环节做配置工作。作为了解,记录下分析start MDB Listener的脚本该如何写。

proc startListenerPort {cname nname sname command} {
 
global AdminControl
global AdminConfig
 
set lPorts [$AdminControl queryNames type=ListenerPort,cell=$cname,node=$nname,process=$sname,*]
 
foreach lPort $lPorts {
   set state [$AdminControl getAttribute $lPort started]
   if {$command == "start"} {
   if {$state == "false"} {
        $AdminControl invoke $lPort $command
     }
   }
 
   if {$command == "stop"} {
   if {$state == "true"} {
        $AdminControl invoke $lPort $command
     }
   }
}
 
 
}
 
################################################################################################
 
 
 
   set cname [lindex $argv 0]
   set nname [lindex $argv 1]
   set sname [lindex $argv 2]
   set command [lindex $argv 3]
 
   startListenerPort $cname $nname $sname $command
 
   $AdminConfig save

说明:
1. proc是函数开头的关键字。
2. global 命令:全局作用域是顶级作用域。此作用域在任何过程外。必须通过使用 global 命令使变量在可以访问过程中命令的全局作用域中定义。
3. 到WAS的IC上查AdminControl的API
1)queryNames

Use the queryNames command to query for a list of each of the ObjectName objects based on the name template.
2)getAttribute

Use the getAttribute command to return the value of the attribute for the name that you provide.
3)invoke

Use the invoke command to invoke an object operation with or without parameters. The command invokes the object operation using the parameter list that you supply. The signature generates automatically. The types of parameters are supplied by examining the MBeanInfo that the MBean supplies. Returns the string result of the invocation. The string that is returned is controlled by the Mbean method that you invoked. If the MBean method is synchronous, then control is returned back to the wsadmin tool only when the operation is complete. If the Mbean method is asynchronous, control is returned back to the wsadmin tool immediately even though the invoked task might not be complete.
4. [lindex argv 数字] 接受第几个命令行参数。
5.
AdminConfig save 一定记着保存。

保存此脚本为startMQListener.jacl,在外面调用此脚本的命令:

wsadmin.sh -wsadmin_classpath $CLASSPATH $credentials -f $RFIDIC_INSTALL_HOME/bin/jacl/startMQListener.jacl $CELLNAME $NODENAME $SERVERNAME start

console输出为:
WASX7209I: Connected to process “server1” on node tslnx09Node01 using SOAP connector; The type of process is: UnManagedProcess
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: “[tslnx09Node01Cell, tslnx09Node01, server1, stop]”

第一句表示连接到了WAS的Admin,如果不启动WAS则会报错。
第二句表示4个参数传入了刚刚编写的脚本。

Leave a Comment.