Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


JRMP, IIOP typeÀÇ RMIºÐ»ê °´Ã¼(RMI over IIOP)
 
JRMP, IIOP typeÀÇ RMIºÐ»ê °´Ã¼(RMI over IIOP)ÀÇ °³³ä°ú »ùÇÃÇÁ·Î±×·¥À» º¸µµ·Ï ÇÑ´Ù. ( 2003/02/28 ) 41
Written by specular - ÀüÈ«¼º
1 of 1
 
¡Ø RMI over IIOP
    RMI over IIOP´Â IBM°ú Sun¿¡ ÀÇÇØ °³¹ßµÈ°ÍÀ¸·Î, IIOP¿¡ ´ëÇÑ »õ·Î¿î RMI ¹öÁ¯ÀÔ´Ï´Ù. Ãʱâ RMI(Remote method invocation)Àº JRMP(Java Remote Method Protocol)À» »ç¿ëÇߴµ¥, CORBA¿Í interoperability¸¦ Áö¿øÇϱâ À§ÇØ RMI over IIOP¸¦ Á¦½ÃÇÏ°Ô µÈ °ÍÀÔ´Ï´Ù.

Before RMI-IIOP


Introducing RMI-IIOP

 
 
    RMI ºÐ»ê°´Ã¼´Â JRMP, IIOPµÎ°¡Áö ¹æ½ÄÀ¸·Î °³¹ß µÇ¾î Áú¼ö ÀÖ½À´Ï´Ù. java.rmi.server.UnicastRemoteObject¸¦ extends ¹Þ¾Æ servant class¸¦ Á¤ÀÇÇÒ¶§´Â JRMP·Î °³¹ß µÇ¾î Áö´Â °ÍÀÌ°í, javax.rmi.PortableRemoteObject¸¦ extends¹ÞÀ» °æ¿ì´Â IIOP·Î °³¹ß µÇ¾î Áö´Â °ÍÀÌ´Ù. ¹°·Ð, servant classÀÇ super class type¿¡ ÀÇÇØ JRMP, IIOP°¡ °áÁ¤µÈ´Ù°í À̾߱â ÇÒ¼ö´Â ¾ø½À´Ï´Ù. servant class°¡ super class¾øÀÌ °³¹ß µÇ¾îÁö°í, exportObjectÀ» UnicastRemoteObject¸¦ ÀÌ¿ëÇϸé, JRMP typeÀÌ°í, PortableRemoteObject¸¦ ÀÌ¿ëÇϸé, IIOP typeÀÌ µÇ´Â °ÍÀÔ´Ï´Ù.
±×¸®°í, jdkÀÇ naming service¿¡´Â rmiregistry, tnameserv°¡ Àִµ¥, rmiregistry´Â JRMP¸¦ Áö¿øÇÏ°í, tnameserv´Â IIOP¸¦ Áö¿øÇÕ´Ï´Ù.
ÀÚ ±×·³ ´ÙÀ½ÀÇ ´Ü°èº° Äڵ带 º¸°Ú½À´Ï´Ù.

    1. Remote interface °³¹ß : JRMP, IIOP³ª remote interface °³¹ßÀº µ¿ÀÏ ÇÕ´Ï´Ù.
import java.rmi.*;

public interface Echo extends Remote 
{
	public String sayEcho(String name) 
		throws RemoteException;
}
    2. Servant class °³¹ß : JRMP typeÀ¸·Î °³¹ßÇÏ°íÀÚ ÇÒ°æ¿ì¿¡´Â java.rmi.server.UnicastRemoteObject, IIOP typeÀ¸·Î °³¹ßÇÏ°íÀÚ ÇÒ°æ¿ì¿¡´Â javax.rmi.PortableRemoteObject·Î ºÎÅÍ »ó¼ÓÀ» ¹Þ¾Æ Á¤ÀÇ ÇÒ¼ö ÀÖ½À´Ï´Ù. ±×·¯³ª, Dual Export(ÇϳªÀÇ ºÐ»ê°´Ã¼¸¦ °®°í, JRMP, IIOP µÎ°¡Áö typeÀ¸·Î export)Çϱâ À§ÇØ ´ÙÀ½°ú °°ÀÌ Á¤ÀÇ Çß½À´Ï´Ù.
import java.rmi.*;
import javax.rmi.*;
import java.rmi.server.*;

