Vous êtes sur la page 1sur 59

! " #$ !

% &'
' '$ ! ( '
) $$
' '$ $ ! " #$ ( '
* $$ +
, -&./-0 $ ! (

' ' '


" #$ % " #$ % " #$ %
' ' '

1' " *
- $ $
3 ' &$' 4
% 5 6 ! ! ' %
" #$ ( '
. ' '
- $ ! ' &$' ' '$ & (7
* $ * $
% $ * !
1- 1 $ - &. %
)183 $$ )(7 1 * 8 + 3
!) 9 $ ! ' ( '* * " #$
: 1 ; 1 $ ; :
$ ' ' $
< $ ) )
)1830 : :
'$ '
3 # 4 $'$ $$ ( '
: :
2
< $ $ 0 ' * ' '
# 1- &1 ;
;
3 " ! '
9' ' $ 0 % $ >
- " $* ' '$ ?
' %
' ' 4
# 4$ $'$ '
3 " ! ' '$
$ "
- ' ' > ' '$ ' 4$'$
- $ " $ ' 7 !' '$ '
$ ' ( ! "$

/ $ 4 ' '$ $?$ $


3 # % $ $'$ ' '$

=
' * * $
, 4
3 # 4 (7 & $ *
$ ' $$
$
! '' ' ' " #$
)183 % $ ' 1- &1 ;
' '$ ' !$ *
, " 0
$
$
. $$ &
1- 0 $ 0 $'$ '
$$
@
$$ $
- 0 ' '$
' $
$$ 0 $ 1- &1 ;
! ' '$ B ! '
' '$ ? ' !
. ' '$ ' * !
1 ! ' ! ' '$ 0 $
) $ 4 '' ' '$ *
' $ ( * !
) !' '$ $ 4 ' '
'' ' '$
. '' !' '$ 0
! ' ' '$ ''
A
3 ' ' 0

- &
-

! , *

! $$ $$

"
# 1' 1'

