Tải bản đầy đủ (.pdf) (508 trang)

foundations of jini 2 programming

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (13.01 MB, 508 trang )

CYAN
MAGENTA
YELLOW
BLACK
PANTONE 123 CV
this print for content only—size & color not accurate
7" x 9-1/4" / CASEBOUND / MALLOY
(1.0 INCH BULK 512 pages 50# Thor)
THE EXPERT’S VOICE
®
IN JAVA

TECHNOLOGY
Jan Newmarch
Foundations of
Jini 2
Programming
Learn to build SOA-driven distributed systems
using the new and open source Jini

2 technology
EMPOWERING PRODUCTIVITY FOR THE JAVA

DEVELOPER
Foundations of Jini

2 Programming
Dear Reader,
Jini

technology is essentially middleware for building robust Java™-based


distributed applications. Many recognized that when Jini was first released, it
was ahead of its time; only now is its importance being realized as Jini is in its 2.x
releases. Moreover, Jini is now open source under the Apache 2.0 license, which
simply increases the ways in which you can use and apply Jini technology.
As a result, Apress and I realized the time was right for this book, the only
up-to-date book dealing with the Jini 2.x specification and its implementation.
Foundations of Jini

2 Programming covers the fundamentals through
advanced topics such as security and transactions. It even includes a chapter
on interfacing Jini services and clients with Web Services. The book contains
many working examples with full code listings, which can be used as the basis
for your own clients and services.
Overall, this book will show you how to build complex, robust, and reliable
distributed systems using the innovative Jini technology. Enjoy.
Jan Newmarch
Author of
A Programmer’s Guide to
Jini

Technology
(Apress)
Logic Programming:
Prolog and Stream Parallel
Languages
The X Window System and
Motif: A Fast Track Approach
Shelve in
Java Programming
User level:

Beginner–Advanced
www.apress.com
SOURCE CODE ONLINE
forums.apress.com
FOR PROFESSIONALS
BY PROFESSIONALS

Join online discussions:
THE APRESS JAVA

ROADMAP
Pro Java™
Programming, 2E
Java™ 6
Platform Revealed
The Definitive Guide to
Java
™ Swing, 3E
Foundations of
Jini

2 Programming
Beginning Java™
Objects, 2E
SCJP Exam for
J2SE

5 Platform
Jini 2
Programming

Newmarch
ISBN 1-59059-716-8
9 781590 597163
90000
6 89253 59716 3
Companion
eBook Available
Companion eBook
See last page for details
on $10 eBook version

Covers
Jini

2.1
Technology
Covers
Jini

2.1
Technology
Foundations of

Foundations of Jini

2
Programming
■■■
Jan Newmarch
7168 FM.fm Page i Friday, September 1, 2006 10:23 AM

Foundations of Jini

2 Programming
Copyright © 2006 by Jan Newmarch
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-13: 978-1-59059-716-3
ISBN-10: 1-59059-716-8
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Java and all Java-based marks are tradmarks or registered trademarks of Sun Microsystems, Inc., in the US
and other countries.
Apress, Inc. is not affiliated with Sun Microsystems, Inc., and this book was written without endorsement
from Sun Microsystems, Inc.
Lead Editor: Steve Anglin
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick,
Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser,
Keir Thomas, Matt Wade
Production Director and Project Manager: Grace Wong
Copy Edit Manager and Copy Editor: Nicole LeClerc
Assistant Production Director and Production Editor: Kari Brooks-Copony
Compositor: Ellie Fountain
Proofreader: Elizabeth Berry
Indexer: Ed Rush
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,

New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail , or
visit .
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA
94710. Phone 510-549-5930, fax 510-549-5939, e-mail , or visit .
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(s) 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.
The source code for this book is available to readers at in the Source Code/
Download section. You will need to answer questions pertaining to this book in order to successfully
download the code.
7168 FM.fm Page ii Friday, September 1, 2006 10:23 AM
iii
Contents at a Glance
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xvii
Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
■CHAPTER 1 Overview of Jini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
■CHAPTER 2 Troubleshooting Jini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
■CHAPTER 3 Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
■CHAPTER 4 Discovering a Lookup Service. . . . . . . . . . . . . . . . . . . . . . . . . . 35
■CHAPTER 5 Entry Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
■CHAPTER 6 Service Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
■CHAPTER 7 Client Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
■CHAPTER 8 Leasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
■CHAPTER 9 A Simple Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
■CHAPTER 10 Jini Extensible Remote Invocation . . . . . . . . . . . . . . . . . . . . . 117
■CHAPTER 11 Choices for Service Architecture . . . . . . . . . . . . . . . . . . . . . . . 127
■CHAPTER 12 Discovery Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
■CHAPTER 13 Join Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

■CHAPTER 14 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
■CHAPTER 15 More Complex Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
■CHAPTER 16 Remote Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
■CHAPTER 17 ServiceDiscoveryManager . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
■CHAPTER 18 Example: Flashing Clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
■CHAPTER 19 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
■CHAPTER 20 Logging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
■CHAPTER 21 ServiceStarter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
■CHAPTER 22 Advanced Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
7168 FM.fm Page iii Friday, September 1, 2006 10:23 AM
iv
■CHAPTER 23 Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
■CHAPTER 24 User Interfaces for Jini Services . . . . . . . . . . . . . . . . . . . . . . . 373
■CHAPTER 25 Activation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
■CHAPTER 26 Introspection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
■CHAPTER 27 Extended Example: Home Audio System . . . . . . . . . . . . . . . . . 437
■CHAPTER 28 Web Services and Jini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
■INDEX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
7168 FM.fm Page iv Friday, September 1, 2006 10:23 AM
v
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xvii
Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
■CHAPTER 1 Overview of Jini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Jini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Eight Fallacies of Distributed Computing . . . . . . . . . . . . . . . . . . . . 3
Jini Success Stories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Jini Licensing and Apache. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Jini in One Hour. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Service Registration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Client Lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Proxies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Client Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Server Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Partitioning an Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Support Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
The End of Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
■CHAPTER 2 Troubleshooting Jini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Java Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Jini and Java Versions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Jini Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
HTTP Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Network Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Could Not Obtain Preferred Value. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Lookup Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
RMI Stubs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Garbage Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Debugging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Contents
7168 FM.fm Page v Friday, September 1, 2006 10:23 AM
vi
■CONTENTS
■CHAPTER 3 Ant. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Top-Level Build File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Project Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
■CHAPTER 4 Discovering a Lookup Service . . . . . . . . . . . . . . . . . . . . . . . . . 35

Running a Lookup Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
reggie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Unicast Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
LookupLocator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
InvalidLookupLocator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Running the InvalidLookupLocator. . . . . . . . . . . . . . . . . . . . . . . . 37
Information from the LookupLocator . . . . . . . . . . . . . . . . . . . . . . 39
getRegistrar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Running the UnicastRegister . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Broadcast Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
LookupDiscovery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
DiscoveryListener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
DiscoveryEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Staying Alive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Running the MulticastRegister. . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Broadcast Range. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
ServiceRegistrar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Information from the ServiceRegistrar . . . . . . . . . . . . . . . . . . . . . 51
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
■CHAPTER 5 Entry Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Entry Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Attribute Matching Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Restrictions on Entries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Convenience Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Further Uses of Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7168 FM.fm Page vi Friday, September 1, 2006 10:23 AM
■CONTENTS
vii

■CHAPTER 6 Service Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
ServiceRegistrar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
ServiceItem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Registration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
ServiceRegistration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
The SimpleService Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Running the SimpleService Program . . . . . . . . . . . . . . . . . . . . . . 63
Information from the ServiceRegistration. . . . . . . . . . . . . . . . . . . 64
Service ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Entries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
■CHAPTER 7 Client Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Searching for Services with the ServiceRegistrar. . . . . . . . . . . . . . . . . 67
Receiving the ServiceMatches Object . . . . . . . . . . . . . . . . . . . . . . . . . 69
Matching Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
■CHAPTER 8 Leasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Requesting and Receiving Leases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Cancellation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Expiration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Renewing Leases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Granting and Handling Leases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Abstract Lease . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Landlord Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
LandlordLease Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
LeasedResource Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
LeasePeriodPolicy Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Landlord Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
■CHAPTER 9 A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

Problem Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Service Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Common Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
MIMEType. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
FileClassifier Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7168 FM.fm Page vii Friday, September 1, 2006 10:23 AM
viii
■CONTENTS
The Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Unicast Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Multicast Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
The Service Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Uploading a Complete Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
FileClassifier Implementation. . . . . . . . . . . . . . . . . . . . . . . . . . . 105
FileClassifierServer Implementation. . . . . . . . . . . . . . . . . . . . . . 106
Client Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Running the FileClassifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
■CHAPTER 10 Jini Extensible Remote Invocation. . . . . . . . . . . . . . . . . . . . 117
Traditional RMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Exporter Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Jeri Exporter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Exported Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Garbage Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Proxy Accessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
■CHAPTER 11 Choices for Service Architecture . . . . . . . . . . . . . . . . . . . . . 127
Proxy Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

Proxy Is the Service. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
RMI Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Non-RMI Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
RMI and Non-RMI Proxies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
RMI Proxy for FileClassifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
What Doesn’t Change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
RemoteFileClassifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
FileClassifierImpl. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
FileClassifierServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Jeri: What Classes Need to Be Where? . . . . . . . . . . . . . . . . . . . 136
JRMP: What Classes Need to Be Where? . . . . . . . . . . . . . . . . . 140
Running the RMI Proxy FileClassifier . . . . . . . . . . . . . . . . . . . . . 141
7168 FM.fm Page viii Friday, September 1, 2006 10:23 AM
■CONTENTS
ix
Non-RMI Proxy for FileClassifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
FileClassifierProxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
FileServerImpl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
What Classes Need to Be Where? . . . . . . . . . . . . . . . . . . . . . . . 147
Running the Non-RMI Proxy FileClassifier . . . . . . . . . . . . . . . . . 148
RMI and Non-RMI Proxies for FileClassifier . . . . . . . . . . . . . . . . . . . . 151
FileClassifierProxy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
ExtendedFileClassifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
ExtendedFileClassifierImpl . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
FileClassifierServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
What Classes Need to Be Where? . . . . . . . . . . . . . . . . . . . . . . . 156
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
■CHAPTER 12 Discovery Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Finding Lookup Locators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161

LookupLocatorDiscovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
LookupDiscoveryManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
■CHAPTER 13 Join Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Registering Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
■CHAPTER 14 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Getting Going with No Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Why AllPermission Is Bad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Removing AllPermission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Jini with Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Service Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Client Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
RMI Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
ServiceRegistrar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
7168 FM.fm Page ix Friday, September 1, 2006 10:23 AM
x
■CONTENTS
Being Paranoiac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Protection Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Signing Standard Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Signing Other Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
■CHAPTER 15 More Complex Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Where Are the Class Files? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Problem Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
NameEntry Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Naive Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

What Files Need to Be Where? . . . . . . . . . . . . . . . . . . . . . . . . . 189
Factory Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
What Files Need to Be Where? . . . . . . . . . . . . . . . . . . . . . . . . . 191
Using Multiple Class Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
What Files Need to Be Where? . . . . . . . . . . . . . . . . . . . . . . . . . 193
Inexact Service Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Matching Using Local Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Leased Changes to a Service. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Leased FileClassifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
LeaseFileClassifier Implementation . . . . . . . . . . . . . . . . . . . . . . 203
Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
FileClassifierLeasedResource Class. . . . . . . . . . . . . . . . . . . . . . 206
Reaper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
FileClassifierLandlord Class . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Lease Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
■CHAPTER 16 Remote Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Event Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Remote Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Event Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Listener List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Single Listener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Multiple Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Listener Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
File Classifier with Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
7168 FM.fm Page x Friday, September 1, 2006 10:23 AM
■CONTENTS
xi
Leasing Event Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Monitoring Changes in Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
■CHAPTER 17 ServiceDiscoveryManager. . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
ServiceDiscoveryManager Interface . . . . . . . . . . . . . . . . . . . . . . . . . 237
ServiceItemFilter Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Finding a Service Immediately . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Using a Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Building a Cache of Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Running the CachedClientLookup . . . . . . . . . . . . . . . . . . . . . . . 246
Monitoring Changes to the Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
■CHAPTER 18 Example: Flashing Clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
TickerTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
ComputerTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
ClockFrame. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
TickerTimer Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
ComputerTimer Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Multiple Clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
ClockDevice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Runtime Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
■CHAPTER 19 Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Runtime Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
ConfigurationFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Specifying the Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
Storing the Service ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Specifying the Codebase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Using localhost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
A Generic Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279

7168 FM.fm Page xi Friday, September 1, 2006 10:23 AM
xii
■CONTENTS
■CHAPTER 20 Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Logging LookupDiscovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
■CHAPTER 21 ServiceStarter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
ServiceDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Starting a Nonactivatable Service . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Starting a Nonactivatable Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
reggie and ServiceStarter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
■CHAPTER 22 Advanced Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Invocation Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Method Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
TCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
SSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Proxy Preparer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
File Classifier Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
TCP Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
SSL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Proxy Verification. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
HTTPMD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Calculating HTTPMD URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
reggie and HTTPMD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Proxy Verifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325

Client with Proxy Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
SSL Trusted Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Confidentiality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
SSL Confidential Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Mix and Match . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
7168 FM.fm Page xii Friday, September 1, 2006 10:23 AM
■CONTENTS
xiii
Identity Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Java Authentication and Authorization Service (JAAS) . . . . . . . . 335
Keystores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Authenticating Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
Client Requiring Authentication . . . . . . . . . . . . . . . . . . . . . . . . . 343
Alternative Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Authenticating Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Server Requiring Authentication . . . . . . . . . . . . . . . . . . . . . . . . 349
Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
■CHAPTER 23 Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Two-Phase Commit Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Transactions Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Transaction Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Transaction Participant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
mahalo Transaction Manager . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Transactions Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
PayableFileClassifierImpl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
AccountsImpl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
■CHAPTER 24 User Interfaces for Jini Services . . . . . . . . . . . . . . . . . . . . . 373
User Interfaces As Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
User Interfaces from Factory Objects . . . . . . . . . . . . . . . . . . . . . . . . 374
Current Factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Marshalling Factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
UIDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Toolkit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
File Classifier Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
ServiceType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
7168 FM.fm Page xiii Friday, September 1, 2006 10:23 AM
xiv
■CONTENTS
■CHAPTER 25 Activation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
The phoenix Activation Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
A Service Using Activation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Running the Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Nonlazy Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Maintaining State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Using a Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
LeaseRenewalService . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
The norm Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Using the LeaseRenewalService . . . . . . . . . . . . . . . . . . . . . . . . 412
LookupDiscoveryService . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419

The fiddler Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Using the LookupDiscoveryService . . . . . . . . . . . . . . . . . . . . . . 422
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
■CHAPTER 26 Introspection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Basic Service Lister . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Unknown Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Introspection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Unknown Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
■CHAPTER 27 Extended Example: Home Audio System . . . . . . . . . . . . . . 437
Distributed Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Parameters for A/V Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Source/Sink Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
Content Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
Transport Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Linkages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
An HTTP Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
An HTTP Ogg Vorbis Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
An HTTP Sink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Content Sinks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
Sink Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
7168 FM.fm Page xiv Friday, September 1, 2006 10:23 AM
■CONTENTS
xv
Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Sink Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Source Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
File Source Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Playlists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
Basic Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
■CHAPTER 28 Web Services and Jini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Integrating Web Services and Jini . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Simple Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
Bridging Between a Jini Client and Web Service, Example 1 . . . . . . . 469
Bridging Between a Jini Client and Web Service, Example 2 . . . . . . . 470
Bridging Between a Web Service Client and Jini Service . . . . . . . . . . 471
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
■INDEX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
7168 FM.fm Page xv Friday, September 1, 2006 10:23 AM
7168 FM.fm Page xvi Friday, September 1, 2006 10:23 AM
xvii
About the Author
■JAN NEWMARCH is Associate Professor in the Information
Technology faculty at Monash University, Australia. He
teaches and does research in the field of distributed
computing and currently specializes in pervasive
systems. His interests are broad and include user
interfaces, security, and web-based technologies. He has
published over 80 papers, and this is his fourth book. It is
based on his online tutorial (comp.
monash.edu.au/java/jini/tutorial/Jini.xml), which
has introduced Jini to thousands of programmers.
7168 FM.fm Page xvii Friday, September 1, 2006 10:23 AM
7168 FM.fm Page xviii Friday, September 1, 2006 10:23 AM
xix
Acknowledgments
I would like to acknowledge the hard work and visionary thinking of the Jini team for making
this technology possible. I have received comments and encouragement from the team in
developing this book from an initial short tutorial. I would also like to thank the many Jini

programmers who have used this book in its online form, and who have often given helpful
comments and made corrections. Thanks go to Bill Venners, who tech reviewed the first
edition.
Parts of this book were completed while I was on a sabbatical program at the Beijing
University of Post and Telecommunications and the University of California, Berkeley. I would
like to thank Dr. Xiaosheng Tang and Professor Jan Rabaey for their hospitality.
Finally, my thanks to the many students over the past eight years who have attended my
courses and done further development with Jini.
7168 FM.fm Page xix Friday, September 1, 2006 10:23 AM
7168 FM.fm Page xx Friday, September 1, 2006 10:23 AM
xxi
Introduction
The business and academic worlds have long accepted the use of networking technologies,
allowing users to share files and applications and to exchange information using network
services such as e-mail. The continuing explosive growth of the Internet and the Web has made
everyone conscious of the importance of networked applications, and this importance is
increasing with the emergence of home, mobile, and sensor networks.
For the programmer, building distributed applications can be a complex business. There
are issues related to network stability and accessibility involved, in addition to partitioning
applications into portions that can run separately but still be linked into larger functional units.
A variety of frameworks—both experimental and commercial—have been devised to make it
easier to build and deploy distributed applications.
Service-oriented architectures (SOAs) have come to the fore recently as a means of
structuring and linking components into distributed applications. There is much reinvention
going on in this area, but people are beginning to realize that as long ago as 1998, Jini addressed
and solved many of the issues that arise in building SOA systems. This has led to a resurgence
of interest in what is all of a philosophy of building applications, an API, and an
implementation.
Who This Book Is For
This book is aimed at the professional programmer who wants to build robust and reliable

distributed applications. It assumes you have a background in Java programming and network
programming. It also assumes that you are familiar with network concepts such as remote
procedure calls, are familiar with Java syntax, and have a working knowledge of the Java core
classes.
What This Book Covers
This is a hands-on, study-the-code book. My intention is to introduce you to code that can be
readily understood and that can be copied and adapted for your own programs. The book
covers the full range of Jini concepts, from the basics through to advanced topics, such as
security, transactions, user interfaces, and linking Jini and Web Services.
This book originated from an online tutorial that began at ten pages in 1999 and has grown
steadily since. In 2001, the tutorial was published as A Programmer’s Guide to Jini Technology
(Apress) and dealt with Jini version 1.1. Jini has continued to develop, and the tutorial has
continued to evolve, so it’s now appropriate to release this new edition covering Jini 2.1.
7168 FM.fm Page xxi Friday, September 1, 2006 10:23 AM
xxii
■INTRODUCTION
■Note Jini 2.1 requires at least JDK 1.4, but it will also work with JDK 1.5.
The first nine chapters of this book deal with the basics of Jini programming, leading to a
complete, but simple, application. The subsequent chapters discuss more advanced material.
Most aspects of the Jini technology are covered, but of course there are always complexities
that will take you beyond the bounds of this book. There is an active Jini mailing list, http://
archives.java.sun.com/archives/jini-users.html, with many helping hands, if you find
yourself in need of further assistance.
7168 FM.fm Page xxii Friday, September 1, 2006 10:23 AM
1
■ ■ ■
CHAPTER 1
Overview of Jini
Jini grew from early work in Java to make distributed computing easier. It intends to make
network devices and network services into standard components of everyone’s computing

environment. The computing world is currently abuzz about service-oriented systems, and Jini
has been a major platform for service-oriented computing since its inception, long before the
term became popular.
Jini supports both software and hardware services. When you buy a new piece of office
computing equipment such as a desk lamp, or a new home computer appliance such as an
alarm clock, it will not only carry out its “traditional” functions, but will also join a network of
other computer devices and services. The desk lamp will turn itself off when you leave your
desk, informed of your departure by sensors in your chair; the alarm clock will tell your coffee-
maker to switch on a few minutes before it wakes you up. These hardware services will interact
with software services such as calendar and diary services, and possibly with external services
such as weather and stock exchange services (to wake you up early if the weather is cold or if
there is sudden movement on the market). Jini doesn’t care what is behind services; it just
makes the services available to applications.
Homes, offices, and factories are becoming increasingly networked. Current twisted-pair
wiring will remain, but it will be augmented by wireless networks and networks built on phone
lines and power cables. On top of this will be an infrastructure to allow services to communi-
cate. TCP/IP will be a part of this, but it will not be enough. There will need to be mechanisms
for service discovery, for negotiation of properties, and for event signaling (e.g., “My alarm has
gone off—does anyone want to know?”).
Jini supplies this higher level of interaction. This chapter provides a brief overview of Jini,
and the components of a Jini system and the relationships between them.
■Note The licensing model for Jini has now changed to an open source Apache license from a proprietary
license. This change, plus the continued quality of the middleware, has sparked renewed interest in Jini.
Jini
Jini is the name for a distributed computing environment that can offer network plug and play,
meaning that a device or a software service can be connected to a network and announce its
presence, and clients that wish to use such a service can then locate it and call it to perform
7168ch01.fm Page 1 Friday, September 8, 2006 12:29 PM
2
CHAPTER 1

■ OVERVIEW OF JINI
tasks. Jini can be used for mobile computing tasks where a service may be connected to a
network for only a short time, but it can more generally be used in any network where there is
some degree of change. Jini is useful in a large number of scenarios, including the following:
• A new printer can be connected to the network and announce its presence and capabil-
ities. A client can then use this printer without having to be specially configured to do so.
• A digital camera can be connected to the network and present a user interface that will
not only allow pictures to be taken, but also be aware of any printers so that the pictures
can be printed.
• A configuration file that is copied and modified on individual machines can be made
into a network service from a single machine, reducing maintenance costs.
• New capabilities extending existing ones can be added to a running system without
disrupting existing services, or without any need to reconfigure clients.
• Services can announce changes of state, such as when a printer runs out of paper.
Listeners, typically of an administrative nature, can watch for these changes and flag
them for attention.
Jini is not an acronym for anything, and it does not have a particular meaning (although it
gained the post-hoc interpretation of “Jini Is Not Initials”). A Jini system or federation is a
collection of clients and services all communicating by the Jini protocols. Often this federation
will consist of applications written in Java, communicating using the Java Remote Method
Invocation (RMI) mechanism. Although Jini is written in pure Java, neither clients nor services
are constrained to be in pure Java. They may include native code methods, act as wrappers
around non-Java objects, or even be written in some other language altogether. Jini supplies a
middleware layer to link services and clients from a variety of sources.
When you download a copy of Jini, you actually get a mixture of things. First, Jini is a spec-
ification of a set of middleware components, including an application programming interface
(API) so that you as a programmer can write services and components that make use of this
middleware. Second, it includes an implementation (in pure Java) of the middleware, as a set
of Java packages. By including these packages in the classpath of your client or service, you can
invoke the Jini middleware protocols to join in whatever Jini services and clients are currently

running. (This collection of clients and services is sometimes called a djinn.) You also get
source code to these packages as a bonus. Finally, Jini requires a number of “standard”
services, and Sun gives basic implementations of each. These implementations are not an offi-
cial part of Jini, but are included to get you going, and in practice, most users find these
implementations sufficient to do substantial work with Jini.
Jini was not born in a vacuum. It was based on long experience within Sun Microsystems
of building networking applications and frameworks. Many of the most important lessons
from this were summarized in the Eight Fallacies of Distributed Computing. For the last few
years Jini has not been highly visible. There are various non-technical reasons for this, but also
technology that works and works well is often not reported. Nevertheless, to show that Jini
came from somewhere and has been used in substantial projects, in the subsections that
follow, I discuss the Eight Fallacies of Distributed Computing and how they relate to Jini, and I
also describe some Jini success stories.
7168ch01.fm Page 2 Friday, September 1, 2006 10:26 AM

×