Professional Documents
Culture Documents
RMI
Server:
Cung
cp
dch
v
RMI
(phng
thc
t
xa)
Client:
Gi
cc
phng
thc
t
xa
c
cung
cp
bi
server.
RMI
-
V
d
Local
Machine
(Client)
SampleServer remoteObject; int s; s = remoteObject.sum(1,2);
1,2
public int sum(int a,int b) { return a + b; }
System.out.println(s);
return
call
lookup
stub
RMI Client
Local Machine
Hot
ng
ca
RMI
Server
RMI
phi
ng
k
vi
mt
dch
v
tra
rm
v
ng
k
tn
(rmiregistry)
Sau
khi
server
c
ng
k,
n
s
ch
cc
yu
cu
RMI
t
cc
client
Nu
mt
dch
v
chuyn
t
server
ny
sang
mt
server
khc,
client
ch
cn
tra
rm
trnh
ng
k
rm
ra
v
tr
mi
Cc
client
RMI
s
gi
cc
thng
ip
RMI
gi
mt
phng
thc
trn
mt
i
tng
t
xa
Hot
ng
ca
RMI
ng
dng
client
yu
cu
mt
tn
dch
v
c
th,
v
nhn
mt
URL
tr
ti
ti
nguyn
t
xa
rmi://hostname:port/servicename
Stub
call
skeleton
RMI Client
Stub
RMI Server
return
Stub: mt i tng y quyn, truyn ti yu cu i tng ti server RMI Ngi pht trin ng dng khng cn quan tm n ti nguyn RMI nm u, n ang chy trn nn no, n p ng y yu cu nh th no -> Client RMI gi mt phng thc trn i tng y quyn
Skeleton
call
skeleton
RMI Client
Stub
RMI Server
return
Skeleton c nhim v lng nghe cc yu cu RMI n v truyn cc yu cu ny ti dch v RMI Skeleton khng cung cp bn ci t ca dch v RMI. N ch ng vai tr nh l chng trnh nhn cc yu cu, v truyn cc yu cu
Computer A
A1
C1- stub
Computer C C1 Skel
A2
B1_stub
C1
B1Skel
B1
Computer B
java.rmi.server.* java.rmi.*
Java
classes
java.rmi.Remote
public
interface
Remote:
1. public
interface
BankAccount
extends
java.rmi.Remote
{
2.
public
void
deposit(oat
amount)
3.
throws
java.rmi.RemoteExcepSon;
4.
public
void
withdraw(oat
amount)
5.
throws
OverdrawnExcepSon,
java.rmi.RemoteExcepSon;
6.
public
oat
getBalance()
7.
throws
java.rmi.RemoteExcepSon;
8. }
Server phi ng k tn vi registry, client s rm kim tn server. S dng lp Use java.rmi.Namingclass ng k tn server vi registry. Trong v d ny, tn server l SAMPLE-SERVER. Trong phng thc main ca i tng server, RMI security manager c to v ci t.
Windows:
> start rmiregistry
Steps
7
&
8:
Start
the
remote
server
objects
&
Run
the
client
Khi
Registry
c
chy,
server
c
th
c
khi
ng
v
s
c
th
c
lu
tr
trong
Registry.
V
nh
bo
mt
ca
Java,
cn
phi
thit
lp
mt
chnh
sch
bo
mt
cho
RMI
bng
thit
lp
java.security.policy
to
the
le
policy.all
elpis:~/rmi> java Djava.security.policy=policy.all SampleServerImpl elpis:~/rmi> java Djava.security.policy=policy.all SampleClient