向左走,向右走。。。
永遠不回頭
BlogJava
首頁
新隨筆
新文章
聯系
聚合
管理
posts - 16,comments - 17,trackbacks - 0
<
2005年2月
>
日
一
二
三
四
五
六
30
31
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
1
2
3
4
5
6
7
8
9
10
11
12
網 名:
非飛
性 別:
男
籍 貫:
廣西桂林
Q Q:
8038052
MSN:
towerhe@hotmail.com
Email:
towerhe@gmail.com
愛 好:
愛好廣泛,不在此處做詳細說明。
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(3)
給我留言
查看公開留言
查看私人留言
隨筆分類
(14)
Flash相關技術(1)
JAVA 相關技術(6)
JavaScript相關技術(2)
生活瑣事(3)
軟件工程(2)
隨筆檔案
(16)
2005年5月 (2)
2005年4月 (4)
2005年3月 (6)
2005年2月 (2)
2005年1月 (2)
文章分類
(2)
JMX(2)
文章檔案
(3)
2005年4月 (1)
2005年2月 (2)
收藏夾
(3)
JAVA(3)
友情鏈接
楊彥
陶文
文章
JMX相關文章
搜索
最新評論
1.?re: 回實驗室上班
兄臺,好久不更新, 這就是你的不對了!我等著你寫博客啊
--YZ
2.?re: JMX設計模式之MBeanWriteToLog模式
good
--hellochen
3.?re: Hibernate中的繼承映射
錯別字也太多了點吧
--無可奈何花落去
4.?re: 程序員應該怎么過生活???
程序員很苦,但有個老姐就很幸福了!哈哈.....
--dwj
5.?re: JMX設計模式之MBeanWriteToLog模式
好!
--王瓊
6.?re: JavaScript讀取服務器端的xml
很好,謝謝~
--lovelywcm
7.?re: 各層共享使用PO的代價
我的觀點,大部分實體對象只要vo、po重用就可以了,只有vo、po差距較大的地方才分開,這樣就做到了簡潔性和可擴展性的良好折中。
--CowNew開源團隊
8.?re: 各層共享使用PO的代價
都TMD的人云亦云,很少有說PO變動之后,VO不變動的,既然兩個都要動,何不只動一個?
--TMD
9.?re: 程序員應該怎么過生活???
我很按時睡覺的都是 晚上1:00
--smilerain
10.?re: NIO中Selector的工作原理
sorry, 我說的是SelectionKey.interestOps
--zhangwei
閱讀排行榜
1.?NIO中Selector的工作原理 (17393)
2.?通過mx4j實現JMXConnectorServer和JMXConnector(5705)
3.?JavaScript讀取服務器端的xml(4718)
4.?Hibernate中的繼承映射(4601)
5.?使用JavaScript來實現頁面間的參數傳遞(4100)
6.?Linux下JNI調用(3354)
7.?用了一下flash的反編譯(2704)
8.?設計模式精解 [讀書筆記](2639)
9.?JMX設計模式之MBeanWriteToLog模式(2463)
10.?各層共享使用PO的代價(2463)
11.?組織團隊開發項目的方式(2306)
12.?JMX設計模式之MBeanForAppConfig模式(2227)
13.?程序員應該怎么過生活???(2119)
14.?看《難兄難弟》有感要說呀!(1963)
15.?一天的工作終于結束了。。。(1563)
16.?回實驗室上班(627)
評論排行榜
1.?NIO中Selector的工作原理 (3)
2.?使用JavaScript來實現頁面間的參數傳遞(3)
3.?程序員應該怎么過生活???(3)
4.?各層共享使用PO的代價(2)
5.?JMX設計模式之MBeanWriteToLog模式(2)
6.?Hibernate中的繼承映射(1)
7.?回實驗室上班(1)
8.?JavaScript讀取服務器端的xml(1)
9.?用了一下flash的反編譯(1)
10.?Linux下JNI調用(0)
通過mx4j實現JMXConnectorServer和JMXConnector
看了兩天文檔,總算對JMX有了一個整體的認識。發現使用mx4j實現JMX還是相當的輕松的。MBeans可以使用mx4j-tools中的 Xdoclet偷一下懶,讓它自動的生成MBeans和Descriptions,ant有相應的支持,還是比較方便的,對于MBean接口的實現,自己寫了。
對于如何產生和注冊MBeans,mx4j提供了一個相當方便的工具,為什么說相當方便,是因為它真的實在是太方便了。通過寫一個xml配置文件可以完成所有的工作。比起M-LET確實是強了不少。下面就是一個在MBean Server產生注冊一個NamingService、JMXConnectorServer和一個自寫的MBean的配置文件。
<?
xml version="1.0" encoding="UTF-8"
?>
<
configuration
port
="9999"
>
<
startup
>
<
create
classname
="mx4j.tools.naming.NamingService"
objectname
="naming:type=rmiregistry"
>
<
arg
type
="int"
>
1099
</
arg
>
</
create
>
<
call
operation
="start"
objectname
="naming:type=rmiregistry"
/>
<
object
objectid
="rmi"
>
<
call
classname
="javax.management.remote.JMXConnectorServerFactory"
method
="newJMXConnectorServer"
>
<
arg
type
="javax.management.remote.JMXServiceURL"
>
<
new
classname
="javax.management.remote.JMXServiceURL"
>
<
arg
type
="string"
>
service:jmx:rmi://localhost/jndi/rmi://localhost:1099/jmx
</
arg
>
</
new
>
</
arg
>
<
arg
type
="java.util.Map"
/>
<
arg
type
="javax.management.MBeanServer"
/>
</
call
>
</
object
>
<
register
objectname
="connectors:type=rmi,protocol=jrmp"
>
<
arg
type
="object"
refobjectid
="rmi"
/>
</
register
>
<
call
method
="start"
refobjectid
="rmi"
/>
<
create
classname
="nsmp.examples.mbeans.rmi.MyRemoteServiceObject"
objectname
="services:type=my-remote"
/>
</
startup
>
<
shutdown
>
<
call
operation
="stop"
objectname
="services:type=my-remote"
/>
<
call
method
="stop"
refobjectid
="rmi"
/>
<
call
operation
="stop"
objectname
="naming:type=rmiregistry"
/>
<
unregister
objectname
="services:type=my-remote"
/>
<
unregister
objectname
="connectors:type=rmi,protocol=jrmp"
/>
<
unregister
objectname
="naming:type=rmiregistry"
/>
</
shutdown
>
</
configuration
>
java代碼:
package nsmp.agent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.Reader;
import java.net.Socket;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import mx4j.tools.config.ConfigurationLoader;
import nsmp.util.NsmpGlobals;
/**/
/*
*
* @version 1.0
* @author tower
*
* TODO write the comment of this type
*/
public
class
NsmpServer
{
public
void
startup() throws Exception
{
MBeanServer server
=
MBeanServerFactory.newMBeanServer();
ConfigurationLoader loader
=
new
ConfigurationLoader();
server.registerMBean(loader, ObjectName.getInstance(
"
config:service=loader
"
));
Reader reader
=
new
BufferedReader(
new
FileReader(NsmpGlobals.NSMP_HOME
+
"
/conf/config.xml
"
));
loader.startup(reader);
reader.close();
System.
out
.println(
"
Start the nsmp server successfully!
"
);
}
public
void
shutdown() throws Exception
{
String shutdownCommand
=
"
shutdown
"
;
Socket socket
=
new
Socket(
"
127.0.0.1
"
,
9999
);
socket.getOutputStream().write(shutdownCommand.getBytes());
socket.close();
}
}
startup方法調用配置文件的startup部分完成創建和注冊,shutdown方法調用配置文件的shutdown部分釋放相應的資源。通過調用 startup方法就可以起動MBeanServer提供服務了。對于shutdown開始搞了我半天startup后 ConfigurationLoader都沒有創建一個偵聽端口來接收shutdown命令,看了看mx4j的源碼發現 ConfigurationLoader也沒有發現什么特殊地方。捉摸半天終于發現了自己放了一個愚笨的錯誤,eclipse是用普通用戶權限開的,沒有辦法創建偵聽,改成root后一切ok。
接下就隨便寫了一個JMXConnector,代碼:
/**/
/*
* Copyright (C) The MX4J Contributors.
* All rights reserved.
*
* This software is distributed under the terms of the MX4J License version 1.0.
* See the terms of the MX4J License in the documentation provided with this software.
*/
package nsmp.examples.mbeans.rmi;
import java.util.Map;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
/**/
/*
*
* @version $Revision: 1.3 $
*/
public
class
Client
{
public
static
void
main(String[] args) throws Exception
{
JMXServiceURL address
=
new
JMXServiceURL(
"
service:jmx:rmi://localhost/jndi/rmi://localhost:1099/jmx
"
);
Map creationEnv
=
null
;
JMXConnector connector
=
JMXConnectorFactory.newJMXConnector(address, creationEnv);
Map connectionEnv
=
null
;
connector.connect(connectionEnv);
MBeanServerConnection serverConnection
=
connector.getMBeanServerConnection();
ObjectName name
=
ObjectName.getInstance(
"
services:type=my-remote
"
);
MBeanInfo mbInfo
=
serverConnection.getMBeanInfo(name);
MBeanOperationInfo[] operationInfo
=
mbInfo.getOperations();
for
(
int
i
=
0
; i
<
operationInfo.length; i
++
)
{
System.
out
.println(operationInfo[i].getName());
}
serverConnection.invoke(name,
"
sayHello
"
,
new
Object[]
{
"
Tower He
"
}
,
new
String[]
{
"
java.lang.String
"
}
);
}
}
JMXConnector是通過獲取一個MBeanServerConnection來實現遠程調用的,運行了一下一切順利通過。
下載:
MX4JExample.rar
posted on 2005-02-05 19:07
非飛
閱讀(5705)
評論(0)
編輯
收藏
所屬分類:
JAVA 相關技術
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
JMX設計模式之MBeanWriteToLog模式
JMX設計模式之MBeanForAppConfig模式
NIO中Selector的工作原理
Linux下JNI調用
Hibernate中的繼承映射
通過mx4j實現JMXConnectorServer和JMXConnector
Copyright ©2025 非飛 Powered By
博客園
模板提供:
滬江博客
主站蜘蛛池模板:
亚洲一区免费在线观看
|
亚洲一本大道无码av天堂
|
亚洲伊人久久大香线蕉苏妲己
|
免费夜色污私人影院网站电影
|
日韩在线天堂免费观看
|
亚洲av无码一区二区三区天堂
|
国产成人免费网站
|
亚洲国产精品专区
|
无人影院手机版在线观看免费
|
亚洲国产午夜电影在线入口
|
久久笫一福利免费导航
|
亚洲中文字幕乱码AV波多JI
|
免费电影在线观看网站
|
亚洲人成色77777在线观看
|
国产青草视频在线观看免费影院
|
亚洲av无码无线在线观看
|
99久久人妻精品免费二区
|
久久久久亚洲AV成人无码
|
120秒男女动态视频免费
|
国产精品亚洲精品
|
免费A级毛片无码久久版
|
本道天堂成在人线av无码免费
|
久久精品国产亚洲网站
|
每天更新的免费av片在线观看
|
天天爽亚洲中文字幕
|
四虎影视免费永久在线观看
|
国产精品亚洲精品爽爽
|
亚洲国产成人久久综合区
|
国产va在线观看免费
|
亚洲国产品综合人成综合网站
|
日本免费网站在线观看
|
日韩免费在线中文字幕
|
亚洲网红精品大秀在线观看
|
午夜高清免费在线观看
|
大地资源在线资源免费观看
|
亚洲精品白色在线发布
|
夜色阁亚洲一区二区三区
|
小草在线看片免费人成视久网
|
亚洲国产精品成人精品软件
|
免费一看一级毛片人
|
免费视频成人片在线观看
|