public class EchoImpl 
	implements Echo 
{
	
	public EchoImpl() 
		throws RemoteException{ }
	
	public String sayEcho(String name) 
	{
		System.out.println(name);
		return "Hi..."+name;
	}
}
    3. Server application °³¹ß : °³¹ßµÈ ºÐ»ê°´Ã¼¸¦ JRMP naming serviceÀÎ rmiregistry¿Í IIOP naming serviceÀÎ tnameserv¿¡ °¢°¢ exportÇÔ.
import java.rmi.*;
import java.rmi.server.*;
import javax.rmi.*;
import javax.naming.*;
import java.util.*;

public class Server 
{
	public static void main(String args[]) 
		throws Exception 
	{
		EchoImpl serv = new EchoImpl();
		
		String jrmpUrl="rmi://localhost:1099";
		String jrmpFactory="com.sun.jndi.rmi.registry.RegistryContextFactory";
		Hashtable jrmpEnv=new Hashtable();
		jrmpEnv.put(Context.PROVIDER_URL, jrmpUrl);
		jrmpEnv.put(Context.INITIAL_CONTEXT_FACTORY,jrmpFactory);
		Context jrmpCtx = new InitialContext(jrmpEnv);
		UnicastRemoteObject.exportObject(serv);
		jrmpCtx.rebind("MyEcho",serv);
		
		String iiopUrl="iiop://localhost:900";
		String iiopFactory="com.sun.jndi.cosnaming.CNCtxFactory";
		Hashtable iiopEnv=new Hashtable();
		iiopEnv.put(Context.PROVIDER_URL, iiopUrl);
		iiopEnv.put(Context.INITIAL_CONTEXT_FACTORY,iiopFactory);
		Context iiopCtx = new InitialContext(iiopEnv);
		PortableRemoteObject.exportObject(serv);
		iiopCtx.rebind("MyEcho",serv);
		
		System.out.println("Server is ready...");		
	}
} 	
    4. Client Application °³¹ß : naming service¸¦ ÅëÇØ ºÐ»ê°´Ã¼ÀÇ remote reference¸¦ ¾ò¾î³»°í, remote method¸¦ È£Ãâ...
import java.rmi.*;
import javax.rmi.*;
import javax.naming.*;
import java.util.*;

public class Client 
{
	public static void main(String args[]) 
		throws Exception 
	{
		System.out.println("### to the rmiregistry : JRMP -------------------");
		String jrmpUrl="rmi://localhost:1099";
		String jrmpFactory="com.sun.jndi.rmi.registry.RegistryContextFactory";
		Hashtable jrmpEnv=new Hashtable();
		jrmpEnv.put(Context.PROVIDER_URL, jrmpUrl);
		jrmpEnv.put(Context.INITIAL_CONTEXT_FACTORY,jrmpFactory);
		Context jrmpCtx = new InitialContext(jrmpEnv);
		
		Object obj = jrmpCtx.lookup("MyEcho");
		System.out.println(obj.getClass().getName());
		Echo echo = (Echo)PortableRemoteObject.narrow(obj,Echo.class);
		System.out.println(echo.sayEcho("HongSeong"));
		
		System.out.println("### to the tnameserv : IIOP -------------------");
		String iiopUrl="iiop://localhost:900";
		String iiopFactory="com.sun.jndi.cosnaming.CNCtxFactory";
		Hashtable iiopEnv=new Hashtable();
		iiopEnv.put(Context.PROVIDER_URL, iiopUrl);
		iiopEnv.put(Context.INITIAL_CONTEXT_FACTORY,iiopFactory);
		Context iiopCtx = new InitialContext(iiopEnv);
		
		obj=iiopCtx.lookup("MyEcho");
		System.out.println(obj.getClass().getName());
		echo=(Echo)PortableRemoteObject.narrow(obj,Echo.class);
		System.out.println(echo.sayEcho("HongSeong"));
	}
}
    5. Compile
	prompt>javac *.java
    6. Stub,Skeleton »ý¼º
	prompt>rmic EchoImpl   		==> JRMP type Stub,Skeleton »ý¼º
	prompt>rmic -iiop EchoImpl		==> IIOP type Stub,Skeleton »ý¼º
    ¡ß ½Ç Çà
	1. Naming service start
		prompt>rmiregistry
		prompt>tnameserv
		
	2. Server App start
		prompt>java Server
		
	3. Client App start
		prompt>java Client
		### to the rmiregistry : JRMP -------------------
		EchoImpl_Stub
		Hi...HongSeong
		### to the tnameserv : IIOP -------------------
		_Echo_Stub
		Hi...HongSeong
		
   
2001.05.17 written by Jeon HongSeong
 
1
References
 
http://www.javaworld.com/javaworld/jw-12-1999/jw-12-iiop.html
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD