liurunyu
2023-11-20 aab5b6fc250e074c8cac9e5d244bab011b9d9a32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.dy.common.mw.channel.rmi;
 
import java.rmi.Naming;
import org.apache.logging.log4j.* ; 
 
public class RmiClient {
 
    private static final Logger log = LogManager.getLogger(RmiClient.class.getName()) ;
 
    private String rmiServerIp;
    private Integer rmiServerPort;
    private String rmiServerContext ;
    
    public RmiClient(String rmiServerIp, Integer rmiServerPort, String rmiServerContext){
        this.rmiServerIp = rmiServerIp ;
        this.rmiServerPort = rmiServerPort ;
        this.rmiServerContext = rmiServerContext ;
    }
    
    /**
     * 得到中间件RMI
     * @return RmiFrameWork
     */
    public RmiFrameWork getRmiInterface() {
        String rmiServerUrl = "rmi://" + this.rmiServerIp + ":" + this.rmiServerPort + "/" + this.rmiServerContext ;
        RmiFrameWork rmiIntf = null;
        try {
            rmiIntf = (RmiFrameWork) Naming.lookup(rmiServerUrl);
        } catch (Exception e) {
            log.error("连接RMI服务:" + rmiServerUrl + "时出错。", e);
        }
        return rmiIntf;
    }
 
}