Chap12

Similar documents
Network Programming

rmi_박준용_final.PDF

Microsoft PowerPoint - RMI.ppt

Microsoft PowerPoint - 04-UDP Programming.ppt

10-Java Applet

(Microsoft PowerPoint - Chapter17 RMI.ppt [\310\243\310\257 \270\360\265\345])

歯NetworkKawuiBawuiBo.PDF

Interstage5 SOAP서비스 설정 가이드

자바-11장N'1-502

PowerPoint 프레젠테이션

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class

02 C h a p t e r Java

비긴쿡-자바 00앞부속

PowerPoint 프레젠테이션

자바GUI실전프로그래밍2_장대원.PDF

<4D F736F F F696E74202D20C1A63236C0E520BED6C7C3B8B428B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

웹연동 } 웹 (Web) 환경에서데이터베이스시스템을연동하는방법은다음과같다 } Server Client 구조의통신 (2-Tier) } Server Middleware Client 구조의통신 (3-Tier) 2

개요

JMF3_심빈구.PDF

FileMaker ODBC and JDBC Guide

12-file.key

05-class.key

자바로

Chap7.PDF

Microsoft PowerPoint - ÀÚ¹Ù08Àå-1.ppt

교육2 ? 그림

MasoJava4_Dongbin.PDF

PowerPoint Presentation

<4D F736F F F696E74202D20C1A63139C0E520B9E8C4A120B0FCB8AEC0DA28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

11장.key

<4D F736F F F696E74202D20C1A63233C0E520B1D7B7A1C7C820C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

FileMaker ODBC and JDBC Guide

歯Writing_Enterprise_Applications_2_JunoYoon.PDF

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

JavaGeneralProgramming.PDF

9장.key

gnu-lee-oop-kor-lec10-1-chap10

제11장 프로세스와 쓰레드

01-OOPConcepts(2).PDF

PowerPoint Presentation

자바 프로그래밍

10장.key

목차 JEUS EJB Session Bean가이드 stateful session bean stateful sample 가이드 sample source 결과확인 http session에

Microsoft PowerPoint - Supplement-03-TCP Programming.ppt [호환 모드]

Spring Boot/JDBC JdbcTemplate/CRUD 예제

1

FileMaker 15 ODBC 및 JDBC 설명서

Spring Data JPA Many To Many 양방향 관계 예제

숭실대학교 최종명님의 자바 프로그래밍 강좌

03-JAVA Syntax(2).PDF

슬라이드 1

PowerPoint 프레젠테이션

Microsoft PowerPoint - 14주차 강의자료

Cluster management software

<4D F736F F F696E74202D20C1A63138C0E520C0CCBAA5C6AE20C3B3B8AE28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

문서의 제목 나눔고딕B, 54pt

5장.key

FileMaker ODBC 및 JDBC 가이드

<4D F736F F F696E74202D20C1A63230C0E520BDBAC0AE20C4C4C6F7B3CDC6AE203128B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

JMF2_심빈구.PDF

Microsoft PowerPoint - 03-TCP Programming.ppt

신림프로그래머_클린코드.key

Microsoft PowerPoint - JavaPrimer.ppt [호환 모드]

14-Servlet

09-interface.key

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

ch09

Java

PowerPoint 프레젠테이션

JMF1_심빈구.PDF

Spring Boot

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

PowerPoint Presentation

Microsoft PowerPoint - Java7.pptx

목차 BUG DEQUEUE 의 WAIT TIME 이 1 초미만인경우, 설정한시간만큼대기하지않는문제가있습니다... 3 BUG [qp-select-pvo] group by 표현식에있는컬럼을참조하는집합연산이존재하지않으면결괏값오류가발생할수있습니다... 4

Microsoft PowerPoint - 06-Chapter09-Event.ppt

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

강의자료

(Microsoft PowerPoint - LZVNQBAJWGTC.ppt [\310\243\310\257 \270\360\265\345])

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345])

쉽게 풀어쓴 C 프로그래밍

초보자를 위한 자바 2 21일 완성 - 최신개정판

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드]

歯JavaExceptionHandling.PDF

Microsoft PowerPoint os5.ppt

슬라이드 1

07 자바의 다양한 클래스.key

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

gnu-lee-oop-kor-lec06-3-chap7

제8장 자바 GUI 프로그래밍 II

Analyze Connection Failover Options.ppt

Cluster management software

JAVA PROGRAMMING 실습 09. 예외처리

PowerPoint Presentation

PowerPoint Presentation

PowerPoint Presentation

rosaec_workshop_talk

쉽게 풀어쓴 C 프로그래밊

Transcription:

12 12Java RMI

121 RMI 2

