dev2dev.bea.com.cn
首页 资源中心 dev2dev学堂 在线技术论坛 专家Blog User Group CodeShare

WLS 9.0 Management API,第二部分

2005-11-25 00:00:00 | 评论 (0) | 被访问(551)次

Satya Ghattu
  Satya Ghattu加入BEA公司已经有4年多了,担任软件工程师,专门负责WebLogic Platform的Operations Administration以及Management方面。Satya拥有将近8年的软件开发经验,主要是在应用服务器、核心java以及相关的(J2EE)技术方面。他还领导着dev2dev上CodeShare中的几个开源项目,并向dev2dev社区贡献了大量的代码示例。Satya是WebLogic Scripting Tool (WLST)的最初设计者,该工具是BEA官方支持的WebLogic Server命令行工具。在加入BEA之前,他曾在许多软件公司担任各种不同的职务,做过高级Java开发人员、软件分析师,还做过Oracle数据库管理员。Satya持有俄亥俄州Akron大学的工程学硕士学位。


  在我的前一篇文章中,我们讨论了如何管理9.0之前的WLS。在9.0中发生了许多变化,重要的变化包括:采用了基于JMX 1.2的JSR 160的Management API,以及包含新功能的MbeanServer。JSR 160定义了JMX的远程API,使客户机无需在类路径中使用任何的专有类就可以连接到远程的JMX MbeanServer。既然已经有了远程连接到JMX Agent的标准方式,BEA就不鼓励使用其远程扩展MbeanHome和RemoteMBeanServer了。BEA也否决了(当查找一个Mbean时)MbeanHome通常返回的类型安全存根,现在推荐使用直接的JMX或WLST。在9.0中,config.xml是基于模式的,这使用户可以使用诸如XMLSpy之类的工具脱机编辑配置文件。在9.0以前的版本中,只有一个MbeanServer,用来驻留所有的Mbean(Configuration、Runtime以及Custom)。在9.0中,WLS有四个Mbean服务器,根据它们的功能,每个都提供了到不同MBean的访问。Edit MBean Server提供到可编辑的Configuration Mbean的访问,Domain Runtime MBean Server提供到域中所有Runtime Mbean和只读Configuration MBean的联邦访问,Runtime MBean Server提供只到Runtime或只读Configuration Mbean的访问,Compatibility MBeanServer提供到所有不鼓励使用的MBean的访问。

  下面我们对9.0以前的WLS版本和9.0版本做个一对一的比较。

WLS Management(6.0到8.1) WLS Management(9.0及以后)
专有的远程API,用于访问MbeanServer。 采用基于标准的JSR 160。不鼓励使用 MbeanHome和RemoteMBeanServer。
一个MbeanServer,驻留所有的Mbean。 4个Mbean服务器(MBS),根据功能驻留不同的Mbean。
不基于模式的config.xml。 基于模式的config.xml。
在MBean层次结构中存在许多故障链接。 所有的MBean都完全链接,使层次结构可以越过。
MbeanHome是创建和删除所有Mbean的Factory。 每个父Mbean都作为创建和删除其子Mbean的Factory。
配置更改机制是原子的。 对配置更改引入了事务语义。
对配置更改没有控制,而且通常无法预料。 对配置进行更改时需要锁定,更多控制(可以撤销更改、终止编辑等等)。
AdminMBeanHome提供域的联邦视图。 DomainRuntime MBeanServer提供域的联邦视图。
通过weblogic.Admin进行命令行管理。 否决weblogic.Admin,引入了WLST。
WebLogic域名在MBean的ObjectName中,例如: mydomain:Name=myserver,Type=Server。 更改为com.bea,例如: com.bea:Name=myserver,Type=Server。
config.xml表示所有的WLS配置。 {domain_dir}/config目录表示WLS配置,即,配置分布于多个xml文件中(JMS、JDBC和WLDF配置在不同的文件中)。
无。

获得根MBean的服务MBean。


  下面是在WLS 9.0中获得ServerMBean的代码:

// All JMX imports that you need
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
// Assuming you know these
String protocol = "t3"; // can be t3, http, iiop
String hostname = "localhost";
int port = 7001;
String uri = "/jndi/" +"weblogic.management.mbeanservers.runtime"; 
// Create a JMX Service URL
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, uri);
// Setup connection properties
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, user);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); // this one points to a BEA class
// Create a connection to the RuntimeMBeanServer
JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);
// Get the RuntimeMBeanServer
MBeanServerConnection connection = connector.getMBeanServerConnection();
// Get the Runtime Service MBean
ObjectName service = new ObjectName("weblogic:Name=RuntimeService");
// Get the Domain MBean
ObjectName domain = (ObjectName) connection.getAttribute(service,"DomainConfiguration");
// Get the ServerMBean
ObjectName server = (ObjectName) connection.getAttribute(domain,"ServerConfiguration");
String name = (String) connection.getAttribute(server, "Name");
System.out.println("Server's name "+name);


  或者可以编写一个简单的WLST脚本来实现,代码会少很多,但是肯定也会需要在类路径中使用Weblogic类。下面是可能的脚本:

# assuming you know the username, password and url
connect(username, password, url)
svr = cmo.lookupServer('myserver')
print svr.getName() 
  本文概述了9.0中的Management API的变化。更多信息请参考BEA电子文档。

原文出处:http://dev2dev.bea.com/blog/sghattu/archive/2005/09/wls_90_manageme_1.html



Tags: WLS 9.0 Management API Mbean
文章评论:(以下网友留言只代表个人观点,不代表BEA观点和立场)
暂时没有评论!

2005年11月

  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
             
RSS订阅

Satya Ghattu's Blog搜索