package jmxbook.ch11;
import jmxbook.ch3.RMIClientFactory;
import java.util.*;
import java.io.*;
import java.net.*;
import com.sun.jdmk.comm.*;
import javax.management.*;
import javax.management.relation.*;
import jmxbook.ch3.ExceptionUtil;
public class RelationMain
{
ObjectName relationServiceName = null;
Role voiceProcessorRole = null;
Role faxProcessorRole = null;
RoleList roleList = new RoleList();
private RmiConnectorClient client = null;
////////////////////////////////////////////////////////////////////////////////////////
// //
////////////////////////////////////////////////////////////////////////////////////////
public RelationMain()
{
client = RMIClientFactory.getClient();
try{
relationServiceName = new ObjectName( "JMXBookAgent:name=relationService" );
}
catch(Exception e){
e.printStackTrace();
System.exit(0);
}
}
////////////////////////////////////////////////////////////////////////////////////////
// //
////////////////////////////////////////////////////////////////////////////////////////
public void createMBeans()
{
try
{
//register the first PhoneCard
Object[] params = new Object[1];
params[0] = new Integer(1);
String[] sig = new String[1];
sig[0] = "int";
System.out.println("\n>>> REGISTERING PhoneCard1 MBean");
ObjectName phoneCard1Name = new
ObjectName("JMXBookAgent:name=phoneCard,slot=1");
client.createMBean( "jmxbook.ch11.PhoneCard",
phoneCard1Name,
params,
sig );
//register the second PhoneCard
params[0] = new Integer(2);
System.out.println("\n>>> REGISTERING PhoneCard2 MBean");
ObjectName phoneCard2Name = new
ObjectName( "JMXBookAgent:name=phoneCard,slot=2" );
client.createMBean( "jmxbook.ch11.PhoneCard",
phoneCard2Name,
params,
sig );
//register the FaxCard
System.out.println("\n>>> REGISTERING FaxCard MBean");
ObjectName faxCardName = new
ObjectName( "JMXBookAgent:name=faxCard" );
client.createMBean( "jmxbook.ch11.FaxCard",faxCardName );
//register the RoutingTable
System.out.println("\n>>> REGISTERING RoutingTable MBean");
ObjectName routingTableName = new
ObjectName( "JMXBookAgent:name=routingTable" );
client.createMBean("jmxbook.ch11.RoutingTable",
routingTableName);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error Registering MBeans");
}
}
////////////////////////////////////////////////////////////////////////////////////////
// //
////////////////////////////////////////////////////////////////////////////////////////
public RoleInfo[] createRoleInfoArray()
{
RoleInfo[] roleInfoArray = new RoleInfo[3];
try
{
roleInfoArray[0]= new RoleInfo("VoiceProcessor",
"jmxbook.ch11.PhoneCard",
true,
true,
1,
10,
"The Role for Phone Card");
roleInfoArray[1] = new RoleInfo("FaxProcessor",
"jmxbook.ch11.FaxCard",
true,
true,
1,
1,
"The Role for Fax Card");
roleInfoArray[2] = new RoleInfo("CallRouter",
"jmxbook.ch11.RoutingTable",
true,
true,
1,
1,
"The Role for Routing Table");
}
catch(Exception e)
{
System.out.println("Error Creating the Relation Service MBean");
e.printStackTrace();
}
return roleInfoArray;
}
////////////////////////////////////////////////////////////////////////////////////////
// //
////////////////////////////////////////////////////////////////////////////////////////
public void createRelationTypes( RoleInfo[] roleInfoArray )
{
try
{
Object[] params = new Object[2];
params[0] = "myRelationType";
params[1] = roleInfoArray;
String[] signature = new String[2];
signature[0] = "java.lang.String";
try {
signature[1] = (roleInfoArray.getClass()).getName();
}
catch (Exception exc)
{
throw exc;
}
client.invoke(relationServiceName, "createRelationType",
params, signature);
}
catch (Exception e)
{
System.out.println("Error Creating the RelationType");
ExceptionUtil.printException(e);
}
}
////////////////////////////////////////////////////////////////////////////////////////
// //
////////////////////////////////////////////////////////////////////////////////////////
public void createRoles()
{
ArrayList voiceRoleValue = new ArrayList();
ArrayList faxRoleValue = new ArrayList();
ArrayList routingTableRoleValue = new ArrayList();
try
{
voiceRoleValue.add( new
ObjectName("JMXBookAgent:name=phoneCard,slot=1") );
voiceRoleValue.add( new
ObjectName("JMXBookAgent:name=phoneCard,slot=2") );
Role voiceProcessorRole = new Role("VoiceProcessor",
voiceRoleValue);
faxRoleValue.add( new ObjectName("JMXBookAgent:name=faxCard") );
Role faxProcessorRole = new Role("FaxProcessor", faxRoleValue);
routingTableRoleValue.add( new ObjectName(
"JMXBookAgent:name=routingTable" ) );
Role routingTableRole = new Role("CallRouter",
routingTableRoleValue);
roleList.add(voiceProcessorRole);
roleList.add(faxProcessorRole);
roleList.add(routingTableRole);
}
catch (Exception e)
{
System.out.println("Error Creating Roles");
ExceptionUtil.printException(e);
}
System.out.println(">>> CREATED Roles");
}
////////////////////////////////////////////////////////////////////////////////////////
// //
////////////////////////////////////////////////////////////////////////////////////////
public void createRelation()
{
System.out.println("\n>>> CREATE EXTERNAL RELATION of "
+ " type myRelationType");
try
{
//register the relation MBean
ObjectName relationMBeanName = new ObjectName(
"JMXBookAgent:type=RelationMBea
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
jmxbook.rar (81个子文件)
jmxbook
META-INF
jboss.xml 576B
ejb-jar.xml 2KB
ch12
MonitoringSetup.java 1KB
CorrectiveStringMonitor.java 881B
ObservableObjectMBean.java 289B
TimerSetup.java 1KB
ObservableObject.java 727B
CorrectiveStringMonitorMBean.java 255B
ch9
JINIConnectorClient.java 7KB
TCPTester.java 2KB
TCPServerMBean.java 179B
JINIServer.java 3KB
JINIConnector.java 329B
JINIServerMBean.java 286B
TCPServer.java 1KB
TCPAdapter.java 6KB
JINIConnectorException.java 363B
JINIConnectorImpl.java 875B
ch13
runPublisher.bat 738B
DebugSubscriber.java 3KB
resources
jndi.properties 156B
JMSPublisher.java 3KB
JMSSetup.java 2KB
JMSController.java 5KB
JMSControllerMBean.java 143B
runDeviceDebug.bat 715B
runSubscriber.bat 1KB
ch6
NotificationBroadcasterPersister.java 1KB
PollingMBean.java 181B
Polling.java 2KB
PollingSetup.java 845B
ch11
RelationMain.java.new 7KB
PhoneCardMBean.java 92B
CtlRelation.java 2KB
RelationMain.java 10KB
CtlRelationMBean.java 285B
RoutingTableMBean.java 152B
RoutingTable.java 431B
FaxCard.java 216B
FaxCardMBean.java 90B
PhoneCard.java 313B
ch7
ModelMBeanInfoBuilder.java 5KB
ModeledClass.java 2KB
ch3
JMXBookAgent.java 5KB
HelloWorldSetup.java 655B
RMIClientFactory.java 754B
ExceptionUtil.java 819B
lib
jmxtools.jar 100KB
jmxri.jar 357KB
ch5
DynamicMBeanSupport.java.saf 6KB
JINIServiceManager.java.saf 4KB
ch14
EJBMBeanGenerator.java 6KB
WorkflowManager.java 4KB
UserInfo.java 353B
UserInfoHome.java 326B
Workflow.java 291B
UserInfoMgr.java 3KB
WorkflowHome.java 326B
UserInfoBean.java 2KB
UserInfoMgrMBean.java 178B
WorkflowBean.java 5KB
UserLogin.java 1KB
ch4
PropertyManagerMBean.java 265B
PropertyManager.java 1KB
PropertyManagerSetup.java 642B
DBSourceMBean.java 257B
DataLayerMBean.java.unused 247B
LoggerMBean.java 232B
Logger.java 2KB
DBSource.java 1KB
ch10
MLetWrapper.java 6KB
MLetWrapperMBean.java 125B
MLetNotification.java 839B
ch10.mlet 93B
MLetWrapperSetup.java 982B
ch2
HelloWorld.java 770B
HelloWorldMBean.java 177B
HelloAgent.class 2KB
HelloWorld.class 1KB
HelloAgent.java 1KB
HelloWorldMBean.class 244B
共 81 条
- 1
资源评论
- twosand2014-06-12谢谢分享了,有源码真不错,不用自己敲了,提高效率 不过,对于现在版本的jdk来说,有些源码已经比较老了,要稍作修改
thinkhejie
- 粉丝: 4
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功