使用脚本编制在模块级别配置有状态会话 Bean 故障转移
使用脚本编制和 wsadmin 工具为有状态会话 Bean 故障转移配置应用程序。
开始之前
关于此任务
过程
- 使用 AdminConfig 对象来显示应用程序中 EJB 模块的有状态会话 Bean 故障转移配置。
- 启动 wsadmin 脚本编制客户机。
- 使用 Jacl
-
wsadmin
- 使用 Jython:
-
wsadmin -lang Jython
- 识别应用程序的部署配置对象,并将其指定给变量;例如:
- 使用 Jacl
-
set app [$AdminConfig getid /Deployment:EJBinWARTest/] set depObj [$AdminConfig showAttribute $app deployedObject]
- 使用 Jython:
-
app = AdminConfig.getid("/Deployment:EJBinWARTest/" ) depObj = AdminConfig.showAttribute(app, "deployedObject" )
- 获取该应用程序的模块列表。
- 使用 Jacl
-
set modules [lindex [$AdminConfig showAttribute $depObj modules] 0]
- 使用 Jython:
-
modules = AdminConfig.showAttribute(depObj, "modules" ) modules = modules.replace('[','').replace(']','') modules = modules.split(' ')
- 在本示例中,EJB 模块(即 EJBBean.jar)包含一个企业 Bean,Web 模块(即 EJB2xInWARBean.war)包含另一个企业 Bean。以下代码显示了如何为每一个企业 Bean 修改有状态会话 Bean 配置。
- 使用 Jacl
-
# Assign the EJB and web module configuration IDs to variables ejbmod and webmod: foreach module $modules { set moduleName [$AdminConfig show $module uri] if { [string first "EJBBean.jar" $moduleName] >= 0} { set ejbmod $module } if { [string first "EJB2xInWARBean.war" $moduleName] >= 0} { set webmod $module } }
- 使用 Jython:
-
# Assign the EJB and web module configuration IDs to variables ejbmod and webmod: for module in modules: moduleName = AdminConfig.showAttribute(module, 'uri') if moduleName.find('EJBBean.jar') >= 0: ejbmod = module if moduleName.find('EJB2xInWARBean.war') >= 0 : webmod = module
- 获取 EJB 模块配置对象。
- 使用 Jacl
-
# Get the single EJB module configuration object associated with the pure EJB module: set ejbConfig [lindex [$AdminConfig showAttribute $ejbmod configs] 0] if { ($ejbConfig == "") } { puts "\nejbConfig not present - creating one" set ejbConfig [$AdminConfig create EJBModuleConfiguration $ejbmod {{enableSFSBFailover true} {overrideDefaultDRSSettings false}}] set attrs [list config $ejbConfig] set targetMappings [lindex [$AdminConfig showAttribute $ejbmod targetMappings] 0] $AdminConfig modify $targetMappings [list $attrs] } else { puts "\nejbConfig present" }
- 使用 Jython:
-
# Get the list of configuration objects associated with the pure EJB module: ejbmodConfigs = AdminConfig.showAttribute (ejbmod, 'configs') if (ejbmodConfigs): print "\nejbmodConfigs present" # Extract the single EJB module configuration object: ejbConfig = ejbmodConfigs.replace('[','').replace(']','') print "\nejbConfig:" print AdminConfig.show(ejbConfig) else: print "\nejbmodConfigs not present - creating one" ecAttrs = [] attr1 = ["enableSFSBFailover", "true"] attr2 = ["overrideDefaultDRSSettings", "false"] ecAttrs.append(attr1) ecAttrs.append(attr2) ejbConfig = AdminConfig.create('EJBModuleConfiguration', ejbmod, ecAttrs) tmAttrs = ['config', ejbConfig] targetMappings = AdminConfig.showAttribute (ejbmod, 'targetMappings') targetMappings = targetMappings[1:len(targetMappings)-1] AdminConfig.modify(targetMappings, [tmAttrs])
- 显示 EJB 模块的有状态会话 Bean 故障转移配置设置。
- 使用 Jacl
-
# Show the Stateful session bean failover configuration of the EJB module: puts "\nStateful session bean failover settings of the EJB module" puts [$AdminConfig show $ejbConfig] # Show the drsSettings of the EJB module: set drsSettings [$AdminConfig showAttribute $ejbConfig drsSettings] if { ($drsSettings == "") } { puts "drsSettings not present on the EJB module." } else { puts "\ndrsSettings of the EJB module:" puts [$AdminConfig show $drsSettings] }
- 使用 Jython:
-
# Show the Stateful session bean failover configuration of the EJB module: print AdminConfig.show(ejbConfig) # Show the drsSettings of the EJB module: drsSettings = AdminConfig.showAttribute (ejbConfig, 'drsSettings') if (drsSettings): print "\ndrsSettings of the EJB module:" print AdminConfig.show(drsSettings) else: print "\ndrsSettings not present on the EJB module." drsSettings = AdminConfig.showAttribute (ejbConfig, 'drsSettings') if (drsSettings): print "\ndrsSettings of the EJB module:" print AdminConfig.show(drsSettings) else: print "\ndrsSettings not present on the EJB module."
- 启动 wsadmin 脚本编制客户机。
- 使用 AdminConfig 对象来修改同一应用程序中 Web 模块内企业 Bean 的有状态会话 Bean 故障转移配置。对于打包在 WAR 文件中的 EJB 模块,这些步骤类似,只是添加了用于从配置对象列表抽取 EJB 模块的步骤。
- 在给定步骤 4 中的 Web 模块配置标识的情况下,获取与该 Web 模块相关联的 EJB 模块配置对象。
- 使用 Jacl
-
# Get the web module configuration object: set webmodConfig [lindex [$AdminConfig showAttribute $webmod configs] 0] # Extract the EJB module configuration object associated with the web module. set ejbInWarConfig [$AdminConfig showAttribute $webmodConfig ejbModuleConfiguration]
- 使用 Jython:
-
# Get the list of configuration objects associated with the web module: webmodConfigs = AdminConfig.showAttribute (webmod, 'configs') # Extract the single web module configuration object: webmodConfig = webmodConfigs.replace('[','').replace(']','') # Extract the EJB module configuration object associated with the web module. ejbInWarConfig = AdminConfig.showAttribute (webmodConfig, 'ejbModuleConfiguration')
- 显示有状态会话 Bean 配置设置。
- 使用 Jacl
-
# Show the configuration of the EJB module within the web module: puts "\nStateful session bean failover settings of the EJB within the web module:" puts [$AdminConfig show $ejbInWarConfig] # Get the SFSB failover settings of the EJB module within the web module: set drsSettings [$AdminConfig showAttribute $ejbInWarConfig drsSettings] if { ($drsSettings == "") } { puts "drsSettings not present on the EJB within the Web module." } else { puts "\ndrsSettings of the EJB within the Web module:" puts [$AdminConfig show $drsSettings] }
- 使用 Jython:
-
print "\nStateful session bean failover configuration of the EJB module within the web module:" print AdminConfig.show(ejbInWarConfig) drsSettings = AdminConfig.showAttribute(ejbInWarConfig, 'drsSettings') if (drsSettings): print "\ndrsSettings of the EJB module within the web module:" print AdminConfig.show(drsSettings) else: print "\ndrsSettings not present on the EJB module within the web module." print "\ndrsSettings of the EJB module within the Web module:"
- 修改有状态会话 Bean 配置设置。
- 使用 Jacl
-
# To enable SFSB failover for the EJB within the web module: $AdminConfig modify $ejbInWarConfig {{enableSFSBFailover "true"}}
- 使用 Jython:
-
# Enable SFSB failover for the EJB within the web module: AdminConfig.modify(ejbInWarConfig, [['enableSFSBFailover', 'true']])
- 在给定步骤 4 中的 Web 模块配置标识的情况下,获取与该 Web 模块相关联的 EJB 模块配置对象。
相关概念:


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=txml_ejbsfsbf
文件名:txml_ejbsfsbf.html