/ojc-core/bpelmonitortool/monitor-src/src/com/sun/em/connectors/JmxConnector.java

https://bitbucket.org/ssteinmetz/openesb-components · Java · 713 lines · 332 code · 94 blank · 287 comment · 2 complexity · 432cee107b0d81ff32d3f19994819fb6 MD5 · raw file

  1. /* *************************************************************************
  2. *
  3. * Copyright (c) 2002, SeeBeyond Technology Corporation,
  4. * All Rights Reserved
  5. *
  6. * This program, and all the routines referenced herein,
  7. * are the proprietary properties and trade secrets of
  8. * SEEBEYOND TECHNOLOGY CORPORATION.
  9. *
  10. * Except as provided for by license agreement, this
  11. * program shall not be duplicated, used, or disclosed
  12. * without written consent signed by an officer of
  13. * SEEBEYOND TECHNOLOGY CORPORATION.
  14. *
  15. ***************************************************************************/
  16. package com.sun.em.connectors;
  17. import java.io.IOException;
  18. import java.util.Properties;
  19. import java.util.Set;
  20. import java.util.logging.Logger;
  21. import javax.management.Attribute;
  22. import javax.management.AttributeList;
  23. import javax.management.AttributeNotFoundException;
  24. import javax.management.InstanceAlreadyExistsException;
  25. import javax.management.InstanceNotFoundException;
  26. import javax.management.IntrospectionException;
  27. import javax.management.InvalidAttributeValueException;
  28. import javax.management.ListenerNotFoundException;
  29. import javax.management.MBeanException;
  30. import javax.management.MBeanInfo;
  31. import javax.management.MBeanRegistrationException;
  32. import javax.management.NotCompliantMBeanException;
  33. import javax.management.NotificationFilter;
  34. import javax.management.NotificationListener;
  35. import javax.management.ObjectInstance;
  36. import javax.management.ObjectName;
  37. import javax.management.QueryExp;
  38. import javax.management.ReflectionException;
  39. import javax.management.remote.JMXConnectorFactory;
  40. import javax.management.remote.JMXServiceURL;
  41. import javax.management.remote.JMXConnector;
  42. /**
  43. * JmxConnnector is the client-side component that allows client code to contact a remote MBeanServer.
  44. * A JMXConnector handles the details of registering notification listeners and receiving notifications
  45. * from the remote MBeanServer, as well as providing a way to authenticate to the JMXConnectorServer, and
  46. * eventually execute operations on behalf of a given javax.security.auth.Subject.
  47. * Finally the JMXConnector allows client code to obtain an implementation of the javax.management.MBeanServerConnection
  48. * interface that allows to interact with the remote MBeanServer as if it is local.
  49. *
  50. * The preferred way to create a JMXConnector is to use the javax.management.remote.JMXConnectorFactory class:
  51. *
  52. * @author ylee
  53. *
  54. * TODO To change the template for this generated type comment go to
  55. * Window - Preferences - Java - Code Generation - Code and Comments
  56. */
  57. public class JmxConnector extends Connector {
  58. private static final Logger logger = Logger.getLogger(JmxConnector.class.getName());
  59. JMXConnector mJMXConnector;
  60. /**
  61. * Allows connection to remote MBean server via JSR160 protocol
  62. * @param protocol -
  63. * @param host - name of the host for remote host where the MBeanServer is residing
  64. * @param port - port of the host for remote host where the MBeanServer is residing
  65. * @param username -
  66. * @param password -
  67. */
  68. public JmxConnector(String protocol, String hostname, String port, String username,
  69. String password,int hostType) {
  70. // JNDI name
  71. super(protocol,hostname,port,username,password,null,hostType);
  72. }
  73. public JmxConnector(String protocol, String hostname, String port, String username, String password,
  74. String jndiName, int hostType) {
  75. // JNDI name
  76. super(protocol,hostname,port,username,password,jndiName,hostType);
  77. }
  78. /**
  79. * This method returns the MBeanServerConnection to used to invoke the
  80. * remote MBean methods
  81. * @return MBeanServerConnection
  82. */
  83. public AbstractConnector getConnector() throws Exception {
  84. Properties env = new Properties();
  85. // properties contain user credentials, protocol, authentication, etc
  86. // default is <null> properties
  87. return getConnector(env);
  88. }
  89. /**
  90. * This method returns the MBeanServerConnection which can be used to invoke the
  91. * remote MBean methods and register for notifications
  92. * @return MBeanServerConnection
  93. */
  94. public AbstractConnector getConnector(Properties env) throws Exception {
  95. try {
  96. JMXServiceURL serviceURL;
  97. if ( jndiName!=null ) {
  98. serviceURL = new JMXServiceURL(protocol, hostname, Integer.parseInt(port),jndiName);
  99. } else {
  100. serviceURL = new JMXServiceURL(protocol, hostname, Integer.parseInt(port));
  101. }
  102. JMXConnector connector = JMXConnectorFactory.connect(serviceURL, (java.util.Hashtable)env);
  103. mbeanServerConnector = connector.getMBeanServerConnection();
  104. return this;
  105. } catch (Exception exception) {
  106. throw exception;
  107. }
  108. }
  109. // Public --------------------------------------------------------
  110. /**
  111. * @todo Document this method
  112. *
  113. * @param className X
  114. * @param name X
  115. * @return X
  116. * @exception ReflectionException X
  117. * @exception InstanceAlreadyExistsException X
  118. * @exception MBeanRegistrationException X
  119. * @exception MBeanException X
  120. * @exception NotCompliantMBeanException X
  121. */
  122. public ObjectInstance createMBean(
  123. String className,
  124. ObjectName objectName
  125. )
  126. throws
  127. ReflectionException,
  128. InstanceAlreadyExistsException,
  129. MBeanRegistrationException,
  130. MBeanException,
  131. NotCompliantMBeanException,
  132. java.io.IOException,
  133. java.rmi.RemoteException {
  134. return mbeanServerConnector.createMBean(className,objectName);
  135. }
  136. /**
  137. * @todo Document this method
  138. *
  139. * @param className X
  140. * @param name X
  141. * @param loaderName X
  142. * @return X
  143. * @exception ReflectionException X
  144. * @exception InstanceAlreadyExistsException X
  145. * @exception MBeanRegistrationException X
  146. * @exception MBeanException X
  147. * @exception NotCompliantMBeanException X
  148. * @exception InstanceNotFoundException X
  149. */
  150. public ObjectInstance createMBean(
  151. String className,
  152. ObjectName objectName,
  153. ObjectName loaderName
  154. )
  155. throws
  156. ReflectionException,
  157. InstanceAlreadyExistsException,
  158. MBeanRegistrationException,
  159. MBeanException,
  160. NotCompliantMBeanException,
  161. InstanceNotFoundException,
  162. java.io.IOException,
  163. java.rmi.RemoteException {
  164. return mbeanServerConnector.createMBean(className,objectName,loaderName);
  165. }
  166. /**
  167. * Instantiates the given class and registers it on the remote MBeanServer
  168. * and returns an Object Instance of the MBean.
  169. *
  170. * @param className Class name of the class to be loaded and instantiated
  171. * @param nameToAssign Object Name the new MBean should be assigned to
  172. * @param params Array of parameter passed to the creator of the class. If
  173. * one is of data type Object handler it will be replaced on the
  174. * server-side by its effective object.
  175. * @param signatures Array of Class Names (full qualified) to find the right
  176. * parameter. When there is an ObjectHandler as a parameter type then
  177. * it will be replaced on the server- side by the class name of the
  178. * effective object) otherwise it will be kept.
  179. * @exception ReflectionException X
  180. * @exception InstanceAlreadyExistsException X
  181. * @exception MBeanRegistrationException X
  182. * @exception MBeanException X
  183. * @exception NotCompliantMBeanException X
  184. * @return Object Instance of the new MBean
  185. */
  186. public ObjectInstance createMBean(
  187. String className,
  188. ObjectName nameToAssign,
  189. Object[] params,
  190. String[] signatures
  191. )
  192. throws
  193. ReflectionException,
  194. InstanceAlreadyExistsException,
  195. MBeanRegistrationException,
  196. MBeanException,
  197. NotCompliantMBeanException,
  198. java.io.IOException,
  199. java.rmi.RemoteException {
  200. return mbeanServerConnector.createMBean(className,nameToAssign,params,signatures);
  201. }
  202. /**
  203. * @todo Document this method
  204. *
  205. * @param className X
  206. * @param objectName X
  207. * @param loaderName X
  208. * @param params X
  209. * @param signatures X
  210. * @return X
  211. * @exception ReflectionException X
  212. * @exception InstanceAlreadyExistsException X
  213. * @exception MBeanRegistrationException X
  214. * @exception MBeanException X
  215. * @exception NotCompliantMBeanException X
  216. * @exception InstanceNotFoundException X
  217. */
  218. public ObjectInstance createMBean(
  219. String className,
  220. ObjectName objectName,
  221. ObjectName loaderName,
  222. Object[] params,
  223. String[] signatures
  224. )
  225. throws
  226. ReflectionException,
  227. InstanceAlreadyExistsException,
  228. MBeanRegistrationException,
  229. MBeanException,
  230. NotCompliantMBeanException,
  231. InstanceNotFoundException,
  232. java.io.IOException,
  233. java.rmi.RemoteException {
  234. return mbeanServerConnector.createMBean(className,objectName,loaderName,params,signatures);
  235. }
  236. /**
  237. * @todo Document this method
  238. *
  239. * @param objectName X
  240. * @exception InstanceNotFoundException X
  241. * @exception MBeanRegistrationException X
  242. */
  243. public void unregisterMBean(
  244. ObjectName objectName
  245. )
  246. throws
  247. IOException,
  248. InstanceNotFoundException,
  249. MBeanRegistrationException,
  250. java.rmi.RemoteException {
  251. mbeanServerConnector.unregisterMBean(objectName);
  252. }
  253. /**
  254. * @todo Document: Getter for ObjectInstance attribute of the
  255. * RemoteMBeanServer object
  256. *
  257. * @param objectName X
  258. * @return X
  259. * @exception InstanceNotFoundException X
  260. */
  261. public ObjectInstance getObjectInstance(
  262. ObjectName objectName
  263. )
  264. throws
  265. IOException,
  266. InstanceNotFoundException,
  267. java.rmi.RemoteException {
  268. return mbeanServerConnector.getObjectInstance(objectName);
  269. }
  270. /**
  271. * @todo Document this method
  272. *
  273. * @param objectName X
  274. * @param pQuery X
  275. * @return X
  276. */
  277. public Set queryMBeans(
  278. ObjectName objectName,
  279. QueryExp query
  280. ) throws IOException,
  281. java.rmi.RemoteException {
  282. return mbeanServerConnector.queryMBeans(objectName,query);
  283. }
  284. /**
  285. * @todo Document this method
  286. *
  287. * @param objectName X
  288. * @param query X
  289. * @return X
  290. */
  291. public Set queryNames(
  292. ObjectName objectName,
  293. QueryExp query
  294. ) throws IOException,
  295. java.rmi.RemoteException {
  296. return mbeanServerConnector.queryNames(objectName,query);
  297. }
  298. /**
  299. * @todo Document: Getter for Registered attribute of the RemoteMBeanServer
  300. * object
  301. *
  302. * @param objectName X
  303. * @return X
  304. */
  305. public boolean isRegistered(
  306. ObjectName objectName
  307. ) throws IOException,
  308. java.rmi.RemoteException {
  309. return mbeanServerConnector.isRegistered(objectName);
  310. }
  311. /**
  312. * @todo Document: Getter for InstanceOf attribute of the RemoteMBeanServer
  313. * object
  314. *
  315. * @param objectName X
  316. * @param className X
  317. * @return X
  318. * @exception InstanceNotFoundException X
  319. */
  320. public boolean isInstanceOf(
  321. ObjectName objectName,
  322. String className
  323. )
  324. throws
  325. IOException,
  326. InstanceNotFoundException,
  327. java.rmi.RemoteException {
  328. return mbeanServerConnector.isInstanceOf(objectName,className);
  329. }
  330. /**
  331. * @todo Document: Getter for MBeanCount attribute of the RemoteMBeanServer
  332. * object
  333. * @return X
  334. */
  335. public Integer getMBeanCount(
  336. ) throws IOException,
  337. java.rmi.RemoteException {
  338. return mbeanServerConnector.getMBeanCount();
  339. }
  340. /**
  341. * @todo Document: Getter for Attribute attribute of the RemoteMBeanServer
  342. * object
  343. *
  344. * @param objectName X
  345. * @param attribute X
  346. * @return X
  347. * @exception MBeanException X
  348. * @exception AttributeNotFoundException X
  349. * @exception InstanceNotFoundException X
  350. * @exception ReflectionException X
  351. */
  352. public Object getAttribute(
  353. ObjectName objectName,
  354. String attribute
  355. )
  356. throws
  357. IOException,
  358. MBeanException,
  359. AttributeNotFoundException,
  360. InstanceNotFoundException,
  361. ReflectionException,
  362. java.rmi.RemoteException {
  363. return mbeanServerConnector.getAttribute(objectName,attribute);
  364. }
  365. /**
  366. * @todo Document: Getter for Attributes attribute of the RemoteMBeanServer
  367. * object
  368. *
  369. * @param objectName X
  370. * @param attributes X
  371. * @return X
  372. * @exception InstanceNotFoundException X
  373. * @exception ReflectionException X
  374. */
  375. public AttributeList getAttributes(
  376. ObjectName objectName,
  377. String[] attributes
  378. )
  379. throws
  380. IOException,
  381. InstanceNotFoundException,
  382. ReflectionException,
  383. java.rmi.RemoteException {
  384. return mbeanServerConnector.getAttributes(objectName,attributes);
  385. }
  386. /**
  387. * @todo Document: Setter for Attribute attribute of the RemoteMBeanServer
  388. * object
  389. *
  390. * @param objectName attribute
  391. * @param attribute attribute
  392. * @exception InstanceNotFoundException X
  393. * @exception AttributeNotFoundException X
  394. * @exception InvalidAttributeValueException X
  395. * @exception MBeanException X
  396. * @exception ReflectionException X
  397. */
  398. public void setAttribute(
  399. ObjectName objectName,
  400. Attribute attribute
  401. )
  402. throws
  403. IOException,
  404. InstanceNotFoundException,
  405. AttributeNotFoundException,
  406. InvalidAttributeValueException,
  407. MBeanException,
  408. ReflectionException,
  409. java.rmi.RemoteException {
  410. mbeanServerConnector.setAttribute(objectName,attribute);
  411. }
  412. /**
  413. * @todo Document: Setter for Attributes attribute of the RemoteMBeanServer
  414. * object
  415. *
  416. * @param objectName attributes
  417. * @param attributes attributes
  418. * @return X
  419. * @exception InstanceNotFoundException X
  420. * @exception ReflectionException X
  421. */
  422. public AttributeList setAttributes(
  423. ObjectName objectName,
  424. AttributeList attributes
  425. )
  426. throws
  427. IOException,
  428. InstanceNotFoundException,
  429. ReflectionException,
  430. java.rmi.RemoteException {
  431. return mbeanServerConnector.setAttributes(objectName,attributes);
  432. }
  433. /**
  434. * @todo Document this method
  435. *
  436. * @param objectName X
  437. * @param actionName X
  438. * @param params X
  439. * @param signature X
  440. * @return X
  441. * @exception InstanceNotFoundException X
  442. * @exception MBeanException X
  443. * @exception ReflectionException X
  444. */
  445. public Object invoke(
  446. ObjectName objectName,
  447. String actionName,
  448. Object[] params,
  449. String[] signature
  450. )
  451. throws
  452. IOException,
  453. InstanceNotFoundException,
  454. MBeanException,
  455. ReflectionException,
  456. java.rmi.RemoteException {
  457. return mbeanServerConnector.invoke(objectName,actionName,params,signature);
  458. }
  459. /**
  460. * @todo Document: Getter for DefaultDomain attribute of the
  461. * RemoteMBeanServer object
  462. * @return X
  463. */
  464. public String getDefaultDomain(
  465. ) throws
  466. IOException,
  467. java.rmi.RemoteException {
  468. return mbeanServerConnector.getDefaultDomain();
  469. }
  470. public String[] getDomains() throws IOException {
  471. return mbeanServerConnector.getDomains();
  472. }
  473. /**
  474. * @todo Document: Getter for MBeanInfo attribute of the RemoteMBeanServer
  475. * object
  476. *
  477. * @param objectName X
  478. * @return X
  479. * @exception InstanceNotFoundException X
  480. * @exception IntrospectionException X
  481. * @exception ReflectionException X
  482. */
  483. public MBeanInfo getMBeanInfo(
  484. ObjectName objectName
  485. )
  486. throws
  487. IOException,
  488. InstanceNotFoundException,
  489. IntrospectionException,
  490. ReflectionException,
  491. java.rmi.RemoteException {
  492. return mbeanServerConnector.getMBeanInfo(objectName);
  493. }
  494. /**
  495. * Adds a feature to the NotificationListener attribute of the
  496. * RemoteMBeanServer object
  497. *
  498. * @param objectName The feature to be added to the NotificationListener
  499. * attribute
  500. * @param pListener The feature to be added to the NotificationListener
  501. * attribute
  502. * @param pFilter The feature to be added to the NotificationListener
  503. * attribute
  504. * @param handback The feature to be added to the NotificationListener
  505. * attribute
  506. * @exception InstanceNotFoundException X
  507. */
  508. public void addNotificationListener(
  509. ObjectName objectName,
  510. NotificationListener listener,
  511. NotificationFilter filter,
  512. Object handback
  513. )
  514. throws
  515. IOException,
  516. InstanceNotFoundException,
  517. java.rmi.RemoteException {
  518. mbeanServerConnector.addNotificationListener(objectName,listener,filter,handback);
  519. }
  520. /**
  521. * Adds a feature to the NotificationListener attribute of the
  522. * RemoteMBeanServer object
  523. *
  524. * @param objectName The feature to be added to the NotificationListener
  525. * attribute
  526. * @param listener The feature to be added to the NotificationListener
  527. * attribute
  528. * @param filter The feature to be added to the NotificationListener
  529. * attribute
  530. * @param handback The feature to be added to the NotificationListener
  531. * attribute
  532. * @exception InstanceNotFoundException X
  533. */
  534. public void addNotificationListener(
  535. ObjectName objectName,
  536. ObjectName listener,
  537. NotificationFilter filter,
  538. Object handback
  539. )
  540. throws
  541. IOException,
  542. InstanceNotFoundException,
  543. java.rmi.RemoteException {
  544. mbeanServerConnector.addNotificationListener(objectName,listener,filter,handback);
  545. }
  546. /**
  547. * @todo Document this method
  548. *
  549. * @param objectName X
  550. * @param listener X
  551. * @exception InstanceNotFoundException X
  552. * @exception ListenerNotFoundException X
  553. * @exception UnsupportedOperationException X
  554. */
  555. public void removeNotificationListener(
  556. ObjectName objectName,
  557. ObjectName listener
  558. )
  559. throws
  560. IOException,
  561. InstanceNotFoundException,
  562. ListenerNotFoundException,
  563. UnsupportedOperationException,
  564. java.rmi.RemoteException {
  565. mbeanServerConnector.removeNotificationListener(objectName,listener);
  566. }
  567. /**
  568. * @todo Document this method
  569. *
  570. * @param objectName X
  571. * @param listener X
  572. * @exception InstanceNotFoundException X
  573. * @exception ListenerNotFoundException X
  574. */
  575. public void removeNotificationListener(
  576. ObjectName objectName,
  577. NotificationListener listener
  578. )
  579. throws
  580. IOException,
  581. InstanceNotFoundException,
  582. ListenerNotFoundException,
  583. java.rmi.RemoteException {
  584. mbeanServerConnector.removeNotificationListener(objectName,listener);
  585. }
  586. /**
  587. *
  588. */
  589. public void removeNotificationListener(
  590. ObjectName objectName,
  591. NotificationListener listener,
  592. NotificationFilter filter,
  593. Object handback)
  594. throws
  595. IOException,
  596. InstanceNotFoundException,
  597. ListenerNotFoundException,
  598. java.rmi.RemoteException {
  599. mbeanServerConnector.removeNotificationListener(objectName,listener,filter,handback);
  600. }
  601. /**
  602. *
  603. */
  604. public void removeNotificationListener(
  605. ObjectName objectName,
  606. ObjectName listener,
  607. NotificationFilter filter,
  608. Object handback)
  609. throws
  610. IOException,
  611. InstanceNotFoundException,
  612. ListenerNotFoundException,
  613. java.rmi.RemoteException {
  614. mbeanServerConnector.removeNotificationListener(objectName,listener,filter,handback);
  615. }
  616. public JMXConnector getJMXConnector() {
  617. return mJMXConnector;
  618. }
  619. }