121 RMI 3 - RMI, CORBA

121 RMI RMI RMI (remote object) 4 - ( ) UnicastRemoteObject,

121 RMI 5 class A - class B - ( ) class A a() class Bb()

121 RMI 6 RMI /

121 RMI RMI 1 2 ( 7) 3 ( ) 4 stubskeleton 5 registry 6 - javarmiremote, javarmiserver Remote Remote public interface Remote { } RemoteObject - RMI

122 RMI 1 sayhello() Hello : Hellojava 1 package hello; 82 3 import javarmi*; 4 5 public interface Hello extends Remote { 6 7 public String sayhello() throws javarmiremoteexception; 8 9 } 1) javarmiremote 2) public

122 RMI 9 2 Hello HelloImpl : HelloImpljava 1 package hello; 2 3 import javarmi*; 4 import javarmiserver*; 5 import javanet*; 6 7 public class HelloImpl extends UnicastRemoteObject implements Hello { 8 9 public HelloImpl() throws RemoteException { 10 super(); 11 } 12 13 public String sayhello() throws RemoteException { 14

122 RMI 15 return "Hello World"; 16 } 17 18 public static void main(string[] args) { 19 SystemsetSecurityManager(new RMISecurityManager()); 20 21 try { 22 HelloImpl h = new HelloImpl(); 23 Namingrebind("//localhost/hello", h); 24 Systemoutprintln("Hello Server ready"); 25 } catch (RemoteException re) { 26 Systemoutprintln("Exception in HelloImplmain: " + re); 27 } catch (MalformedURLException mfe) { 28 Systemoutprintln("MalformedURLException in HelloImplmain" + mfe); 29 } 30 } 31 } 10

122 RMI bindrebind 11 rebind() bind(), bind() javarmialreadyboundexception, rebind() RMI URL RMI URL rmi://host:port/object_name hello : Namingrebind("rmi://localhost:1099/hello", h); RMI 1099 1 2 RemoteExceptionthrows