C
E '$ ! ' '
'
E '$ $$ * ' ' '
E '$ $ $$
/ ' ' '$
E '$ ' '' $ * $
$
, ( ' '$ & %" ' * $
$?$ ' $?$ *
* + ' '$ ' *
* ? ! ! '

D
/ ' ' '$
- * ! '
- * ! '

3 ' 5 6 $
3 $ '$ '
' !
/ ' ' '$ $$
&
; $
3 * , - ./- + '
$$ *

F
< $ ' ' ! ! ' 4
H ' # $$ ''
! (7
' '0 ''
H ' '' ! (7
3 " * ! ! ' $ '
%'
2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! ' " $*
- ( ! $' 4 ' '
$$ ,- ' $

G
- + +
- + 4 '
$$ 1 ;
1# 4
. ! ' ( 4
' !
. ' '
* ! ! %

H $ '$ '
'

H ' $#
' $ '$
! '
' ' * ! ! !
( 4
* ' ' * !
! %
H! ' ' $ % ' * 4 !
$# ! ' !
! % ' ( #$ !
! ' 0 $$ 0 % $
NoSuchObjectException ' ' ! (7
StubNotFoundException ( ! '' '
UnknowHostException $ ! '' '
AlreadyBoundException $ ' 4 ! (7 '74 '
ConnectException % '
- ! $ ! % '
getCause() RemoteException
% $ ! 0 ' '
public interface IRectangle extends Remote {

public int calculSurface(Rectangle rect)


throws RemoteException;

public Rectangle decalerRectangle(Rectangle rect,


int x, int y) throws RemoteException;
}
H ' * * 0 "
$# " $ !$ *
H ! $ '$ ' !
) $ ! 4
' ! %
! $ &: * ' (

2
H 1 $ ' '
!
public class Rectangle implements Serializable {

public int x1, x2, y1, y2;

public Rectangle(int x1, int y1, int x2, int y2){


this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}

public String toString() {


return "("+x1+","+y1+")("+x2+","+y2+")"; }
}
L ( ( $
=
! "
H $ '$ !
UnicastRemoteObject
4 $$ , -
H! (7 $ '$ ! 5 ! % 6
%
' 0 ' '$ ' 4
$$ + , -
. ! (7 $ '$ ! ! % * !
% $ $
H! (7 $ ! %' *
/ %$
H ' $ UnicastRemoteObject
H ' super();
- ' %' !
UnicastRemoteObject.exportObject(this);
H ' '
* ! RemoteException
@
!
% $ ! Irectangle
public class RectangleImpl implements Irectangle {

public int calculSurface(Rectangle rect)


throws RemoteException {
return ((rect.x2 - rect.x1)*(rect.y2 - rect.y1)); }

public Rectangle decalerRectangle(Rectangle rect,


int x, int y) throws RemoteException {
return new Rectangle(rect.x1 + x, rect.y1 + y,
rect.x2 + x, rect.y2 + y); }

public RectangleImpl() throws RemoteException {


UnicastRemoteObject.exportObject(this); } }
H ' ! 5 60 41 ;
4 ! % RemoteException
H $ '$ ! ' $
! ' Remote ( 4
A
#
. ' ' ''
! (7 $ '$ !
. 5 "6 0
H " '4 4 ' :
. (7 # " Naming
; ! (7
J .1H $ rmi://hote:port/nomObj
$ $ *
"
* ' "
$)(7 $ '4 (7 '
' ' ' "
' ! M " '

C
#
H $ "
. %&H % $ rmiregistry [port]
N > start rmiregistry [port]
$# 0 ' $' !'
"
- ' GFF
- " ( '
) (7 "
J $ (7 : 4 ! %'
"
) ' java.rmi.registry.LocateRegistry
public static Registry createRegistry(int port)
throws RemoteException
H " $ !' '
$#
D
#
java.rmi.Naming
@ ' * (7 ' '
'' # % O 3-;
void bind(String name, Remote obj)
(7 $ name '74 (7 $
void rebind(String name, Remote obj)
(7 $ name0 ' ' '
(7 & $ %
void unbind(String name)
$ " '' ! (7 $$' name
String[] list(String name)
1 ! $( $ (7 ' "
Remote lookup(String name)
1 '' ! (7 $ ' $#
% NotBoundException ' (7 ' "
3 ( name @ ' $ .1H " 1 ;
F
$
- ' 4 0
' ' (
* :
. rmic
- % $ $ rmic RectangleImpl
) $# 4 rmic $ *
$ '$ !
9' # $ $ * $
RectangleImpl_Stub.java
-keep rmic :
- $

2G
' ! 1 ;$
$ "
try {
&& 5 6 ! (7
RectangleImpl rect = new RectangleImpl();

&& $ ! (7 $5 1 6 "
Naming.rebind("opRect",rect);
}
catch (Exception e) { ... }

3 ! %' rmiregistry
) * " '
$ scinfr222 ' "

2
'
% 4 '
Rectangle r1, r2;
r1 = new Rectangle(10, 10, 20, 30);

&& $ " $ '


&& " ' ! (7 $$' 5 1 6
IRectangle opRectangle = (IRectangle)
Naming.lookup("rmi://scinfr222/opRect");

&& '' ( 0 $ $ '


&& ! (7 1 $ %
int surface = opRectangle.calculSurface(r1);
r2 = opRectangle.decalerRectangle(r1, 15, 10);

System.out.println(" surface de r1 = "+surface);


System.out.println(" position de r2 = "+r2);

2
1' +
(7 ' " 0 (7
$ '$ ! ' ' * Remote
* (7 $ '$ IRectangle
$$ % $ RectangleImpl ' '
) ' # ''
RectangleImpl_Stub
H ' * %" ! # 4 !
1 ;$ '
- $ 0 IRectangle
- ( ! * % $
$

22
%
H ! $' =
' $# '
$#
$ '$
) ' # '' (7
! $ '$
H! (7 '0 ' # ! (7
- " $ ' $
! $ '$ (7
? $# ? "
H $# '$ ' '
? $ '

2=
&
) ! % $ ' '
. $'

( !
$'
( +
/ %$ " >
1 '' $
1' ' '' ! $'
L $
/ ' ' ! '
* ' '$ 7 M ' $$
2@
&
% $ $ '$ $%
. ' '$ ! ( ' # ' & '
(
/! ' '$ ( $ ! ( '
* ! ? $
'
; ! ' 0 ' (
. ' * ' ! ( ' *
' ( '
!

" # $
" % &
2A
&
; ! ' ' ( '
!

# $
" %
# $
" % &
. $' ! $$ (
'
H $# "
! 4 (7 $ '$ ! $
$

2C
&
;$ '$ ! (
!

&& $' * ' ! ( '


" # $ " !
' #( ) (* $%
&

&& $' 4 ! # ! ( '


+ #$ !
' !
, # $
- . #( )// 000/ ($%
# $% &
# $ ! & &

&& * 5 6 % ! (7
#$ " !
#$% &
&
2D
&
;$ '$ ! ( '
!

&& (
1 %

&& ' ( '


, 2%

&& $ ! (
' # $
" !
1 # $%
&

&& ' $ ! (
' # $
" !
1 # $% &
2F
&
;$ '$ ! ( '
&& $' ' $ * '
' # " $ !
, " %
%
&& $ (
# ,2% 3 1 #$% **$
' !
, # $ 1 4 # $%
" # $% &
# $ ! &
&

&& % ! (7 (
#$ " !
#$%
1 , " #$% &
&
=G
&
H $ ! ( '
, " #$%
- #( (5 $%
# ,6% 3,7% **$ !
# 862$%
+ #6222$%
&

H $ ! (
, " #$%
+ #$%
&& 4 40 ! (7 ( $' $
&& ! "

=
L &
K ( ! ( '
0 '' 5 6 $ '$

H! " ( ! (
! ( '* "
L
) * ( '
"
) $$ * (7 4
$ $ P ! % '
H! $ " ! * ' '
'' 4 $ '
; ( % $?$
'' 4 ! ( '
=
&
H $' ! ( $ * '
'
- ' ' !
'
1 ;0 ' * '
" $* $ * !
'' 4
3 # (
$ $?$ $ 4 %' '
, 7 ? * $ '$
$?$ % $ !

=2
1' ' (7
' ' '' ( * $ '$
$?$ ! ' * ! (7
?$ ( ! > % $
0 ? ' 4 ! %'
! ( '
H ' (7 ! %' $?$ :J
$?$ $ # % '
' 0 ' ' ' (
$ ' ' ( ! (7
H $ 0 H3 -3,Q
3 0 '' 4 !
$ $ ' '
==
. '' : $ ' .1H
P '' *
java.rmi.server.codebase0 4
$$ :
.1H " 5 60 5 6 5 6
% $
$ java -Djava.rmi.server.codebase=file:///home/
ecariou/test-rmi/ Serveur
$ java -Djava.rmi.server.codebase=http://www.univ-
pau.fr/~ecariou/test-rmi/ Serveur
- ( #$ '' $
' ' ' '' !$
* !$ P

=@
9 ' '
; ! ( ''
$ 5 "$ 6
java.lang.SecurityManager
- $ ' $ ! # % 0
' 04 ' % (7 04 '
4 ' ' $
%
- 1 ;0 % '
java.rmi.RMISecurityManager
,# ' $$ '' $
4 #

=A
9 ' '
3 1 ;0 % 5 ! 6
. ' 5$ 6 " 4
1 ; "
. 1 ; " '
$ 7 "
% $ 0 $
3' * ( ' ! ' 'R
< toutesPermissions.policy

grant {
permission java.security.AllPermission;
};
' "

public class SecurityManagerOuvert extends SecurityManager{


public void checkPermission(Permission perm) { }
}
=C
9 ' '
- ' '0 %'
System.setSecurityManager(new RMISecurityManager()));
- "0 ''
7 " $ $$
$ java -Djava.security.policy=toutesPermissions.policy
Serveur
$ 4 $$
* '' 0
$$ $ ' S
3 T $ % 4 ' $
J $ ' ' 4 7
=D
< $ ' ' ' ' ( '
K (7 "0 "
' ' ( ! 4 ! (7
' ( ' " !"

" " ' $?$ ' *


% $
K $ 4 ' ' '' (7
H " $ ( ( '
" ' 0 (
H3 -3,Q0 ! 4*
'
0 ' # ( "' "
' $# ( 4 $ 0
' $ 4
H (0 ! " $* $
# 4 ! (7

=F
1' ' ( 0 % $ (
%
H # %(
H3 -3,Q
- ( ' ( 0 '
$
/" $* '
H ' ' (
H ' (
$ "' "
/" $* '
H ' ' (
H 0 ! % $ 0 ' #
( ' (
@G
( '
L * (
, ' ( $
! ? '' ' (
% $ ! % $

H 1 ' 1
public class Rectangle2 extends Rectangle {

public Rectangle2(int x1, int y1, int x2, int y2){


super(x1, y1, x2, y2);
}
}

@
% $
H! ' IRectangle
' 0 $ decaleRectangle()
" Rectangle2

public class RectangleImpl implements IRectangle {

(...)

public Rectangle decalerRectangle(Rectangle rect,


int x, int y) throws RemoteException
{
return new Rectangle2(rect.x1 + x, rect.y1 + y,
rect.x2 + x, rect.y2 + y);
}
(...)

@
% $
H 7 ''
" $* $
"$ $$

&& "$
System.setSecurityManager(new SecurityManagerOuvert());

Rectangle r1, r2;


r1 = new Rectangle(10, 10, 20, 30);

IRectangle opRectangle = (IRectangle)


Naming.lookup("rmi://scinfe222/opRect");

r2 = opRectangle.decalerRectangle(r1, 15, 10);

System.out.println("classe de IRectangle = "


+opRectangle.getClass());
System.out.println("classe de r2 = "+r2.getClass());
@2
% $
H 7 ' '
( ' % *
; 1 ;$ ! # "
$ java -Djava.rmi.server.codebase=http://www.univ-
pau.fr/~ecariou/test-rmi/ Serveur
H " ' ! ' * *
P
H ' # H3 -3,Q
%( 1 ;$ 1
$ java Client
* '
classe de IRectangle = class RectangleImpl_Stub
classe de r2 = class Rectangle2

@=
% $
H 1 ;$ 1 ''
' '' '' 4 !.1H
&& &U & $&
L
4 ! %' % . $ % 0
3 / % L < %
'
4 '' $
$ $
P ' '
! ' " ! 4 ' '
(0 ( '' ( ' '

@@
0 ( ' ! # % 0
$
! * !4
# 4 H3 -3,Q
H " '$ * $ (
' "$
'' (
" * ! $ # %
L
L ( $ +
$ ' $ ! (
' (

@A
: 1 ; # ( ( '
0
! (7
1 ' $' finalize() java.lang.Object
- ''
; java.rmi.server.Unreferenced '
public void unreferenced()
? $ '$ ' (7
' ( 4
H! ' ' * (7
# '' ! (7
* ! % $ $' 5 ' % 6
! (7 unexporteObject(this, true);

@C
H ( ( ' 1 ; #
' (
- ' ' java.rmi.dgc.leaseValue
H ( G$ '
- $ 0 $
$$
$ java -Djava.rmi.dgc.leaseValue=20000 Serveur
H ' ' ' $ 0 G
L
L ( * " #
'' ! (7 '' '
"
@D
'
- % (7 0
. 1 $ )(7
H! (7 ( $
:J * ! %' ? ' 0 ! (7
> '' ' $
J ( 3 (
- $ ! ! (7 * * '
J $' $ :J
- $ $ $( ! (7 $?$
$ $'$ (
- $ % 4 $ ' '

@F
'$ $
( '
- $ '
$ ? $$ 4
- 1 ;0 !
$$ * Q,,-
, Q,,-
5 6
J $ ' ' !

AG

Vous aimerez peut-être aussi