package mysh.cluster;

import org.junit.Ignore;
import org.junit.Test;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

@Ignore
public class RMITest {
	public static interface RI extends Remote {
		int getValue() throws RemoteException;
	}

	public static class RIImpl implements RI {

		@Override
		public int getValue() {
			return 1;
		}
	}

	int port = 8030;

	@Test
	public void server() throws Exception {
		Registry registry = LocateRegistry.createRegistry(port);

		RIImpl ro = new RIImpl();
		Remote expRO = UnicastRemoteObject.exportObject(ro, port + 1);
		registry.bind("ro", expRO);

		Thread.sleep(10000000);
	}

	@Test
	public void clientRemoteObj() throws Exception {
		Registry registry = LocateRegistry.getRegistry("mysh", port);

		final RI riClient = (RI) registry.lookup("ro");
		System.out.println(riClient.getValue());
	}


}