122 RMI % javac -d Hellojava HelloImpljava 12 3 HelloImpl ( ) : HelloClientjava 1 package hello; 2 3 import javarmi*; 4 5 public class HelloClient { 6 7 public static void main(string[] args) { 8 9 SystemsetSecurityManager(new RMISecurityManager()); 10 11 try {

122 RMI 1312 Hello h = (Hello) Naminglookup("rmi://mycomsoongsilackr/hello"); 13 14 String message = hsayhello(); 15 Systemoutprintln("HelloClient: " +message); 16 } catch(exception e) { 17 Systemoutprintln("Exception in main: "+ e); 18 } 19 } 20 } 4 rmic stubskeleton, jar % rmic -d hellohelloimpl % jar cvf hellojar hello/*class 1) rmicstubskel

122 RMI 14 5 rmiregistry % unsetenv CLASSPATH % rmiregistry & [1] 7382 6 : javapolicy 1 grant{ 2 permission javanetsocketpermission "*:1024-65535", 3 "connect,accept"; 4 permission javanetsocketpermission "*:80", "connect"; 5 }; 7 rmi % java -Djavasecuritypolicy=javapolicy hellohelloimpl Hello Server ready

122 RMI 15 7 % java -Djavasecuritypolicy=javapolicy hellohelloclient HelloClient: Hello World RMI : HelloAppletjava 1 package hello; 2 3 import javaawt*; 4 import javaapplet*; 5 import javarmi*; 6 7 public class HelloApplet extends Applet { 8 String message = ""; 9 10 public void init() {

122 RMI 1611 try { 12 Hello obj = (Hello)Naminglookup("//"+getCodeBase() gethost() + "/hello"); 13 message = objsayhello(); 14 } catch(exception e) { 15 Systemoutprintln("HelloApplet exception: " + egetmessage()); 16 } 17 } 18 19 public void paint(graphics g) { 20 gdrawstring(message, 25, 50); 21 } 22 }

122 RMI 17 : Hellohtml 1 <html><title>hello World</title> 2 <applet code=hellohelloapplet archive=hellojar width=400 height=400> 3 </applet> 4 </html> % javac -d HelloAppletjava % jar cvf hellojar hello/*class % appletviewer Hellohtml

123 RMI RMI TCP/IP 3 Stub/Skeleton - Remote Reference - Transport - 18 RMI, (marshal stream) (marshaling) (unmarshaling)

123 RMI 19 : SetMessagejava 1 package message; 2 3 import javarmi*; 4 5 public interface SetMessage extends Remote { 6 public void setmessage(string msg) throws RemoteException ; 7 public String getmessage() throws RemoteException ; 8 } : SetMessageImpljava 1 package message; 2 3 import javarmi*; 4 import javarmiserver*; 5 import javanet*;

123 RMI 20 6 7 public class SetMessageImpl extends UnicastRemoteObject implements SetMessage { 8 private String msg; 9 10 public SetMessageImpl() throws RemoteException { 11 super(); 12 msg = ""; 13 } 14 15 public String getmessage() throws RemoteException { 16 return msg; 17 } 18 19 public void setmessage(string msg) throws RemoteException { 20 thismsg = msg; 21 Systemoutprintln("message: "+msg); 22 }

123 RMI 21 23 } 24 25 class SetMessageServer { 26 public static void main(string args[]) { 27 SystemsetSecurityManager(new RMISecurityManager()); 28 try { 29 SetMessageImpl s = new SetMessageImpl(); 30 Namingrebind("setmessage", s); 31 Systemoutprintln("SetMessage Server is ready"); 32 } catch (RemoteException e) { 33 Systemoutprintln(e); 34 } catch (Exception ex) { 35 Systemoutprintln(ex); 36 } 37 } 38 }

123 RMI 22 : SetMessageClientjava 1 package message; 2 3 import javaawt*; 4 import javaawtevent*; 5 import javaapplet*; 6 import javarmi*; 7 8 public class SetMessageClient extends Applet implements Runnable, ActionListener { 9 Thread runner; 10 SetMessage obj; 11 String message = ""; 12 TextField input; 13 14 public void init() { 15 setlayout(new BorderLayout()); 16 input = new TextField(10); 17 inputaddactionlistener(this); 18 add("south", input);

123 RMI 23 19 runner = new Thread(this); 20 runnerstart(); 21 22 try { 23 obj = (SetMessage) Naminglookup("//"+getCodeBase()getHost() + "/setmessage"); 24 } catch (Exception e) { 25 Systemoutprintln(e); 26 } 27 } 28 29 public void run() { 30 while(true) { 31 try { 32 Threadsleep(500); 33 message = objgetmessage(); 34 } catch(exception ex) { 35 message = extostring(); 36 } 37 repaint();

123 RMI 24 38 } 39 } 40 41 public void paint(graphics g) { 42 gdrawstring(message, 25, 25); 43 } 44 45 public void actionperformed(actionevent e) { 46 Component c = (Component) egetsource(); 47 48 if(c == input) { 49 try { 50 objsetmessage(inputgettext()); 51 } catch (Exception ex) {} 52 inputsettext(""); 53 } 54 } 55 }

123 RMI 25 : SetMessageClienthtml 1 <table border=1><tr> 2 <td><applet code=messagesetmessageclientclass archive=messagejar 3 width=300 height=100> 4 </applet> 5 <td><applet code=messagesetmessageclientclass archive=messagejar 6 width=300 height=100> 7 </applet> 8 </tr> 9 </table>

124 RMI (callback) 26 register() update()

124 RMI (callback) : RMIChatServerjava 1 package rmichat; 2 3 import javarmi*; 4 5 public interface RMIChatServer extends Remote { 6 public void register(rmichatclient client) throws RemoteException; 7 public void broadcast(string msg) throws RemoteException; 8 public void unregister(rmichatclient client) throws RemoteException; 9 } 27 register() unregister(), broadcast()

124 RMI (callback) 28 : RMIChatServerImpljava 1 package rmichat; 2 3 import javarmiserver*; 4 import javarmi*; 5 import javautil*; 6 7 public class RMIChatServerImpl extends UnicastRemoteObject implements RMIChatServer { 8 Vector clientlist; 9 public RMIChatServerImpl() throws RemoteException { 10 super(); 11 clientlist = new Vector(5, 5); 12 } 13 14 public synchronized void register(rmichatclient client) throws RemoteException { 15 clientlistaddelement(client); 16 } 17

124 RMI (callback) 29 18 public void broadcast(string msg) throws RemoteException { 19 synchronized(clientlist) { 20 Enumeration e = clientlistelements(); 21 while(ehasmoreelements()) { 22 RMIChatClient c = (RMIChatClient) enextelement(); 23 csetmessage(msg); 24 } 25 } 26 } 27 28 public synchronized void unregister(rmichatclient client) throws RemoteException { 29 clientlistremoveelement(client); 30 } 31 32 public static void main(string args[]) { 33 SystemsetSecurityManager(new RMISecurityManager()); 34 try { 35 RMIChatServerImpl c = new RMIChatServerImpl(); 36 Namingrebind("rmi://mycomsoongsilackr/chat", c);

124 RMI (callback) 37 Systemoutprintln("RMI Chat Server is ready"); 38 } catch(exception ex) { 39 Systemoutprintln(ex); 40 } 41 } 42 } : RMIChatClientjava 1 package rmichat; 2 3 import javarmi*; 4 5 public interface RMIChatClient extends Remote { 6 public void setmessage(string msg) throws RemoteException; 7 } 30 RMIChatClient setmessage()

124 RMI (callback) 31 : RMIChatClientAppjava 1 package rmichat; 2 3 import javaawt*; 4 import javaawtevent*; 5 import javaapplet*; 6 import javarmi*; 7 import javarmiserver*; 8 9 public class RMIChatClientApp extends Frame implements RMIChatClient, ActionListener { 10 TextArea display; 11 TextField input; 12 RMIChatServer server; 13 14 public RMIChatClientApp() { 15 super("chat Client"); 16 setlayout(new BorderLayout()); 17 add("center", display = new TextArea()); 18 displayseteditable(false);

124 RMI (callback) 32 19 addwindowlistener(new WindowAdapter() { 20 public void windowclosing(windowevent e) { 21 setvisible(false); 22 try { 23 serverunregister(rmichatclientappthis); 24 } catch(exception ex) {} 25 dispose(); 26 Systemexit(0); 27 } 28 }); 29 30 add("south", input = new TextField()); 31 inputaddactionlistener(this); 32 33 try { 34 UnicastRemoteObjectexportObject(this); 35 server = (RMIChatServer) Naminglookup("rmi://mycomsoongsilackr/ chat"); 36 serverregister(this); 37 } catch (Exception ex) {

124 RMI (callback) 33 38 displayappend(extostring()); 39 } 40 setsize(400, 300); 41 setvisible(true); 42 } 43 44 public synchronized void setmessage(string msg) { 45 try { 46 displayappend(msg + ""); 47 } catch (Exception e) { 48 displayappend(etostring()); 49 } 50 } 51 52 public void actionperformed(actionevent e) { 53 Component c = (Component) egetsource(); 54 55 if(c == input) { 56 try { 57 serverbroadcast(inputgettext());

124 RMI (callback) 34 58 inputsettext(""); 59 } catch (Exception ex) { 60 displayappend(extostring()); 61 } 62 } 63 } 64 65 public static void main(string args[]) { 66 new RMIChatClientApp(); 67 } 68 }

124 RMI (callback) RMI : RMIChatClientAppletjava 351 package rmichat; 2 3 import javaawt*; 4 import javaawtevent*; 5 import javaapplet*; 6 import javarmi*; 7 import javarmiserver*; 8 9 public class RMIChatClientApplet extends Applet implements RMIChatClient, ActionListener { 10 TextArea display; 11 TextField input; 12 RMIChatServer server; 13 14 public void init() {

124 RMI (callback) 36 14 public void init() { 15 setlayout(new BorderLayout()); 16 add("center", display = new TextArea()); 17 displayseteditable(false); 18 add("south", input = new TextField()); 19 inputaddactionlistener(this); 20 21 try { 22 UnicastRemoteObjectexportObject(this); 23 Systemoutprintln(getCodeBase()getHost()); 24 server = (RMIChatServer) Naminglookup("// + getcodebase()gethost() + "/chat"); 25 serverregister(this); 26 } catch (Exception ex) { 27 displayappend(extostring()); 28 } 29 } 30

124 RMI (callback) 37 31 public synchronized void setmessage(string msg) { 32 try { 33 displayappend(msg + ""); 34 } catch (Exception e) { 35 displayappend(etostring()); 36 } 37 } 38 39 public void actionperformed(actionevent e) { 40 Component c = (Component) egetsource(); 41 42 if(c == input) { 43 try { 44 serverbroadcast(inputgettext()); 45 inputsettext(""); 46 } catch (Exception ex) { 47 displayappend(extostring());

124 RMI (callback) 38 RMI HTMLapplet HTMLConverter

125 JDBC + RMI = 3 tier? 39 2-tier /, 2-tier 3-tiermulti-tier / JDBC 2-tier Alumnijava RMI (middle tier) 3-tier / AlumniRecord AlumniRecord (serializable)

125 JDBC + RMI = 3 tier? 40 % psql alumni alumni=> Database = alumni +------------------+----------------------------------+----------+ Owner Relation Type +------------------+----------------------------------+----------+ jmchoi cs table +------------------+----------------------------------+----------+ alumni=> cs Table = cs +----------------------------------+----------------------------------+-------+ Field Type Length +----------------------------------+----------------------------------+-------+ num varchar 10 name varchar 10 phone varchar 25 company varchar 40 email varchar 40 +----------------------------------+----------------------------------+-------+

125 JDBC + RMI = 3 tier? 41