`
`Ian Newmarch
`
`A Programmer’s Guide
`to JiniT” Technology
`
`Up-to-date coverage of the newest IinilM features announced by Sun this year
`
`I
`
`Addresses important topics such as application architecture. user interfaces for JiniTM services,
`
`and how hardware devices and CORBA fit in with the IiniTM framework
`
`Tech reviewed by master JavaTM programmer and well-known columnist Bill Venner
`
`APress Media, LLC
`
`1
`
`APPLE 1046
`
`1
`
`APPLE 1046
`
`
`
`A Programmer’s Guide to
`Jinim Technology
`
`IAN NEWMARCH
`
`APress Media, LLC
`
`libdocdel@fr.com
`
`2
`
`
`
`A Programmer’s Guide to IiniT'“I Technology
`
`Copyright ©2000 by Ian Newrnarch
`Originally published by Apress in 2000
`
`All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
`means, electronic or mechanical. including photocopying, recording, or by any information
`storage or retrieval system, without the prior written permission of the copyright owner and the
`publisher.
`
`ISBN 978' 1- 893 1 15-804
`DO] 10.1007f978-1-4302'0860'0
`
`ISBN 978- 1-4302-0360-0 (eBool-I)
`
`Ti'ademarked names may appear in this book. Rather than use a trademark symbol with every
`occurrence of a trademarked name, we use the names onlyin an editorial fashion and to the
`benefit of the trademark owner. with no intention of infringement of the trademark.
`
`Editorial Directors: Dan Ap pieman, Gary Cornell. Karen Watterson
`
`Editor: Andy Carroll
`Production Editor: Kari Brooks
`
`Page Composition: Tony Ionick—Rappid Rabbit
`
`Artist: Karl Miyajima
`indexer: Carol Burbo
`
`Cover: Karl Miyajima
`
`The information in this book is distributed on an “as is" basis. without warranty. Although every
`precaution has been taken in the preparation of this work, neither the author nor Apress shall
`have any liability to any person or entity with respect to any loss or damage caused or alleged to
`be caused directly or indirectly by the information contained in this work.
`
`|ibdocde|@fr.com
`libdocdel@fr.com
`
`3
`
`3
`
`
`
`Contents at a Glance
`
`Introduction ..................................................................................................... xu:
`
`Chapter 1 Overview of Jini ........................................................................ 1
`
`Chapter 2 Troubleshooting Jini
`Configuration Problems ............................................................................ 17
`
`Chapter 3 Discovering a Lookup Service ............................................. 23
`
`Chapter 4 Entry Objects ............................................................................. 43
`
`Chapter 5 Service Registration .............................................................. 49
`
`Chapter 6 Client Search ............................................................................. 57
`
`Chapter 7 Leasing ......................................................................................... 63
`
`Chapter 8 A Simple Example ...................................................................... 83
`
`Chapter 9 Choices for Service Architecture ................................... 109
`
`Chapter 10 Discovery Management .......................................................... 153
`
`Chapter 11
`
`Join Manager ........................................................................... 161
`
`Chapter 12 Security ................................................................................... 169
`
`Chapter 13 More Complex Examples ........................................................ 193
`
`Chapter 14 Remote Event ........................................................................... 235
`
`Chapter 15 ServiceDiscoveryManager.................................................... 255
`
`Chapter 16 Transaction ............................................................................. 271
`
`Chapter 17
`
`LEGO MINDS TORMS .................................................................... 295
`
`Chapter 18
`
`CORBA and Jini ....................................................................... 323
`
`Chapter 19 User Interfaces for Jini Services ..................../........... 355
`
`Chapter 20 Activation ............................................................................... 393
`
`Index .................................................................................................................... 433
`
`libdocdel@fr.com
`
`iii
`
`4
`
`
`
`Contents
`
`Introduction ..................................................................................................... xm
`
`Chapter 1 Overview of Jini ................................................................. 1
`
`Jini ............................................................................................................................... 1
`
`Components .................................................................................................................. 2
`
`Service Registration ............................................................................................ 3
`
`Client Lookup ........................................................................................................... 5
`
`Proxies ........................................................................................................................ 7
`
`Client Structure .................................................................................................... 8
`
`Server Structure .................................................................................................. 10
`
`Partitioning an Application .......................................................................... 11
`
`Support Services .................................................................................................. 13
`
`HTTP Server ........................................................................................................ 13
`
`RMI Daemon ....................................................................................................... 15
`
`Summary ...................................................................................................................... 15
`
`Chapter 2 Troubleshooting Jini
`Configuration Problems ............................................... 17
`
`Java Packages ......................................................................................................... 17
`
`Jini versions ......................................................................................................... 18
`
`libdocdel@fr.com
`
`5
`
`
`
`Contents
`
`Jini Packages ......................................................................................................... 19
`
`Lookup Service .......................................................................................................20
`
`RMI Stubs .................................................................................................................. 20
`
`Debugging ..................................................................................................................22
`
`Summary ......................................................................................................................22
`
`Chapter 3 Discovering a Lookup Service ................................23
`
`Running a Lookup Service .................................................................................23
`
`Reggie ................................................................................................................... 23
`
`rrnid and IDK 1.3 ................................................................................................. 26
`
`Unicast Discovecy.................................................................................................26
`
`LookupLocator .................................................................................................... 27
`
`InvalidLookupLocator......................................................................................... 27
`
`Running the InvalidLookupLocator .................................................................. 29
`
`Information from the LookupLocator ............................................................... 29
`
`getRegistrar .......................................................................................................... 30
`
`Running the UnicastRegister .............................................................................. 32
`
`Broadcast Discovery ............................................................................................ 32
`
`Groups .................................................................................................................. 33
`
`LookupDiscovery................................................................................................. 33
`
`DiscoveryListener ................................................................................................ 34
`
`DiscoveryEvent .................................................................................................... 35
`
`Staying Alive ......................................................................................................... 37
`
`Running the MulticastRegister ........................................................................... 38
`
`Broadcast Range .................................................................................................. 39
`
`ServiceRegistrar ................................................................................................... 39
`
`libdocdel@fr.com
`
`6
`
`
`
`Contents
`
`Information from the ServiceRegistrar ............................................................. 41
`
`Summary ...................................................................................................................... 42
`
`Chapter 4 Entry Objects ....................................................................... 43
`
`Entry Class ............................................................................................................. 43
`
`Attribute Matching Mechanism ......................................................................... 45
`
`Restrictions on Entries ................................................................................... 46
`
`Convenience Classes ............................................................................................ 46
`
`Further Uses of Entries ................................................................................... 47
`
`Summary ...................................................................................................................... 48
`
`Chapter 5 Service Registration ..................................................... 49
`
`ServiceRegistrar .................................................................................................. 49
`
`ServiceItem ............................................................................................................. 49
`
`Registration ........................................................................................................... 51
`
`ServiceRegistration ............................................................................................ 51
`
`The SimpleService Program ............................................................................... 52
`
`Running the SimpleService ................................................................................ 53
`
`Information from the ServiceRegistration ........................................................ 54
`
`Service ID ............................................................................................................. 54
`
`Entries ...................................................................................................................... 55
`
`Summary ...................................................................................................................... 55
`
`libdocdel@fr.com
`
`Vii
`
`7
`
`
`
`Contents
`
`Chapter 6 Client Search .......................................................................57
`
`Searching for Services with the ServiceRegistrar ............................. 57
`
`Receiving the ServiceMatches Object ......................................................... 60
`
`Matching Services ................................................................................................. 61
`
`Summary ...................................................................................................................... 62
`
`Chapter 7 Leasing....................................................................................... 63
`
`Requesting and Receiving Leases .................................................................. 63
`
`Cancellation ......................................................................................................... 65
`
`Expiration ............................................................................................................. 65
`
`Renewing Leases ..................................................................................................... 65
`
`Granting and Handling Leases ......................................................................... 66
`
`Abstract Lease ...................................................................................................... 67
`
`Landlord Lease Package ...................................................................................... 68
`
`Summary ...................................................................................................................... 81
`
`Chapter 8
`
`A Simple Example ............................................................... 83
`
`Problem Description ............................................................................................ 83
`
`Service Specification ........................................................................................ 86
`
`common Classes ....................................................................................................... 87
`
`MIMEType ........................................................................................................... 87
`
`FileClassifier Interface ........................................................................................ 89
`
`The Client ................................................................................................................ 90
`
`viii
`
`libdocdel@fr.com
`
`8
`
`
`
`Contents
`
`Unicast Client ...................................................................................................... 90
`
`Multicast Client ................................................................................................... 94
`
`Exception Handling ............................................................................................ 96
`
`The Service Proxy ................................................................................................ 97
`
`Uploading a Complete Service ........................................................................ 98
`
`FileClassifier Implementation ........................................................................... 99
`
`FileClassifierServer Implementation ................................................................. 99
`
`Client Implementation ..................................................................................... 104
`
`What Classes Need to Be Where? ..................................................................... 104
`
`Running the FileClassifier ................................................................................ 1 06
`
`Summary .................................................................................................................... 1 07
`
`Chapter 9 Choices for Service Archi tecture .................... 109
`
`Proxy Choices ....................................................................................................... 109
`
`Proxy Is the Service ........................................................................................... 109
`
`RMI Proxy .......................................................................................................... 1 I 0
`
`Non-RMI Proxy.................................................................................................. 112
`
`RMI and Non—RMI Proxies ............................................................................... 1 14
`
`RMI Proxy for FileClassifier ...................................................................... 115
`
`What Doesn’t Change ....................................................................................... 1 15
`
`RemoteFileClassifier ......................................................................................... 1 1 6
`
`FileClassifierImpl .............................................................................................. 1 l 6
`
`FileClassifierServer............................................................................................ 11 7
`
`What Classes Need to Be Where? ..................................................................... 120
`
`Running the RMI Proxy FileClassifier.............................................................. 122
`
`Non -RMI Proxy for FileClassifier ............................................................. 123
`
`FileClassifierProxy ............................................................................................. 124
`
`libdocdel@fr.com
`
`9
`
`
`
`Contents
`
`FileServerImpl ................................................................................................... 126
`
`Service Provider ................................................................................................. 128
`
`What Classes Need to Be Where? ..................................................................... 131
`
`Running the RMI Proxy FileClassifier ............................................................. 132
`
`RMI and non-RMI Proxies for FileClassifier ........................................ 133
`
`FileClassiflerProxy ............................................................................................. 133
`
`ExtendedFileClassifier ...................................................................................... 134
`
`ExtendedFileClassifierImpl .............................................................................. 135
`
`FileClassifierServer ............................................................................................ 137
`
`What Classes Need to Be Where? ..................................................................... 139
`
`Using Other Services ........................................................................................ 140
`
`Heart Interface ................................................................................................... 142
`
`HeartServer ........................................................................................................ 142
`
`HeartClient ......................................................................................................... 145
`
`Heart Implementation ...................................................................................... 147
`
`Summary .................................................................................................................... 152
`
`Chapter 10 Discovery Management ................................................... 153
`
`Finding Lookup Locators ................................................................................. 153
`
`LookupLocatorDiscovery.................................................................................... 155
`
`LookupDiscoveryManager.................................................................................... 157
`
`Summary .................................................................................................................... 159
`
`Chapter 11 Join Manager........................................................................ 161
`
`Jini 1.1 JoinManager ........................................................................................ 161
`
`libdocdel@fr.com
`
`10
`
`10
`
`
`
`Contents
`
`Jini 1 . 0 JoinManager ........................................................................................ 163
`
`Getting Information from IoinManager .......................................................... 166
`
`Summary .................................................................................................................... 167
`
`Chapter 12 Securi ty.................................................................................. 169
`
`Getting Going with No Security .................................................................. 169
`
`Why AllPermission Is Bad ............................................................................... 170
`
`Removing AllPermission ................................................................................... 172
`
`Jini with Protection ........................................................................................ 173
`
`Service Requirements ........................................................................................ 174
`
`Client Requirements .......................................................................................... 176
`
`RMI Parameters ..................................................................................................... 178
`
`ServiceRegistrar ................................................................................................ 179
`
`Transaction Manager and Other Activatable Services ...................... 180
`
`rmid ........................................................................................................................... 182
`
`rmid and IDK 1.3 ............................................................................................... 183
`
`Being Paranoi ac ................................................................................................... 186
`
`Protection Domains .......................................................................................... 1 86
`
`Signing Standard Files ...................................................................................... 187
`
`Signing Other Services ...................................................................................... 188
`
`Permissions ......................................................................................................... 88
`
`Putting It Together ............................................................................................ 1 89
`
`Summary .................................................................................................................... 191
`
`libdocdel@fr.com
`
`11
`
`11
`
`
`
`Contents
`
`Chapter 13 More Complex Examples ................................................ 193
`
`Where Are the Class Files? ........................................................................... 193
`
`Problem Domain ............................................................................................... 193
`
`NameEntry Interface ......................................................................................... 1 95
`
`Naive Implementation ...................................................................................... 1 96
`
`Factory Implementation ................................................................................... 199
`
`Using Multiple Class Files ................................................................................. 201
`
`Running Threads from Discovery ..................................................................204
`
`Server Threads ...................................................................................................204
`
`Join Manager Threads ....................................................................................... 207
`
`Client Threads .................................................................................................... 207
`
`Inexact Service Matching ...............................................................................209
`
`Matching Using Local Services ....................................................................213
`
`Finding a Service Once Only......................................................................... 221
`
`Leasing Changes to a Service.......................................................................225
`
`Leased FileClassifier .......................................................................................... 226
`
`The FileClassifierLeasedResource Class .......................................................... 228
`
`The FileClassifierLeaseManager Class ............................................................. 229
`
`The FileClassifierLandlord Class ...................................................................... 231
`
`Summary ....................................................................................................................233
`
`Chapter 14 Remote Events .....................................................................235
`
`Event Models .......................................................................................................... 235
`
`Remote Events ....................................................................................................... 236
`
`Event Registration ............................................................................................ 238
`
`xii
`
`libdocdel@fr.com
`
`12
`
`12
`
`
`
`Contents
`
`Listener List ....................................................................................................... 239
`
`Single Listener ................................................................................................... 239
`
`Multiple Listeners ............................................................................................ 241
`
`Listener Source ................................................................................................... 242
`
`File Classifier with Events ........................................................................ 244
`
`Monitoring Changes in Services .................................................................. 249
`
`Summary .................................................................................................................... 254
`
`Chapter 15 ServiceDiscoveryManager ........................................... 255
`
`ServiceDiscoveryManager Interface ........................................................... 255
`
`ServiceItemFilter Interface ........................................................................ 256
`
`Finding a Service Immediately .................................................................... 257
`
`Using a Filter ..................................................................................................... 259
`
`Building a Cache of Services ...................................................................... 262
`
`Running the CachedClientLookup .................................................................. 265
`
`Monitoring Changes to the Cache ................................................................ 266
`
`Summary .................................................................................................................... 269
`
`Chapter 16 Transactions ....................................................................... 271
`
`Transaction Identifiers ................................................................................. 271
`
`TransactionManager ............................................................................................ 272
`
`TransactionParticipant ................................................................................... 223
`
`Mahalo ...................................................................................................................... 273
`
`libdocdel@fr.com
`
`13
`
`xiii
`
`13
`
`
`
`Contents
`
`A Transaction Example ......................................................................................274
`
`PayableFileClassifierImpl ................................................................................. 276
`
`Accountslmpl ..................................................................................................... 282
`
`Client .................................................................................................................. 287
`
`Summary ....................................................................................................................294
`
`Chapter 17 LEGO MINDSTORMS ................................................................295
`
`Making Hardware into Jini Services ......................................................... 295
`
`MINDSTORMS .............................................................................................................. 296
`
`MINDSTORMS as a Jini Service ....................................................................... 296
`
`RCXPort .................................................................................................................... 297
`
`RCX Programs ..........................................................................................................299
`
`Jini Classes .......................................................................................................... 301
`
`Getting It Running ............................................................................................ 307
`
`Entry Objects far a Robot ............................................................................. 315
`
`A Client-Side RCX Class ................................................................................. 316
`
`Higher-Level Mechanisms: Not Quite C ..................................................... 317
`
`Summary .................................................................................................................... 322
`
`Chapter 18 CORBA and Jini ..................................................................323
`
`CORBA ......................................................................................................................... 323
`
`CORBA to Java Mapping ...................................................................................... 325
`
`Jini Proxies .......................................................................................................... 326
`
`xiv
`
`libdocdel@fr.com
`
`14
`
`14
`
`
`
`Contents
`
`A Simple CORBA Example ................................................................................... 328
`
`CORBA Server in Java ....................................................................................... 328
`
`CORBA Client in Java ........................................................................................ 330
`
`Iini Service ......................................................................................................... 331
`
`Iini Server and Client ........................................................................................ 334
`
`Building the Simple CORBA Example ............................................................. 334
`
`Running the Simple CORBA Example ............................................................. 335
`
`CORBA Implementations ................................................................................. 335
`
`Room-Booking Example ........................................................................................ 336
`
`CORBA Objects .................................................................................................. 337
`
`Multiple Objects ................................................................................................ 340
`
`Exceptions .......................................................................................................... 344
`
`Interfaces for Single Thin Proxy ....................................................................... 345
`
`RoomBookingBridge Implementation ............................................................ 347
`
`Other Classes ..................................................................................................... 351
`
`Building the Room-Booking Example ............................................................. 352
`
`Running the Room-Booking Example ............................................................. 352
`
`Migrating a CORBA Client to Jini ............................................................. 353
`
`Jini Service as a CORBA Service ................................................................ 354
`
`Summary .................................................................................................................... 354
`
`Chapter 19 User Interfaces for Jini Services ................. 355
`
`User Interfaces as Entries ........................................................................... 355
`
`Us er Interfaces from Factory Objects ..................................................... 356
`
`Current Factories .............................................................................................. 358
`
`Marshalling Factories ...................................................................................... 358
`
`libdocdel@fr.com
`
`15
`
`15
`
`
`
`Conten