ࡱ> .0)*/w(@ L/ 0DTimes New Roman0z[ 0D[SOes New Roman0z[ 0 DArialNew Roman0z[ 0"0DTahomaew Roman0z[ 0"@DWingdingsRoman0z[ 0PDCourier Newman0z[ 01`DArial Unicode MS0z[ 0 C0.  @n?" dd@  @@``_>*whoosh.wav.WAV 10103RIFFWAVEfmt ++data~~~~~~~~~~~~~~~~~~~~~~~~~~~|||~~~~~zvtvxz|~zvrnlrv||vtrpptz~|xvtv|~~zxvvvz|~xrlhntzzvrrpprrx~|j[QU_|bICCYn[ICY~zlnh]_r|]SUSSjz|x__l~v_]drnUb|nfd_]d]5=rrnj]jz~lMldrx[[_f|YQfWK_xh[zx[CIjzxxdSQz|_fI9WӹM;QnvK;OUx~xj]]YS~ɵlM?plM;CGpٵ[)Kh|% %;xtKQS]ɖbGr|lSnvz~nfS[nëx;Az=+AYݻ|=/1r_ ?|潄W5/Czãf)/pvbMQr|O=OtjdhjlG?G_ɊK3לdQCMppW;1SŷAMz/#?bx͖SAM[hvhYp~~zrvt[]ptWOUtxxd]v~vvxzd_xzh_nrSQltbdp~_lrQ_l][tf]W]~hWfp|fWhnhbU[hzlSCWbYbnxpdhjvjM9Ot]GQ[dpp~hhhdpx~xh]Yntnrp]dlvjQMb|vdjpzxzztljr||_[r~~jb_j|z|xpp~~v]Wh||zx|x|zzndhpxr]Yfntzjl|z||~vppnrzphrxz|~|xtrjjtv~~vz|z||xrrv~xrprtz|||vzxvx|xtx~~~~~~~zxxxx|zxz~~~rrz~|xz~~|vtx|zxz|~~~||zx|||~~zz|zz~~~~|~~||~~||zz|~||z~~~~zxzz|~~~~|~~~|~||~~~~~~~~~~~~~|||~~~~~~~~~~~~~||~~||~||~~~~|||~~~~||||~~~~~~||||~~~~~~~~~~~|~~~~|zz~~~~~~~||||~~||~~~~~|||~~~~~|||~|~|~~~~|z|~~~~~~~|||~~~~~~~~||~~~~~~~~ $$P!)D> %! 0&0'0 '''! &0&0)'O( !!    Avs <) 9   # &%#',&..15789-7&+*#/1235=>  :=<" 0e0e A@A5%8c8c     ?1d0u0@Ty2 NP'p<'p@A)BCD|E? 3@___8 N ʚ;r8ʚ;g4gdgdz[ 0Vpp@ <4!d!d 0$ <4dddd 0$ <4dddd 0$ g4RdRdz[ 0pp p&h___PPT10H0D[SOalr Ne$$@(0@z[ 08DTimes New Roman@(0@z[ 08 DCourier Newman@(0@z[ 0810DArialr Newman@(0@z[ 08" pp___PPT9/ 0zKh? -O =@<Jini Tutorial, Part 3Jini Programming=Tutorial outlinePart 1 Introduction Distributed systems Java basics Remote Method Invocation (RMI) Part 2 Overview of Jini Goals Architecture Basic concepts, protocols Part 3 Jini Programming Part 4 Advanced topics Mobile Jini access Adaptive user interfaces SecurityP@PP-PPPP6P@-  6|Contents\Software overview  architecture, packages Programming the basic steps discovery, join (service registration) and lookup (finding services) Deployment  where to put what<IGIGThe key steps of operation7Every service and client will have to discover one or more lookup services Every service will have to register with (join) the discovered lookup service(s) Every client will have to search for (look up) services in the lookup service(s) First we look at the programming of these fundamental steps of operationV8&8H|Jini package structure$MThe naming of Jini packages follow the inverted domain name naming convention jini.net.xxx The core classes are in packages jini.net.core.*, stored in jini-core.jar Classes building on core classes are in jini.net.*, stored in file jini-ext.jar Non-standard utility, helper classes are in com.sun.jini.*, stored in file sun-util.jarO !)((,,O C!C C( C C,  C CtO "  ) -  :The programmer s view of JiniThe essential steps of creating a system of Jini services and clients Create well-known interfaces (if required) Create services that implement the interfaces Provide discovery in services and clients Services: Program service registration Clients: Program service lookup.FndFHow we should proceedSimple service example to show these steps Defining service interface Creating the service Programming the Unicast Discovery Service registration Service lookup Multicast discovery The interesting parts2+ZndZ+kYCreating the interfaceFirst we define the well-known interface for our sample service public interface GreetingInterface { public void hello(); } LA?A?CCRCreating the Service ProxyThen we create the proxy class the client will see public class GreetingServiceProxy implements Serializable, GreetingInterface { public GreetingServiceProxy (){ }; public void hello(){ System.out.println( Welcome to Jini World! ); } }4ZZ4-C GCG/CNGCbA &!What we want to achieveUnicast discovery * LookupLocator lookup = null; ServiceRegistrar registrar = null; lookup = new LookupLocator( jini://hostname ); registrar = lookup.getRegistrar(); J##                  Service registration7Once we have a proxy to the lookup service, we can register the service ServiceRegistration registration = null; //create serviceItem (no ID, no attributes) try{ // register for 100 seconds registration = registrar.register(serviceItem, 100000L); } catch (java.rmi.RemoteException e){ }lIJ)C-C CCsCPJ ]Putting the service together $#Putting the service together$[ ... ServiceRegistration registration = null; //create serviceItem (no ID, no attributes) ServiceItem serviceItem = new ServiceItem(null, new GreetingServiceProxy(), null); try{ // register for 100 seconds registration = registrar.register(serviceItem, 100000L); }catch (java.rmi.RemoteException e){ } } // GreetingService1PPC*C-C[CCtCC   M %The client sideProgramming the service lookup$@ System.setSecurityManager( new RMISecurityManager() ); // create template for service search ... GreetingServiceInterface returnedService = null; try{ returnedService = (GreetingServiceInterface) registrar.lookup(template); }catch (java.rmi.RemoteException e){ ... } returnedService.hello(); } r@ZZhCG7CGrC5,&Creating the template Class[] serviceTypes = new Class[1]; try { serviceTypes[0] = Class.forName( "GreetingServiceInterface"); }catch (ClassNotFoundException e){ ... } ServiceTemplate template = new ServiceTemplate(null, serviceTypes, null); C /    (Using Attibutes PWhy use attributes The type (interface) of a service will only say  what we can do with a service. We also need information on the properties of the service (eg type and speed of a printer, supercomputer specialising in climate modelling, storage capacity, location of service) You can use standard Jini attributes Address, Comment, Location, Name, ServiceInfo, ServiceType, Status And/or create your own particular onesZZyZ%ZDZ'Zy%  D  '  >  1 AttributesEntry[] attribSet = new Entry[3]; attribSet[0] = new Location( G",  002",  South Building"); attribSet[1] = new Location( 1st",  107", "North Building"); attribSet[2] = new Name( Greeting Service for Euro-Par participants"); ServiceTemplate newTemplate = new ServiceTemplate(null, serviceTypes, attribSet); Since attributes are Java objects and downloaded with the service, they can be used for transferring any type of static or dynamic information from the service to the client077Ct    8Is that all? What s missing?We know how to discover a lookup service, register and lookup services BUT, we can only discover a known lookup service, which is not discovery at all, only connecting to it Multicast discovery to deal with unknown lookup services*99 XProgramming the multicast discovery  Step 1-- XProgramming the multicast discovery  Step 2-- "Handling responses in the listener##$Two methods for joining and leaving public void discovered(DiscoveryEvent e){ //Lookup service discovered } public void discarded(DiscoveryEvent e){ //Clean up after lookup service discarded"); }0$$C,268Step 3 -- Handling registrationMulticast version of the registration process Note the use of event and the number of lookup services public void discovered(DiscoveryEvent event){ ServiceRegistrar[] registrars = event.getRegistrars(); ServiceRegistration[] registration = null; ServiceItem serviceItem = new ServiceItem(null, new GreetingServiceProxy(), null); for (int i = 0; i < registrars.length; i++){ try { registration[i] = registrars[i].register(serviceItem, 100000L); } catch ... } } }.Z8ZZ.C#C C G,C GCGCGyCt   K")7>Creating a  real service proxy@Creating a new proxy that talks to the backend service public class GreetingServiceProxy implements Serializable, GreetingInterface { protected GreetingBackEnd be; public GreetingServiceProxy ( be ){ this.be = be; }; public void hello(){ String str = be.getString(); System.out.println(str); } }7 7SCGUC%GC GCE C  8Modifying the serviceThe interface for the remote proxy public interface GreetingBackEnd extends Remote{ public String getString(); } We also need to create the Backend Remote object that will receive RMI calls from the proxy public class BackEnd extends UnicastRemoteObject implements GreetingBackEnd{ public String getString(){ return  Welcome to Euro-Par ; } }r#ZPZ\ZZ#PG\Gt4! o   ,9Modifying registrationThe service will publish a proxy initialised with a reference to the back end service (the remote object) BackEnd be = new BackEnd(); GreetingServiceProxy proxy = new GreetingServiceProxy(be); ... ServiceItem serviceItem = new ServiceItem(null, proxy, null);rjj]G1CGCk    Where are we now?We have seen the programming of the discovery, join, lookup protocols Shortcomings: We have no leasing for our service Only up and running services will be located  latecomers (both lookup and other services) are missed. We need notification (events) when this happenVTT ' Deployment;Summary Overviewed the programming steps of the Discovery, Join and Lookup protocols Have used a simple and real proxy to a Jini service Looked at the use of attributes Overviewed deployment issues We look at the more advanced issues in the next part /     !$()*Pd ` 33PP` 13` 3333` Q_{` 333fpKNāvI` j@v۩ῑ΂H>?" dd@(?n<d@ `7 `2@`7``2 n?" dd@   @@``PR    @ ` ` p>>  ~  ` (  ` ` <4I"It FA ` TLd"It FA ` <LP"SU_~ FA ` TRd"S>&~ FA ` NdV"%P/ FA ` <Y" FA ` C x^?d?"U  FA  ` <Ha #" `w  X Click to edit Master title style!!(  ` 0(c "z   RClick to edit Master text styles Second level Third level Fourth level Fifth level!    S  ` 6i "]}  Z*C  ` 6n "] }   \*C  ` 6r "]T}  \*CB ` s *޽h ? 333380___PPT10.(г%  Blends   1 ) d (  dT + d "+bb P@ d# "Dwoh d s *"PP d Bd" P@bb P 0  d# "Nyh d s *"P   d Bd"P 0 z  d <" a*h  d s *"  d  f?d?"+)  d B, ?#" ` p  X Click to edit Master title style!!  d 0 " `    [#Click to edit Master subtitle style$$ d 61 "`p   ^*G d 6t1 "`p  1 `* G d 61 "` 1 `* GB d s *޽h ? 333380___PPT10.(г%R 0 Pb(     `x 1 ??z%  1 h*C      `T1 ?? @% 1 j*C     B ??YK  10   `1 ?? M) 1 8USQdkYkHre,g7h_ ,{N~ ,{ N~ ,{V~ ,{N~     f1 ??z  1 h*C      f41 ?? @ 1 j*C   H  0.k ? ̙3380___PPT10.%Ĕ  t(  t t 0: z%  : X*C    t 0L/:  @% : Z*C    t 6: z  : X*C    t 6:  @ : Z*C   H t 0.k ? ̙3380___PPT10.%"  T<(  T~ T s *81 dd 1 ~ T s * 1 d `   1 H T 0޽h ? 33___PPT10i.4+D=' = @B +   X<(  X~ X s *1 `w  1 ~ X s *H `z  1 H X 0޽h ? 3333___PPT10i.@+D=' = @B +y   x0(  xx x c $[} `w  } x x c $X\} `z  } H x 0޽h ? 3333y___PPT10Y+D=' = @B +  0(  x  c $} `w  } x  c $<} `z  } H  0޽h ? 3333  $0(  $x $ c $pV `w   x $ c $DW `z   H $ 0޽h ? 3333   F(  x  c $ `w     c $2 `z   "p`PpH  0޽h ? 3333  PF(  Px P c $$ `w    P c $ `z   "p`PpH P 0޽h ? 3333  0(  x  c $4g `w   x  c $h `z   H  0޽h ? 3333   0(  x  c $) `w  ) x  c $) `z  ) H  0޽h ? 3333%    `  (  x  c $H - `w  - "  3 r)1))??` pP  A Service A  C"  3 r8-1))??( FLookup ServiceC 2   `l-1?` P ,$D 0 G Service ProxyC2  T1?`,$D 0  # l\-))??P `,$D 0 A registrar  C  # lH-))?? 0 ,$D  0 D registration  C    `o?? ,$D 0    `o??r ,$D  0    f-PFPFGHba?? P,$D 0 Fregister( )C   3 rG*H:jI*jJ??k u ,$D 0b  @ C xGleH3I0jJ??`C,$D 0B   fDԔ??@0 ,$D 0H  0޽h ?_       3333___PPT10+wD' = @B DM' = @BA?%,( < +O%,( < +D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<* %(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<* %(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<* %(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<* %(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<* %(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(++0+- ++0+- ++0+- ++0+ - +     (    T?? ,$D 0  T??/?,$D 0x  c $9- `w  - x  c $:- `z  - H  0޽h ? 33336 . ___PPT10 +' D ' = @B D ' = @BA?%,( < +O%,( < +Dn' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*Dn' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*+   0C(    T?? R ,$D 0  T??"B,$D 0x  c $J- `w  - x  c $K- `z  -   N@M-?? ,$D 0 U ServiceItem serviceItem = new ServiceItem(null, new GreetingServiceProxy(), null); V(2VCP   H  0޽h ? 3333___PPT10+=Du' = @B D0' = @BA?%,( < +O%,( < +Dn' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*Dn' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*D{' =%(D#' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*+8+0+- +n   jbP (    T??p P ,$D 0  T??PP ,$D 0  T??P@,$D 0x  c $th- `w  -   0i-   import net.jini.core.discovery.*; import net.jini.core.lookup.*; public class GreetingService { static public void main(String argv[]) { LookupLocator lookup = null; //object for discovery ServiceRegistrar registrar = null; //lookup serv. proxy try { lookup = new LookupLocator("jini://hostname"); } catch(java.net.MalformedURLException e) {...} // perform unicast discovery try { registrar = lookup.getRegistrar(100000); }catch ... }0n<P@C$CCCCCC$CCCC4CVC.CC % (#$OH  0޽h ? 3333___PPT10+-Dh' = @B D#' = @BA?%,( < +O%,( < +Dn' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*Dn' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*Dn' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*+  P0(  x  c $0m- `w  - x  c $m- `z  - H  0޽h ? 3333;  ZR`(  x  c $L- `w  - "  3 r-1))??0  FLookup ServiceC   f,-))??  @Client 1  C2  T1?U ,$D 02   `-1?  ,$D 0 P Found proxyC  # lp-))??  ,$D 0 A registrar  C    f-PFPFG/HN??  ,$D 0 C lookup( )  C   3 rG0*HIfjJ??( @ ,$D 0b   3 rZG0*HI?? x  ,$D  0    fo??0 X ,$D 0    `t-??P,$D 0 A Interface  CR  # lGhCH;IhC??+ ( ,$D  0 2   `0-1?` ,$D  0 G TemplateC @ Z??^p,$D 0B   fDo?? ,$D 0  Z??K P @ ,$D  0 2   `-1?u@,$D  0 E TemplateC|2  T1?PP |2  T1?P |2  T1? |2  T1?02   f ?? @'   `- ??P Z,$D 0 cUnicast discoveryC H  0޽h ?      3333&&___PPT10&+D%' = @B D$' = @BA?%,( < +O%,( < +D{' =%(D#' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<* %(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<* %(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<* %(D4' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<* %(DA' =%(D' =%(D' =A@BBBB0B%(D' =1:Bvisible*o3>+B#style.visibility<*%(++0+- ++0+- ++0+- ++0+ - ++0+- ++0+- ++0+- +   p(    T??P ,$D 0  T??xP,$D 0x  c $- `w  - x  c $h- `z  - H  0޽h ? 33336 . ___PPT10 +' D ' = @B D ' = @BA?%,( < +O%,( < +Dn' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*Dn' =%(D' =%(D' =4@BBBB%(D' =1:Bvisible*o3>+B#style.visibility<*%(D' =+4 8?dCB0-#ppt_w/2BCB#ppt_xB*Y3>B ppt_x<*D' =+4 8?\CB#ppt_yBCB#ppt_yB*Y3>B ppt_y<*+  0(  x  c $ - `w  - x  c $- `z  - B  s *޽h ? 3333  0(  x  c $ 0 `w  0 x  c $ 0 `z  0 H  0޽h ? 3333  0(  x  c $0 `w  0 x  c $l0 `z  0 H  0޽h ? 3333  0(  x  c $H(0 `w  0 x  c $)0 `z  0 H  0޽h ? 3333     ,|7 (  |x | c $10 `w  0  | c $H30 `z  0 LookupDiscovery discover = null; try{ discover = new LookupDiscovery(LookupDiscovery.ALL_GROUPS); }catch ... This implements the process shown in the next figure. Jq#5" x    *    6  " "| 3 r<01))?? @p  HLookup Service NC #|  f\A0))??@ `  JDiscovering entityC" $| 3 rdE01))?? 0`  X Lookup Service & C" %| 3 rI01))?? pP  HLookup Service 2C" &| 3 rL01))?? 0 @ HLookup Service 1CB '|  fD___o??P  p B (|  fD___o??@  B )|  fD___o??0  0 B *|  fD___o??  B +|  fD___o??  ,| T8R0 ?? .  Kmulticast request(2CH | 0޽h ? 3333]   (  x  c $c0 `w  0   c $e0 `z  0 yAsynchronous responses are handled by a listener object (implementing the DiscoveryListener interface) discover.addDiscoveryListener(listener); try{ Thread.currentThread().sleep(10000L); } catch ... } Tgog CGGC,J&GH  0޽h ? 3333  0(  x  c $H{0 `w  0 x  c $|0 `z  0 H  0޽h ? 3333  B(  x  c $0 `w  0   c $1 `z  0   H  0޽h ? 3333 ( 00(  0x 0 c $ԥ0 `w  0 x 0 c $x0 `z  0 B 0 s *޽h ? 3333 * 40(  4x 4 c $T0 `w  0 x 4 c $(0 `z  0 H 4 0޽h ? 3333 )  80(  8x 8 c $ n1 `w  0 x 8 c $n1 `z  1 H 8 0޽h ? 3333 !  0(  x  c $@0 `w  0 x  c $0 `z  0 H  0޽h ? 3333 $ 0$(  "   C xX0Gj___jJ))??``0 JService computerC"   C x0Gj___jJ))?? G Client deviceC"   C x0Gj___jJ))??Pp  QLookup service computerCx  c $T0 `w  0 "  C x01))?? p0  B RMI Daemon  C"  3 rd01))??p@ P ]% HTTP Server for exporting LS classes&&C"  C xT01))?? P   FLookup ServiceC"  C x\01))?? `@ >ClientC"  C x@a11))?? p ?ServiceC"  3 r\01))?? p  b* HTTP Server for exporting service classes++C"   S ~ 01))??P  B RMI Daemon  C"  C xL01))?? `  `(HTTP Server for exporting client classes))CB  @ # lDjJ??`P B  # lDjJ??`  B @ # lDjJ?? P B @  fDjJ?? B @ # lDjJ?? p B  # lDjJ??@ PH  0޽h ? 3333   P0(  Px P c $ 0 `w  0 x P c $a1 `z  0 H P 0޽h ? 3333 0 IA`((  (^ ( S YK   1K ( c $HL1 MP)  1 yJini Packages 1.1 Core packages net.jini.core.discovery net.jini.core.entry net.jini.core.event net.jini.core.lease net.jini.core.lookup net.jini.core.transaction net.jini.core.transaction.server Jini packages building on core net.jini.admin net.jini.discovery net.jini.entry net.jini.event net.jini.lease net.jini.lookup net.jini.lookup.entry net.jini.space Pf`"      U 0"9U 0;NU 0PcU 0exU 0zU 0U 0U 0U 0U 0U 0!/U 01?U 0APU 0RgU 0iw (  `8l1 ??  \ XR Utility packages com.sun.jini.admin com.sun.jini.discovery com.sun.jini.fiddler com.sun.jini.lease com.sun.jini.lease.landlord com.sun.jini.lookup com.sun.jini.lookup.entry com.sun.jini.mahout com.sun.jini.mahout.binder com.sun.jini.mercury com.sun.jini.norm com.sun.jini.outrigger com.sun.jini.reggie com.sun.jini.start H ?`   B    U 0%U 0'=U 0?SU 0UgU 0iU 0U 0U 0U 0U 0U 0U 0&U 0(;U 0=OH ( 0.k ? ̙33 0 P8,(  8^ 8 S YK   1 8 c $\1 M)  1 " H 8 0.k ? ̙33 0 @@,(  @^ @ S YK   1 @ c $1 M)  1 " H @ 0.k ? ̙33 0 pH,(  H^ H S YK   1 H c $t1 M)  1 " H H 0.k ? ̙33!  0   Lq (  L^ L S YK   1  L s *1 M)  1 a YWe create the lookup and registrar objects; lookup for the unicast discovery, registrar to hold the returned proxy for the lookup service. LookupLocator lookup = null; ServiceRegistrar registrar = null; Then we perform the unicast discovery process using the lookup object of LookupLocator class. The constructor LookupLocator() constructs a new LookupLocator object and specifies the lookup service to be contacted by its URL address. LookupLocator(java.lang.String url) takes a URL address of the host as input. The URL must be in the form of jini://host/ or jini://host:port/. The other constructor of the class LookupLocator(java.lang.String host, int port) takes the hostname and port as input. The host should be a valid host name. The default port is 4160. Note that the LookupLocator() constructor does not perform unicast discovery. It does not even perform host resolution. Only the input syntax is checked. The method getRegistrar() is used to perform the unicast discovery after the LookupLocator object has been created. The method returns a ServiceRegistrar object that is a proxy to the specified lookup service. The discovery is performed each time the method is invoked. The difference between the two versions of getRegistrar() is that the first uses a default timeout (60 seconds), whereas in the second one you can specify any timeout value. TZ, a  a    a   a  a O  a  a     a   a    a v ~;  I           -         O     K     3     }      b        /     w  H L 0.k ? ̙33*  0 Tz(  T^ T S YK   1 T s *1 M)  1 jThe Proxy This is the part of the service that goes to the lookup service and will be downloaded by the clients. In our example, the proxy is the full service itself, as it will not talk back to a backend. Serialization The service object must be serializable. The object will be exported and moved around over the network using RMI. The code will be away from the service host when executed. If it makes use of the host hardware, it has to provide code to communicate  over the network  from the client s JVM back to the original host s JVM and hardware. Implement the service interface The service has to provide an implementation for the service interface. There may be several different implementations of the same service interface. This is not a problem, as long as the client knows how to use the methods defined in the interface.PO R H   K   H T 0.k ? ̙33 0 A9X(  X^ X S YK   13 X s *1 M)  1 This is the program that will perform the bootstrap process (discovery and proxy registration). Remember, in this example the proxy is the actual service. zH X 0.k ? ̙33M  0   \ (  \^ \ S YK   1 \ s *9 M)  1 Service Registration The service proxy is uploaded to the lookup service using the register method of the registrar object. The input parameters are a serviceItem object and an initial lease value specified in milliseconds. The ServiceItem class The ServiceItem object contains the service ID of the service, the service object itself that is being registered, and a set of attributes describing the service. The serviceID of a new service (that was not registered previously) is null. The lookup service will assign a unique service ID to the service. This serviceID must be used in subsequent operations. REMEMBER: The service object must be serializable. The object will be exported and moved around over the network using RMI. The register() method The object returned by the register() method is an implementation of the ServiceRegistration interface. This object will run in the JVM of the service and, as mentioned earlier, can be used to manipulate the service item registered with the lookup service. Manipulation includes the modification of service attributes, the lease and access to the serviceID using methods addAttributes(), modifyAttributes(), setAttributes(), getLease() and getServiceID().    !     (  `  ! { ! t   J $!$( (,!,0 04!48 8     G     6  ,     '      :  H p 0.k ? ̙33 0 t,(  t^ t S YK   9 t c $L9 M)  9 " H t 0.k ? ̙33  0 h``(  ^  S YK   9Z  s *l9 M)  9 bUnlike in the unicast discovery case, the constructor of the LookupDiscovery class will perform multicast discovery. How to handle asynchronous responses? We do not know how many responses we receive and when. Multicast discovery uses a separate thread  a Listener object  to handle incoming responses from lookup services. The parameter LookupDiscovery.ALL_GROUPS specifies that we are interested in all lookup services of all communities. If you specify a different name, only the lookup service(s) of the community with the matching name will respond. $2S>(H  0.k ? ̙33! 0 |t (  ^  S YK   9n  s *9 M)  9 The service program should perform a unicast discovery to discover the lookup service and obtain a proxy (registrar) for it. Using the registrar proxy we can register a service proxy with the lookup service. A successful registration will return a registration object. The registration object can be used to manage the service proxy within the lookup service, eg to add or modify attributes, get the lease associated with the proxy. ,$>HH  0.k ? ̙33) 0 y(  ^  S YK   9  s *9 M)  9 iUThis is the interface that our service will implement and be used for service lookup.H  0.k ? ̙33 0 ,(  ^  S YK   9  c $D9 M)  9 " H  0.k ? ̙33# 0 ,(  ^  S YK   9  c $9 M)  9 " H  0.k ? ̙33z% 0 :2(  ^  S YK   9,  s *09 M)  9 NOn the client side we first perform a unicast discovery to obtain a proxy for the lookup service. This process is identical to the one on the service side. Then, to be able to perform a service search, we create a template object that describes the type of service we want to find. This description can use the type of the service (in form of a well-known interface) and/or a set of attributes). When the template is constructed, we invoke the lookup() method on the registrar object with the template as input parameter. The lookup will perform a template-matching search of all registered services based on the search rules described earlier. The successful lookup will return one or more services depending on which of the two lookup methods has been used. Note that the lookup in Jini by default performs exact matching. For instance, if you are interested in services with larger than 500 GFlops computing performance, you need to download all computing services and examine their performance attribute individually. This is because the matching is based on serialised objects (ie the proxies).P&jH  0.k ? ̙33@& 0  (  ^  S YK   9  s *0: M)  9 The Lookup process uses templates and matching to find services. The required service is specified in the form of a ServiceTemplate object and it is the responsibility of the lookup service to return any matched service to the client. The Jini matching mechanism uses exact matches and wildcards. Given a template T, value fields of T must match the value of the same fields of an entry E. Wildcard fields of T can match any value of the same field of E. A value in a field is a reference to an object. A wildcard is a null reference in the give field. The