Advertisement
aironman

mss-jmx

Nov 7th, 2013
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MyMain {
  2.  
  3. public static void main(String[] args) throws InterruptedException {
  4.  
  5. //initializing spring context without applicationContext.xml
  6. AnnotationConfigApplicationContext ctxAnnotationConfigApplicationContext = new AnnotationConfigApplicationContext(MainConfig.class, JmxConfig.class);
  7. MBeanServer server = ManagementFactory.getPlatformMBeanServer();
  8.  
  9. ObjectName name = null;
  10. QueryExp query = null;
  11. try {
  12.  
  13. name = new ObjectName("jboss.ws:service=ServerConfig");
  14. MBeanInfo mbeanInfo = server.getMBeanInfo(name);
  15.  
  16. org.jboss.ws.common.management.AbstractServerConfigMBean dispatcherMBean = MBeanServerInvocationHandler.newProxyInstance(server, name,
  17. org.jboss.ws.common.management.AbstractServerConfigMBean.class, false);
  18.  
  19. System.out.println("host: " + dispatcherMBean.getWebServiceHost());
  20.  
  21. //sleeping each second
  22. while (true) {
  23. // System.out.println("sleeping!");
  24. Thread.sleep(1000);
  25. }
  26.  
  27. } catch (MalformedObjectNameException e) {
  28.  
  29. e.printStackTrace();
  30. System.out.println("ERROR! MalformedObjectNameException"+ e.getMessage());
  31. } catch (IntrospectionException e) {
  32. e.printStackTrace();
  33. System.out.println("ERROR! IntrospectionException"+ e.getMessage());
  34. } catch (InstanceNotFoundException e) {
  35. e.printStackTrace();
  36. System.out.println("ERROR! InstanceNotFoundException. " + e.getMessage());
  37. } catch (ReflectionException e) {
  38. e.printStackTrace();
  39. System.out.println("ERROR! ReflectionException"+ e.getMessage());
  40. } catch (Throwable th) {
  41. th.printStackTrace();
  42.  
  43. System.out.println("ERROR! Throwable!" + th.getCause().getMessage());
  44.  
  45. }
  46.  
  47. }
  48. }
  49.  
  50. @Configuration
  51. public class JmxConfig {
  52. @Inject
  53. private Environment environment;
  54.  
  55. @Bean(name = "jmxConnectorServer")
  56. public JMXConnectorServer getConnector() throws JMException, IOException {
  57. return getConnectorServerFactoryBean().getObject();
  58. }
  59.  
  60. @Bean
  61. public ConnectorServerFactoryBean getConnectorServerFactoryBean() throws JMException, IOException {
  62. ConnectorServerFactoryBean factory = new ConnectorServerFactoryBean();
  63. factory.setObjectName("jboss.sip:type=SipApplicationDispatcher");
  64. factory.setServiceUrl("service:jmx:rmi:///jndi/rmi://localhost:" + getJmxPort() + "/jmxrmi");
  65. factory.setServer(getMBeanServer());
  66. factory.setThreaded(true);
  67.  
  68. return factory;
  69. }
  70.  
  71. protected int getJmxPort() {
  72. return parseInt(environment.getProperty("jmx.port", "1099"));
  73. }
  74.  
  75. @Bean(name = "mbeanServer")
  76. public MBeanServer getMBeanServer() {
  77. return getMBeanServerFactoryBean().getObject();
  78. }
  79.  
  80. @Bean
  81. public MBeanServerFactoryBean getMBeanServerFactoryBean() {
  82. MBeanServerFactoryBean factory = new MBeanServerFactoryBean();
  83. factory.setLocateExistingServerIfPossible(true);
  84.  
  85. return factory;
  86. }
  87.  
  88. @Bean(name = "registry")
  89. public Registry getRegistry() throws Exception {
  90. return getRmiRegistryFactoryBean().getObject();
  91. }
  92.  
  93. @Bean
  94. public RmiRegistryFactoryBean getRmiRegistryFactoryBean() throws Exception {
  95. RmiRegistryFactoryBean factory = new RmiRegistryFactoryBean();
  96. factory.setPort(getJmxPort());
  97. factory.setAlwaysCreate(true);
  98.  
  99. return factory;
  100. }
  101. }
  102.  
  103. @Configuration
  104. public class MainConfig {
  105.  
  106. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement