rmiinvocationhandler.java

来自「jmx codeJava源码」· Java 代码 · 共 54 行

JAVA
54
字号

package book.jmx.examples;

import java.util.*;
import java.net.*;
import java.lang.reflect.*;
import java.rmi.*;


public class RMIInvocationHandler 
    implements InvocationHandler, RMIConnectorConstants {

  /* Remote reference to the connector server. */
  private MBeanServerInvoker invoker = null;

  /* Property values. */
  private String host = null;
  private String name = null;
  private int port    = 1099;
  
  
  /* Constructor */

  public RMIInvocationHandler(Properties props) 
      throws NotBoundException, MalformedURLException,
      RemoteException {
          
    /* Retrieve properties for remote connection. */
    host = props.getProperty(HOST, "localhost");
    port = Integer.parseInt(props.getProperty(PORT, "1099"));  
    name = props.getProperty(REMOTE_NAME,"jmx/RMIConnector");
    
    /* Retrieve the stub implementing MBeanServerInvoker */
    String lookup = "//" + host + ":" + port + "/" + name;
    invoker = (MBeanServerInvoker)Naming.lookup(lookup);        
  }   

  
  /* InvocationHandler implementation */

  public Object invoke(Object proxy, Method method,
                       Object[] args) throws Throwable {
    
    /* Create and initialize serializable MI object. */                   
    MethodInvocation mi = new MethodInvocation(method);
    mi.setParams(args);

    /* Remote call to the connector server. */
    return invoker.invoke(mi);
  }
      
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?