2018년 2월 4일 일요일

방화벽 환경에서의 고정포트 RMI 통신 처리

RMI Server 생성 시 내부적으로는 포트가 2개 열림(하나는 레지스트리 포트, 다른 하나는 실제 데이타 포트)



레지스트리 포트의 경우 서버 설정 시 고정이나 데이타포트의 경우 임의로 열림. (FTP의 Active모드랑 같은 개념인듯)



방화벽문제로 FTP 서버 구현시에도 passive 모드로 포트 고정하여 구현하듯 RMI 서버 설정 시에도 레지스트리 포트, 데이타 포트 고정해야



방화벽 해제 하여 사용이 가능. (아래 샘플의 경우 레지스트리 포트는 8000, 데이타포트는 8001로 설정)



1. RMI 인터페이스 작성

import java.rmi.*;



public interface BatchController extends Remote {
    void executeBatch(String id, String[] args) throws RemoteException;
    String getBatchLog(String id, int seqNo) throws RemoteException;

}



2. RMI 인터페이스 Implemetation 구현

import java.rmi.*;


public class BatchControllerImpl extends UnicastRemoteObject implements BatchController {
    public BatchControllerImpl(int port) throws RemoteException {
        super(port);
    }



    @Override
    public void executeBatch(final String batchId, final String[] args) throws RemoteException {

        // 배치프로그램 재실행

    }



    @Override

    public String getBatchLog(String id, int seqNo) throws RemoteException {

        // 배치로그내용전송

    }

}





3. RMI listening thread 생성

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;


public class ProgramMain {

public static void main(String[] args) throws Exception {

Thread rmiTread = new Thread(new Runnable() {
    public void run() {
        try {
            Registry registry = LocateRegistry.createRegistry(8000);
            registry.rebind("BatchController", new BatchControllerImpl(8001));
        }catch(Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
});
rmiTread.start();

}

}

댓글 없음:

댓글 쓰기

Creating CRC32 Hex string

public String getCRC32HexaString(String paramString) throws Exception  {   byte bytes[] = paramString.getBytes(DEFAULT_CHARSET);   Che...