Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2014 Dell, Inc.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.dell.doradus.management;
 
 
Implements a factory of proxy objects of MBeans/MXBeans which compose a management interface of Doradus-server instance hosted on local or specified host.
 
 public class MBeanProxyFactory {

        
Default JMX-port of Doradus-server. (-9999)
 
     public final int DEFAULT_JMX_PORT = 9999;

    
Creates new factory connected via default port to MBeanServer on local host.

 
     public MBeanProxyFactory() throws IOException {
         this(null, 0);
     }

    
Creates new factory connected via specified port to MBeanServer on specified host.

Parameters:
host
port
Throws:
java.io.IOException
 
     public MBeanProxyFactory(String hostint portthrows IOException {
             if (port <= 0) {
                 port = ;
             }
              = createServerConnection(hostport);
     }

    

Returns:
The URL of MBeanServer.
 
     public JMXServiceURL getJMXServiceURL() {
         return ;
     }

    

Returns:
The connection to MBeanServer.
 
         return ;
     }
    
    
Makes the proxy for ServerMonitorMXBean.

Returns:
A ServerMonitorMXBean proxy object.
Throws:
java.io.IOException
 
         String beanName = . + ":type=" + .;
         return createMXBeanProxy(beanNameServerMonitorMXBean.class);
     }

    
Makes the proxy for StorageManagerMXBean.

Returns:
A StorageManagerMXBean object.
Throws:
java.io.IOException
 
         String beanName = . + ":type=" + .;
         return createMXBeanProxy(beanNameStorageManagerMXBean.class);
     }
     
     
     /////////////////////////////////
 
     private MBeanServerConnection createServerConnection(String hostint portthrows IOException {
              = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi");
             JMXConnector jmxc = JMXConnectorFactory.connect(null);
            return jmxc.getMBeanServerConnection();            
    }
    
    @SuppressWarnings("unused")
	private <T> T createMBeanProxy(String beanNameClass<T> clazzthrows IOException {
        try {
            ObjectName objectName = new ObjectName(beanName);
            return JMX.newMBeanProxy(objectNameclazz);
        } catch (MalformedObjectNameException ex) {
            throw new RuntimeException(ex);
        }
    }
    
    private <T> T createMXBeanProxy(String beanNameClass<T> clazzthrows IOException {
        try {
            ObjectName objectName = new ObjectName(beanName);
            return JMX.newMXBeanProxy(objectNameclazz);
        } catch (MalformedObjectNameException ex) {
            throw new RuntimeException(ex);
        }
    }
    
    private JMXServiceURL jmxServiceURL;
New to GrepCode? Check out our FAQ X