Foundations of Jini 2 Programming

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 ■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

pdf508 trang | Chia sẻ: tlsuongmuoi | Lượt xem: 2237 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Foundations of Jini 2 Programming, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
as // object from the file serviceID = null; try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(serviceIDFile)); serviceID = (ServiceID) ois.readObject(); System.out.println("Got dir service id " + serviceID); } catch(Exception e) { 7168ch27.fm Page 460 Friday, September 1, 2006 11:00 AM C H A P T E R 2 7 ■ E X T E N D E D E X A M P L E : H O M E A U D I O S Y S T E M 461 System.out.println("Couldn't get service IDs - generating new one"); try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(serviceIDFile)); Uuid uuid = UuidFactory.generate(); serviceID = new ServiceID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()); oos.writeObject(serviceID); oos.close(); } catch(Exception e2) { System.out.println("Couldn't save ids"); e2.printStackTrace(); } } } } // FileServer The file source server requires the following classes: • audio.httpsource.FileServer • audio.httpsource.FileServer • audio.http.HttpSourceImpl • audio.http.HttpOggSourceImpl • audio.http.HttpMP3SourceImpl • audio.http.HttpWAVSourceImpl • audio.presentation.MP3 • audio.presentation.WAV • audio.presentation.Ogg • audio.transport.HttpURL • audio.transport.HttpSource • All the classes in the audio.common package These classes can be collected into a .jar file such as audio.httpsource.FileServer.jar and run with a configuration such as the preceding one, as follows: java -classpath audio.httpsource.FileServer.jar audio.httpsource.FileServer sting.cfg Playlists Much music comes on CDs, LPs, tapes, and cassettes, or in some similarly structured format (even a radio show has a structure). This structure often mirrors that of a directory, so a CD 7168ch27.fm Page 461 Friday, September 1, 2006 11:00 AM 462 C H A P T E R 2 7 ■ E X T E N D E D E X A M P L E : H O M E A U D I O S Y S T E M might contain a directory of tracks, and so on. A directory can be a service in its own right, so there is an interface to define it. /** * Directory.java * A one-level directory of services. If the directory is also * a service then it allows a directory tree hierarchy to be built */ package audio.common; import java.rmi.Remote; import java.rmi.RemoteException; import net.jini.core.lookup.ServiceID; public interface Directory extends Remote { ServiceID[] getServiceIDs() throws RemoteException; }// Directory The directory defines the minimum about each of its services: their ServiceIDs. This allows a directory to contain any type of service: individual songs, other directories, and even image services or other services. For a directory like this to work, each service must have a persistent service ID, but this is expected of a Jini service, anyway. There isn’t room in this book to fully explore how directories like this can be used. They can be used to build playlists and lists of playlists. The services are not restricted to a single computer, and the playlists can be dynamically created. The web site for this book goes into much more detail on this topic. Basic Client A client will locate sources and sinks and allow a user to make selections from them. Each sink will be told about the selected sources, and each source will be told about the selected sinks. The client may register itself as a listener for events (such as STOP) from the services. Then the client will ask the sources to play() and the sinks to record(). I do not have space in this book to provide an all-singing, all-dancing client with a graphical user interface that can handle playlists; such a client is discussed on the web site for this book. Instead, I just discuss a minimal client that just connects a single source to a single sink (the first one found of each). The basic client will just find a sink and a source (any source, any sink), tell each about the other, and then play/record to an audio stream. This can be done as follows: package audio.client; import java.rmi.RMISecurityManager; import java.rmi.RemoteException; import net.jini.discovery.LookupDiscovery; import net.jini.core.lookup.ServiceTemplate; import net.jini.discovery.LookupDiscoveryManager; import net.jini.lookup.ServiceDiscoveryManager; import net.jini.core.lookup.ServiceItem; import net.jini.lease.LeaseRenewalManager; import audio.common.Sink; import audio.common.Source; 7168ch27.fm Page 462 Friday, September 1, 2006 11:00 AM C H A P T E R 2 7 ■ E X T E N D E D E X A M P L E : H O M E A U D I O S Y S T E M 463 /** * BasicClient.java */ public class BasicClient { private static final long WAITFOR = 100000L; private ServiceDiscoveryManager clientMgr = null; public static void main(String argv[]) { new BasicClient(); // stay around long enough to receive replies try { Thread.currentThread().sleep(2*WAITFOR); } catch(java.lang.InterruptedException e) { // do nothing } } public BasicClient() { System.setSecurityManager(new RMISecurityManager()); try { LookupDiscoveryManager mgr = new LookupDiscoveryManager(LookupDiscovery.ALL_GROUPS, null, // unicast locators null); // DiscoveryListener clientMgr = new ServiceDiscoveryManager(mgr, new LeaseRenewalManager()); } catch(Exception e) { e.printStackTrace(); System.exit(1); } // find a source and sink Sink sink = (Sink) getService(Sink.class); Source source = (Source) getService(Source.class); // tell them about each other try { source.addSink(sink); sink.addSource(source); } catch(Exception e) { System.err.println("Error setting source or sink " + e); e.printStackTrace(); System.exit(1); } // play the audio try { System.out.println("Playing..."); source.play(); sink.record(); } catch(Exception e) { System.out.println("Error in playing " + e); 7168ch27.fm Page 463 Friday, September 1, 2006 11:00 AM 464 C H A P T E R 2 7 ■ E X T E N D E D E X A M P L E : H O M E A U D I O S Y S T E M System.exit(1); } } private Object getService(Class cls) { Class [] classes = new Class[] {cls}; ServiceTemplate template = new ServiceTemplate(null, classes, null); ServiceItem item = null; // Try to find the service, blocking till timeout if necessary try { item = clientMgr.lookup(template, null, // no filter WAITFOR); // timeout } catch(Exception e) { e.printStackTrace(); System.exit(1); } if (item == null) { // couldn't find a service in time System.out.println("no service for class " + cls); System.exit(1); } // Return the service return item.service; } } // BasicClient The basic client requires the following classes: • audio.client.BasicClient • All the classes in the audio.common package These classes can be collected into a .jar file such as audio.client.BasicClient.jar and run with a configuration such as the previous one, as follows: java -classpath audio.client.BasicClient.jar audio.client.BasicClient Summary This chapter discussed a framework for distributed audio. Jini makes it fairly straightforward to handle service advertisement and discovery, telling services about each other and generating and handling remote events. The architecture is extensible and just consists of adding in more interfaces and implementations. For example, although this chapter discussed only audio, the same framework could be applied to visual content, either still images or movies. 7168ch27.fm Page 464 Friday, September 1, 2006 11:00 AM 465 ■ ■ ■ C H A P T E R 2 8 Web Services and Jini One of the middleware frameworks being heavily promoted at present is that of Web Services. Web Services are built upon the Simple Object Access Protocol (SOAP) invocation protocol, the Web Services Description Language (WSDL) specification language, and the Universal Description, Discovery, and Integration (UDDI) discovery system. In this chapter, we look at how clients and services from different frameworks can interoperate, with particular reference to Web Services and Jini. Integrating Web Services and Jini While this book has been about Jini, other middleware systems are in use, such as CORBA, Web Services, UPnP, and Salutation, among many others. While it would be very convenient for software developers if all but their favorite middleware were to disappear, this is unlikely to happen. There are technical and political reasons for many of these frameworks to survive, and so software developers will just have to live in a world of multiple middleware systems. Users, on the other hand, just want their different pieces of software to work together, no matter what framework is used. It is up to software developers to figure out how to get a Web Services client to work with, for example, a mixture of Jini and UPnP services. The most common way of getting such mixtures to work is through a bridge. That is, to get a Web Service client to talk to a Jini service, typically a bridge will be an application sitting between them and acting as a Web Service service and a Jini client. In the middle, the bridge translates from one framework to the other, in both directions, as shown in Figure 28-1. Figure 28-1. Bridging between middleware systems 7168ch28.fm Page 465 Friday, September 8, 2006 1:10 PM 466 C H A P T E R 2 8 ■ W E B S E R V I C E S A N D J I N I There are two aspects to a bridge: one is concerned with discovery and the other with invocation. • Discovery allows one middleware client to discover a different middleware service—for example, a CORBA client discovering a Jini service. Typically this is done by the client discovering the bridge and the bridge discovering the service. This may involve two service cache managers (lookup services, name services, etc.). • The bridge allows one middleware client to make calls on another middleware service— for example, a CORBA client making calls on a Jini service. It will convert calls received under one protocol into calls in the other. This will often involve conversion of data from one format to another. Web Services and Jini have special features that make this a simpler task than in general: • Web Services are supposed to use the discovery system UDDI. However, UDDI was designed independently as a global white/yellow/green/blue pages directory, and it turns out to be poorly suited to Web Service discovery. In practice, it seems that most Web Service developers rely on the URLs hard-coded into WSDL files, and don’t do any discovery at all. • In Chapter 1, the section “The End of Protocols” discussed how Jini doesn’t really care about invocation protocols, but only about discovery. Of course, a lot of this book has been about how to invoke a service, but much of that discussion is about the choices that a service developer has. The client doesn’t care. • The XML data types don’t map directly to Java data types and vice versa. However, there are now standardized mappings with implementations from several vendors. While building a bridge is in general a nontrivial process, the standardization of data mappings, the indifference of Jini to invocation protocols, and the hard-coded addresses of Web Services simplifies building a Web Services to Jini bridge in the following way: • Web Services don’t need to be discovered; they just need to be looked up. Web clients don’t need to do discovery since they have the services’ URLs hard-coded in the WSDL document. • Jini clients and services can talk SOAP (the Web Service protocol) just as easily as they can talk any other invocation protocol. The client doesn’t even know what invocation protocol is used, while the service programmer just has to SOAP-enable the services. • Jini clients and services can make use of existing libraries to handle SOAP queries. The case of a Jini client talking to a Web Service can lead to several models, as shown in the following figures. In Figure 28-2, the proxy can be an ordinary (e.g., Jeri) proxy talking back to its service. This service also acts as a Web Service client. 7168ch28.fm Page 466 Friday, September 1, 2006 11:01 AM C H A P T E R 2 8 ■ W E B S E R V I C E S A N D J I N I 467 Figure 28-2. Bridging between a Jini client and a Web Service Figure 28-3 shows a “smart” proxy that talks directly to the Web Service. Figure 28-3. Smart proxy bridging between a Jini client and a Web Service Simple Web Service I’ll illustrate this example with a simple Web Service, for file classification again. To avoid the complexities of Web Service types and with deployment of such services, let’s simplify the service to one that takes a string as file name and returns the MIME type as a string major/ minor. The class is not in a package, allowing simple deployment under Apache Axis. The implementation of this service is then straightforward: /** * FileClassifierService.java */ public class FileClassifierService { public String getMIMEType(String fileName) { if (fileName.endsWith(".gif")) { return "image/gif"; } else if (fileName.endsWith(".jpeg")) { return "image/jpeg"; 7168ch28.fm Page 467 Friday, September 1, 2006 11:01 AM 468 C H A P T E R 2 8 ■ W E B S E R V I C E S A N D J I N I } else if (fileName.endsWith(".mpg")) { return "video/mpeg"; } else if (fileName.endsWith(".txt")) { return "text/plain"; } else if (fileName.endsWith(".html")) { return "text/html"; } else // fill in lots of other types, // but eventually give up and return ""; } public FileClassifierService() { // empty } } // FileClassifierService The Apache Axis server runs under Apache Tomcat and is a popular means of delivering Web Services written in Java. It includes libraries for both the client side and service side. The simplest way of deploying the service under Axis is to copy the implementation source code to the axis/webapps directory, renaming the extension .jws instead of .java. The service can, of course, be written in many different languages. This is usually done by a horrible practice that has become common with Web Services: reverse engineer the imple- mentation given previously to a WSDL specification, and then forward engineer this to your favorite language. We will ignore all such issues here. On the client side, a consumer of this service can then be written most simply as follows: package ws; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.namespace.QName; import ws.MIMEType; public class TestWSClient { public static void main(String [] args) { try { String endpoint = ""; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("", "getMIMEType")); String ret = (String) call.invoke( new Object[] { "file.txt" } ); 7168ch28.fm Page 468 Friday, September 1, 2006 11:01 AM C H A P T E R 2 8 ■ W E B S E R V I C E S A N D J I N I 469 System.out.println("Type of file 'file.txt' is " + ret); } catch (Exception e) { System.err.println(e.toString()); } } } There are other ways of achieving the same result, but this is good enough for the rest of this chapter, which is intended to show how Jini and Web Services can interoperate rather than delve into the arcanities of Web Services. Bridging Between a Jini Client and Web Service, Example 1 A bridge that acts as a Jini service implementing the common.FileClassifier specification used throughout this book, and also as a client to the previous file classification Web Service, can be written by essentially including the Web Service client code from earlier into the implementa- tion of the Jini service methods. The bridge is a normal Jini server advertising the following Jini service implementation: package ws; import common.MIMEType; import common.FileClassifier; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.namespace.QName; /** * FileClassifierImpl.java */ public class FileClassifierImpl implements RemoteFileClassifier { public MIMEType getMIMEType(String fileName) throws java.rmi.RemoteException { try { String endpoint = ""; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("", "getMIMEType")); String ret = (String) call.invoke( new Object[] { fileName } ); return new MIMEType(ret); } catch (Exception e) { 7168ch28.fm Page 469 Friday, September 1, 2006 11:01 AM 470 C H A P T E R 2 8 ■ W E B S E R V I C E S A N D J I N I throw new RemoteException("SOAP failure", e); } } public FileClassifierImpl() throws java.rmi.RemoteException { // empty constructor required by RMI } } // FileClassifierImpl This service can export a Jeri or RMI proxy to a Jini client as we have seen before. Client calls on the proxy are sent to this service, which acts as a Web Service client using the model of Figure 28-2. When this implementation is built and run, it will need the Axis libraries on the Jini service side. Bridging Between a Jini Client and Web Service, Example 2 A service can be written that follows the second pattern in Figure 28-3, simply by changing the inheritance from RemoteFileClassifier to FileClassifier and Serializable. A client then gets a copy of this service and all calls are made locally in the client. package ws; import common.MIMEType; import common.FileClassifier; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.namespace.QName; /** * FileClassifierImpl.java */ public class FileClassifierSerializableImpl implements FileClassifier, java.io.Serializable { public MIMEType getMIMEType(String fileName) throws java.rmi.RemoteException { try { String endpoint = ""; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("", "getMIMEType")); 7168ch28.fm Page 470 Friday, September 1, 2006 11:01 AM C H A P T E R 2 8 ■ W E B S E R V I C E S A N D J I N I 471 String ret = (String) call.invoke( new Object[] { fileName } ); return new MIMEType(ret); } catch (Exception e) { throw new RemoteException(e); } } public FileClassifierImpl() throws java.rmi.RemoteException { // empty constructor required by RMI } } // FileClassifierImpl This has major implications for the classes downloaded to the client! In order to run this service on the client side, it needs access to the class files for the Axis classes Call, Service, and QName. The client cannot be expected to have these, since it doesn’t need to know any details of the implementation. So the Axis libraries have to be placed on an HTTP server and listed in the Jini server’s codebase. The libraries are over 1MB in size, so needing to send these across the network can result in a substantial download to the Jini client. Bridging Between a Web Service Client and Jini Service Forming a bridge between Web Service clients and Jini services follows the same general struc- ture, as shown in Figure 28-4. Figure 28-4. Bridge between a Web Service client and a Jini service In this case, we put the Jini client code into the Web Service implementation. There are a couple of wrinkles in getting this to work properly with Apache Axis and the Tomcat server: • Jini class files • Security policy The Jini class files are not in the classpath for Tomcat. However, Tomcat and Apache allow any extra .jar files required by a Web Service to be placed in special lib directories under the 7168ch28.fm Page 471 Friday, September 1, 2006 11:01 AM 472 C H A P T E R 2 8 ■ W E B S E R V I C E S A N D J I N I service’s WEB-INF directory. Copying the Jini files jsk-lib.jar and jsk-platform.jar to this directory will make them available to the Web Service. This will be part of the deployment mechanisms for the Web Service. The issue of a security policy is potentially more difficult. A server such as Tomcat can be started either with or without a security manager. If it uses a security manager, then the default security policy does not allow a new security manager to be put in place. This blocks a Jini client from installing an RMISecurityManager, and so it cannot download a Jini registrar and find Jini services. Negotiation would then be required with the Tomcat administrator to add in sufficient permissions to the security policy to allow a Jini client to run. If Tomcat is run without a security manager, then it is possible for the Web Service to install one. But it will then need to use a security policy. Up to now we have specified such a policy as a command-line argument, but the command line is not accessible to an Axis Web Service. The workaround is to use System.setProperty() to set the security policy file before installing a security manager. All I/O to the console has to be cleaned up and put into remote exceptions. With these factors, the Web Service to bridge to a Jini service looks like this: /** * FileClassifierJiniService.java */ import common.FileClassifier; import common.MIMEType; import java.rmi.RMISecurityManager; import net.jini.discovery.LookupDiscovery; import net.jini.core.lookup.ServiceTemplate; import net.jini.discovery.LookupDiscoveryManager; import net.jini.lookup.ServiceDiscoveryManager; import net.jini.core.lookup.ServiceItem; import net.jini.lease.LeaseRenewalManager; import java.rmi.RemoteException; public class FileClassifierJiniService { private final static long WAITFOR = 10000; public String getMIMEType(String fileName) throws RemoteException { ServiceDiscoveryManager clientMgr = null; // set a security policy file here since we don't have command-line access System.setProperty("java.security.policy", "/home/httpd/html/java/jini/tutorial/policy.all"); System.setSecurityManager(new RMISecurityManager()); try { LookupDiscoveryManager mgr = new LookupDiscoveryManager(LookupDiscovery.ALL_GROUPS, null, // unicast locators null); // DiscoveryListener clientMgr = new ServiceDiscoveryManager(mgr, new LeaseRenewalManager()); } catch(Exception e) { 7168ch28.fm Page 472 Friday, September 1, 2006 11:01 AM C H A P T E R 2 8 ■ W E B S E R V I C E S A N D J I N I 473 throw new RemoteException("Lookup failed", e); } Class [] classes = new Class[] {FileClassifier.class}; ServiceTemplate template = new ServiceTemplate(null, classes, null); ServiceItem item = null; // Try to find the service, blocking until timeout if necessary try { item = clientMgr.lookup(template, null, // no filter WAITFOR); // timeout } catch(Exception e) { throw new RemoteException("Discovery failed", e); } if (item == null) { // couldn't find a service in time return ""; } // Get the service FileClassifier classifier = (FileClassifier) item.service; if (classifier == null) { throw new RemoteException("Classifier null"); } // Now we have a suitable service, use it MIMEType type; try { type = classifier.getMIMEType(fileName); return type.toString(); } catch(java.rmi.RemoteException e) { throw e; } } public FileClassifierJiniService() { // empty } } // FileClassifierJiniService The steps to get all this running are as follows: 1. Download and install Apache Tomcat and Axis. 2. Edit the FileClassifierJiniService.java file to point to a valid security policy file on your system. 7168ch28.fm Page 473 Friday, September 1, 2006 11:01 AM 474 C H A P T E R 2 8 ■ W E B S E R V I C E S A N D J I N I 3. Copy the FileClassifierJiniService.java file to the Tomcat webapps/axis directory as FileClassifierJiniService.jws, changing the file extension. 4. Copy the Jini libraries jsk-lib.jar and jsk-platform.jar to the Tomcat webapps/axis/ WEB-INF/lib directory. 5. Start Tomcat without a security manager (by default it starts without one). 6. Start a Jini lookup service and any Jini implementation of the FileClassifier interface that has been given in this book. 7. Run the Web Service client ws.TestWS2JiniClient. This procedure should run the Web Service, which finds the Jini service, makes a call on it, and returns the result to the Web Service client. Summary Bridging between different types of services is not an easy matter, as there are many complex issues to be considered. Nevertheless, it is possible to build upon work performed to build Java Web Services and their Java clients, allowing you to use Jini services and clients in a relatively simple manner. 7168ch28.fm Page 474 Friday, September 1, 2006 11:01 AM 475 Index ■A A/V formats, 438 abstract leases, 76 access limitations, 175 ACID properties, 353 action listeners, 192 activation (extension to RMI), 389 activation server (phoenix), 390–391 activation, use of configuration, 407–409 LookupDiscoveryService interface, 419–430 maintaining state information, 401–407 renewing leases, 410–419 server, 393–398 service, 391–393 service, running, 398–401 services, lazy and nonlazy, 401 active references, 25 additive permissions, 174 Address class, 56 administration, zero, 21 alive, staying, 47 AllPermission, 172, 173 anonymous classes, 191 Ant build.xml file, 27–29 description, 27 directory structure, 27–28 parameters, 27 project files, 30–32 targets, 28 antBuildFiles directory, 30 Apache Axis server, 468 Apache license, open-source, 1, 5 API (application programming interface), 2 applications, partitioning, 16–18 Arnold, Ken, 91 attribute matching, 55 attributes registered, 65 audio stream, push/pull, 439 audio system example audio-visual content parameters, 438 basic client, 462–464 content interfaces, 441 content sinks, 447–450 description, 437, 438 file source servers, 457–461 HTTP sinks, 446 HTTP source, 443–445 linkages between layers, 442 Ogg Vorbis interface, 445 playlists, 461 sink implementation, 450–453 sink servers, 453–456 source and sink interfaces, 439–441 source servers, 456–457 transport interfaces, 442 authenticating servers, 338–343 authentication of clients, 303, 304, 344–349 required by clients, 343–344 required by servers, 349–350 author’s Web site, 249 authorization, 303, 350 AWT events, 216 ■B banking system, 4 books Design Patterns, 215 The Jini Specifications, Second Edition, 91 BrevilleExtraLiftToaster example, 68–69, 70 bridge, Web Service-Jini discovery and invocation, 465–467 examples, 469–471, 472–474 security policy, 472 structure, 471 broadcast discovery, 43–51 broadcast range, 49 build directory, 27, 28 build.xml file, 27–29 7168IDX.fm Page 475 Friday, September 1, 2006 11:02 AM 476 ■I N D E X ■C cache, monitoring, 246–248 CD databases, 456 certificates, signed, 178 changes in services, leasing. See service changes, leasing changes in services, monitoring, 230–235 class definitions loading, 69 uploading, 177 class files variables, 30 classes accessibility from CLASSPATH, 21 anonymous, 191 changes in Jini 2.0, 22 ConfigUtils, 274 convenience, 56 DiscoveryEvent, 45–47 DiscoveryListener, 44 file delivery to client, 23 FileClassifierImpl, 128, 133, 153 FileClassifierLandlord, 208–211 FileClassifierLeasedResource, 206–207 HttpmdUtil, 323 in .jar files, 23 Jeri, 136–140 JoinManager, 167–170 JRMP, 140–141 LandlordLease, 79 leased FileClassifier, 202–205 LeaseRenewalManager, 75 LeaseRenewalService, 410 lookup services, 50–51 LookupDiscovery, 43, 161 LookupDiscoveryManager, 164–166 LookupLocatorDiscovery, 163–164 MIMEType, 91–93 multiple class files, 192 non-RMI proxy implementation, 147 problem domain, 185–187 Reaper (cleanup), 207–208 ServiceItem, 60 ServiceMatches, 69 ServiceRegistrar, 50–51, 59, 67–69, 179 ServiceRegistration, 60, 64 ServiceType, 57 UIDescriptor, 376–379 UnicastRemoteObject, 83, 118 unknown, 435 See also LookupLocator class; Service- Starter class classifer, file, 222–230 classifying files, 87 CLASSPATH environment variable, 22, 189 clean directory, 28 client ignorance, 19 clients audio system example, 462–464 authentication of, 344–349 confidentiality, 330 description, 94 exception handling, 104 lookup, 12–13 multicast, 99–104 proxy verification, 326 requiring authentication, 343–344 security requirements, 177–178 structure, 14–15 transactions example, 366–371 unicast, 94–99 client-side constraints, 312 ClockDevice package, 261–264 ClockFrame service, 252–259 clocks example. See flashing clocks example code sources, 180 codebase, specifying, 271–274 command-line options, 265 Comment class, 56 commit protocol, two-phase, 353 competitors, 4 compile target, 28 compiler, rmic, 118, 119 complete service, uploading, 105–115 components, 9 ComputerTimer driver, 260 ComputerTimer service, 251 confidentiality clients, 330 description, 303 invocation constraints, 304 SSL server, 331–332 configuration codebase, 271–274 command-line options, 265 file classifier server, 315 7168IDX.fm Page 476 Friday, September 1, 2006 11:02 AM 477■I N D E X Find it faster at generic servers, 274–279 runtime configuration, 265 runtime information, 274–279 service ID, 268–271 specifying, 267 zero configuration, 23 ConfigurationFile language, 266 ConfigUtils class, 274 constraints alternative, 344 client-side, 312 mandatory and preferred, 304 on invocation, 303 on methods, 305 convenience classes, 56 cookies, 77, 81 ■D debugging, 25 deploy directory, 28 Design Patterns book, 215 Deutsch, Peter, 3 device, finding on network, 196 diagrams landlord classes, 78, 79, 80 UML, 39, 40, 45 DialogFactory, 375 digital signatures, creating, 181 directories antBuildFiles, 30 build, 27, 28 clean, 28 deploy, 28 dist, 27, 28 httpd.classes, 27 lib, 23 resources, 27 src, 27, 30 directory structure, Ant, 27–28 discovery between middleware services, 466 DiscoveryEvent class, 45–47 DiscoveryGroupManagement interface, 162 DiscoveryListener class, 44 DiscoveryLocatorManagement interface, 162 DiscoveryManagement interface, 162 dist directory, 27, 28 distance service, 196 Djava.rmi.server.logCalls flag, 25 Djava.security.debug flag, 25 djinns, 171 Dnet.jini.discovery.debug flag, 25 ■E editors example, 53–55 Eight Fallacies, 3, 4 encumbered formats, 438 Entry class attribute matching, 55 attributes registered, 65 convenience classes, 56 description, 54 restrictions, 55 uses of, 57 entry points, 373 environment variable CLASSPATH, 22, 189 ERI. See Jeri (Jini Extensible Remote Invoca- tion) errors garbage collection-related, 24 HTTP server-related, 23 Java-related, 21 Jini-related, 22 localhost, 23 lookup-related, 24 network configuration, 23 preferred value, 24 proxy verification, 328–330 RMI stubs-related, 24 events file classifer, 222–230 listener lists, 218–221 listener sources, 221 listeners, leasing, 230 models, 215 registration, 217 examples BrevilleExtraLiftToaster, 68–69, 70 file editors, 53–55 FooLandlord, 83–86 InvalidLookupLocator, 36–39 matching, 196–202 MulticastRegister, 45–49 registering FileClassifierImpl, 168–170 security policy file, 176, 183 server side-specific action listener, 192 unicast server, 61–64 UnicastRegister, 39–43 Web Service-Jini bridge, 469–471, 472–474 See also audio system example; FileClas- sifier example; flashing clocks example; transactions example 7168IDX.fm Page 477 Friday, September 1, 2006 11:02 AM 478 ■I N D E X exceptions clients, 104 security, 174 explicit proxy, 134, 218, 231 explicit references, 124 exporter for Jeri, 120 exporting for Java, 118 exporting in Jini 2.0, 119 exporting services, 23 Extensible Remote Invocation. See Jeri (Jini Extensible Remote Invocation) ■F factories current set, 375 FileClassifier example, 380–382 implementation, 190 interfaces from, 374 landlord lease, 77, 79 marshalling, 375 failure modes of methods, 91 failure, transaction, 357 federations, 2 fiddler service, 421–422 file classifer, 222–230 file classifier server, 312–318 file editors example, 53–55 file source servers, 457–461 FileClassifier example back-end service, 133 class definition, loading, 114 client, 132 client implementation, 112–114 code, 89, 93 factory, 380–382 interface, 93, 132, 379 location of class file, 114 mixed RMI and non-RMI proxies, 131, 151–159 non-RMI proxy, 142–151 non-RMI proxy classes, 147 non-RMI proxy, running, 148 overall implementation, 105 RemoteFileClassifier interface, 132, 134 RMI proxy, 132–142 running, 114–115 server implementation, 106–112, 124, 154–156 service specification, 90 FileClassifierImpl class, 128, 133, 153 FileClassifierLandlord class, 208–211 FileClassifierLeasedResource class, 206–207 files classifying, 87 signing, 181 flags for debugging, 25 flashing clocks example ClockDevice package, 261–264 ClockFrame service, 252–259 ComputerTimer driver, 260 ComputerTimer service, 251 description, 7–9, 249 downloading compiled classes, 7 multiple clocks, 260, 264 runtime behavior, 264 TickerTimer driver, 259 TickerTimer service, 250 Timer service, 249 UPnP solution, 249 FooLandlord example, 83–86 formats, A/V, 438 FrameFactory, 375 fully qualified path name, 21 ■G Gamma, Eric, 215 garbage collection, Jeri, 124–125 garbage collection-related errors, 24 getGroups() method, 51 getHost() method, 39 getLocator() method, 51 getPort() method, 39 getRegistrar() method, 39–41 getServiceID() method, 51 globally unique identifier (GUID), 60 Gosling, James, 3 groups of services, 43 GUID (globally unique identifier), 60 ■H handback data, 217 home audio system example. See audio sys- tem example hostile lookup services, 171, 172–173, 178–181 HTTP server errors, 23 httpd.classes directory, 27 HTTPMD (HTTP + Message Digest) protocol, 322–325 HttpmdUtil class, 323 7168IDX.fm Page 478 Friday, September 1, 2006 11:02 AM 479■I N D E X Find it faster at ■I icons, 387 identity management authenticating servers, 338–343 clients requiring authentication, 343–344 clients, authentication of, 344–349 constraints, alternative, 344 description, 334 JAAS (Java Authentication and Authori- zation Service), 335–336 keystores, 336–337 servers requiring authentication, 349–350 ignorance, client, 19 images, 387 implementation, 10 inexact service matching, 193–195 inheritance in project files, 30 installation process, 6 integrity of transport client, 318 description, 303, 318 invocation constraints, 304 SSL or TLS server, 320–322 TCP server, 319 interfaces as entry points, 373 configuration, 265 DiscoveryGroupManagement, 162 DiscoveryLocatorManagement, 162 DiscoveryManagement, 162 factory objects, 374 FileClassifier, 93 LeasedResource, 81–82 LeaseRenewalService, 412–419 LookupDiscoveryService, 419–430 MutableFileClassifier, 222, 401 NameEntry, 187–189, 191, 193 Ogg Vorbis, 445 ProxyAccessor, 223 ProxyPreparer, 307–312 remote, 121 RemoteEventListener, 218–221 RemoteFileClassifier, 132, 134 ServiceDescriptor, 285–287 ServiceDiscoveryManager, 237 ServiceItemFilter, 238, 241–242 source and sink, 439–441 introspection library, 434 InvalidLookupLocator example, 36–39 invocation constraints, 303 ■J JAAS (Java Authentication and Authorization Service), 335–336 .jar files, 23 Java Media Framework (JMF), 377 Java Remote Method Protocol (JRMP), 117, 137, 140–141 Java security model, 181 Java virtual machine (JVM), 31, 60 java.lang.Object method, 50 Java-related errors, 21 JComponentFactory, 375 jdb debugger, 25 JDialogFactory, 375 JDK 1.2 security model, 171 Jeri (Jini Extensible Remote Invocation) classes, 136–140 configuration, 122–124 exporter class, 119 garbage collection, 124–125 Java Remote Method Protocol (JRMP), 117, 137, 140–141 proxy accessor, 125 remote interfaces, 121 RMI, 117–119 standard exporter, 120 JFrameFactory, 375, 376 Jini meaning, 2 success stories, 3 uses, 2 Jini 2.0 configuration mechanism, 122 ConfigUtils class, 274 constraints, 304 dynamic policy use, 350 explicit proxy, 134, 218, 231 explicit references, 124 exporting and unexporting, 119 HttpmdUtil class, 323 .jar packages repackaged, 23 Java security mechanism, 303 Jeri instead of RMI, 24 logging API, 25 logging package, 281 LookupDiscovery constructors, 44 main classes changed, 22 ProxyAccessor interface, 223 runtime configuration, 265 Jini 2.1 files for compilation, 38 Jini Extensible Remote Invocation. See Jeri (Jini Extensible Remote Invocation) 7168IDX.fm Page 479 Friday, September 1, 2006 11:02 AM 480 ■I N D E X jini.home parameter, 27 jini-core.jar file, 38 Jini-related errors, 22 JMF (Java Media Framework), 377 JoinManager class, 167–170 JRMP (Java Remote Method Protocol), 117, 137, 140–141 jsk-lib.jar, 38 jsk-platform.jar, 38 JTextArea, 60 JVM (Java virtual machine), 31, 60 JWindowFactory, 375 ■K keepalive means, 47 KeyEvent events, 215 keystores, 181, 336–337 keytool, 181 Konno, Satoshi, 252 ■L landlord interface, 82 landlord packages, 77–81 LandlordLease class, 79 LaunchAll program, 36 lazy services, 401 LeasedResource interface, 81 LeasePeriodPolicy interface, 82 LeaseRenewalService interface, 412–419 leases abstract, 76 cancelling, 74 cookies, 77, 81 description, 73 event listeners, 230 expiring, 25, 74 granting and handling, 75 interfaces, 81–82 landlord class diagrams, 78, 79, 80 landlord packages, 77–81 policies, 82 requesting and receiving, 73 typical lease time, 73 See also renewing leases levels, severity, 281 lib subdirectory, 23 licensing model, 1, 5 listeners action listeners, 192 DiscoveryListener class, 44 MulticastRegister, 45 WindowListener, 191 See also events listing services, 431–433 localhost parameter, 27, 274 localhost, error in use of, 23 Location class, 56 locators, lookup, 161–166, 175 logging, 305–306 logging API, 25 logging package description, 281 LookupDiscovery class, 281–283 lookup locators, 161–166, 175 lookup service-related errors, 24 lookup services broadcast discovery, 43–51 definition, 9 description, 35 discovery, 44 groups, 43 hostile, 171, 172–173, 178–181 locating, 35 multiple, 43 ServiceRegistrar class, 50–51 unicast discovery, 36–43 See also reggie lookup service; services, registering LookupCache, 243–248 LookupDiscovery class description, 43 logging, 281–283 multicast search, 161 LookupDiscoveryManager class, 164–166 LookupDiscoveryService interface fiddler service, 421–422 use of, 422–430 LookupLocator class description, 36 getHost() and getPort() methods, 39 getRegistrar() method, 39–41 LookupLocatorDiscovery class, 163–164 7168IDX.fm Page 480 Friday, September 1, 2006 11:02 AM 481■I N D E X Find it faster at ■M Magneti Marelli Motorsport project, 4 mahalo transaction manager, 355 matching attributes, 55 matching example, 196–202 matching services, 70 methods, constraints on, 305 middleware, 2, 90, 117 MIME types, 87 MIMEType class, 91–93 monitoring cache, 246–248 MouseEvent events, 215, 216 MP3 format encumbered, 438 interface for, 446 no player in JMF, 447 pulled, 439 MPEG format movie player in JMF, 447 MPEG-7, 439, 456 multicast clients, 99–104 description, 35 discovery, 43–51, 175 range, 49 MulticastRegister example, 45–49 multiple class files, 192 MutableFileClassifier interface, 222, 401 ■N Name class, 56 NameEntry interface, 187–189, 191, 193 names of projects, 31 Nedap N.V. project, 4 network configuration error, 23 network layer, dependence on, 23 “network plug and play” definition of Jini, 21 network plug and play, 1 networked environments, 1 networks, 9 nonactivatable server, 297–300 nonactivatable service, 286, 287–296 norm service, 411–412 ■O Ogg Vorbis format, 438 interface, 445 open-source Apache license, 1, 5 Orange project, 5 Orbitz project, 5 ■P packages Java-related errors, 21 Jini-related errors, 22 landlord, 77–81 PanelFactory, 375 parameters Ant, 27 RMI, 179 set by preferences, 176 paranoia, 180 partitioning applications, 16–18 path name, fully qualified, 21 PayableFileClassifierImpl service, 358–363 permissions AllPermission, 172, 173 granted to protection domains, 182 phoenix activation server, 390–391 pictures, 387 playlists, 461 “plug and play” definition of Jini, 21 plug and play, network, 1 points of failure, transaction, 357 policies for leases, 82 policy files example, 176, 183 security, 171, 183 preferences, 176 preferred constraints, 304 preferred value error, 24 print statements for debugging, 25 printer, finding on network, 196 problem domain, 185–187 project files, 30–32 project names, 31 PropertyChange events, 215 protection domains, 180 protocols choices, 122 end of, 18–19 HTTPMD (HTTP + Message Digest), 322–325 SSL (Secure Sockets Layer), 307, 320–322 TCP (Transmission Control Protocol), 306 7168IDX.fm Page 481 Friday, September 1, 2006 11:02 AM 482 ■I N D E X proxies, service choices, 127–131 description, 13–14, 104 explicit, 134, 218, 231 fat, 127 FileClassifier example, 132–159 mixed RMI and non-RMI, 131, 151–159 non-RMI, 129 ProxyPreparer interface, 307–312 RMI, 128 proxy objects for lookup service, 50, 59 maintaining state information, 60 RMI, 60 proxy verification clients, 326 errors, 328–330 HTTPMD, 322–325 SSL truster servers, 327–328 verifiers, 325 ProxyAccessor interface, 223 ProxyPreparer interface, 307–312 push/pull audio stream, 439 ■R random ports used by RMI, 178 range of broadcast, 49 Reaper (cleanup) class, 207–208 references active, 25 strong and weak, 124 reggie lookup service description, 35 HTTPMD, 325 location of objects, 180 RMI, 50 ServiceStarter class, 300 registrar, 6 registration of events, 217 registration. See services, registering remote events, 216 remote interfaces, 121 remote method invocation. See RMI remote procedure call (RPC) communica- tions, 3, 105, 151 RemoteEventListener interface, 218–221 RemoteFileClassifier interface, 132, 134 renewing leases LeaseRenewalManager class, 75 LeaseRenewalService class, 410 LeaseRenewalService interface, 412–419 norm service, 411–412 Representational State Transfer (REST) com- munity, 457 resources directory, 27 restrictions on Entry class, 55 RMI (remote method invocation) extending UnicastRemoteObject, 118 Jeri, 117–119 JRMP-style RMI, 137 parameters, 179 proxies, service, 128 random ports, 178 stubs-related errors, 24 thin proxy to fat service back-end, 105 traditional, 118 use of, 2 rmic compiler, 118, 119 rmid (replaced by phoenix), 390–391 RPC (remote procedure call) communica- tions, 3, 105, 151 Rubean project, 4 runtime configuration, 265 ■S Secure Socket layer (SSL). See SSL security access limitations, 175 client requirements, 177–178 combinations, 332–334 djinns, 171 exceptions, 174 file classifier server, 312–318 invocation constraints, 303 JDK 1.2 model, 171 logging, 305–306 methods, constraints on, 305 paranoia, 180 permissions, 172, 173, 182 policy files, 171, 176, 183 policy for Web Service-Jini bridge, 472 protection domains, 180 ProxyPreparer interface, 307–312 service security requirements, 175–176 See also identity management 7168IDX.fm Page 482 Friday, September 1, 2006 11:02 AM 483■I N D E X Find it faster at SecurityManager, 171 semantic events, 215 sequence diagrams, UML, 39, 40, 45 server side-specific action listener, 192 server, unicast, 61–64 servers Apache Axis, 468 authenticating, 338–343 file classifier, 312–318 file source servers, 457–461 generic, 274–279 nonactivatable, 297–300 proxy verification, 327–328 requiring authentication, 349–350 service providers, 104 sink servers, 453–456 source servers, 456–457 structure, 15–16 trusted, 327–328 service changes, leasing client, 211–213 description, 202 FileClassifierLandlord class, 208–211 FileClassifierLeasedResource class, 206–207 leased FileClassifier class, 202–205 Reaper (cleanup) class, 207–208 server, 205–206 service ID, 65, 67, 268–271 service matching, inexact, 193–195 service proxies. See proxies, service ServiceDiscoveryManager class cache, monitoring, 246–248 filtering services, 241–242 interface, 237 LookupCache, 243–248 services, cache of, 242–245 services, finding immediately, 238–241 ServiceInfo class, 56 ServiceItem class, 60 ServiceItemFilter interface, 238, 241–242 ServiceMatches class, 69 ServiceRegistrar class description, 50–51, 59, 179 finding services, 67–69 ServiceRegistration class, 60, 64 ServiceRegistration method, 50 services changes, monitoring, 230–235 ClockFrame, 252–259 ComputerTimer, 251 defining common knowledge, 87 definition, 9 description pseudocode, 287 distance service, 196 exporting, 23 fiddler, 421–422 groups of, 43 lister program, 431–433 nonactivatable, 286, 287–296 PayableFileClassifierImpl, 358–363 signing, 182 support services, 18 supported, 1 TickerTimer, 250 Timer, 249 transactions example, 363–366 unknown, 433 uploading completely, 105–115 See also service changes, leasing; servic- es, finding; services, registering services, cache of, 242–245 services, finding description, 67 immediately, 238–241 matching, 70 multiple matches, 69 ServiceRegistrar class, 67–69 specifying, 90 services, registering description, 10–11, 59 generating ServiceEvent type events, 231 join manager, 167–170 register(), 60 ServiceItem class, 60 ServiceRegistrar class, 50–51, 59, 179 ServiceRegistration class, 60, 64 ServiceStarter class description, 285 nonactivatable server, 297–300 nonactivatable service, 286, 287–296 reggie lookup service, 300 ServiceDescriptor interface, 285–287 ServiceTemplate class description, 70 specifying sought service, 67 ServiceType class, 56, 57 severity levels, 281 signatures, creating, 181 signed trust certificates, 178 signing services, 182 signing standard files, 181 7168IDX.fm Page 483 Friday, September 1, 2006 11:02 AM 484 ■I N D E X Simple Object Access Protocol (SOAP) invo- cation protocol, 465, 466 sinks content sinks, 447–450 HTTP sinks, 446 implementing, 450–453 servers, 453–456 sink interfaces, 439–441 sleep() method, 47 SOAP (Simple Object Access Protocol) invo- cation protocol, 465, 466 Sommers, Frank, 4, 125 source files, 27, 30 sources of code, 180 specification, 10 specifying services, 90 src directory, 27, 30 src.files variable, 30 SSL (Secure Sockets Layer) configuration, 307 integrity checking, 320–322 server confidentiality, 331–332 trusted servers, 327–328 standard files, signing, 181 Starter Kit installation process, 6 state information, maintaining, 60, 401–407 Status class, 56 staying alive, 47 strong and weak references, 124 stubs-related errors, 24 subtractive permissions, 174 success stories, 3 support services, 18 supported services, 1 Swing JTextArea, 60 staying alive, 47 ■T targets, Ant, 28 taxi-driver, Jini, 217 TCP (Transmission Control Protocol), 306 The Jini Specifications, Second Edition book, 91 threads, daemon and user, 47 TickerTimer driver, 259 TickerTimer service, 250 time to live (TTL), 43, 50 Timer service, 249 TLS (Transport Layer Security), 320–322 toaster example, 68–69, 70 transactions mahalo transaction manager, 355 manager, 354 overview, 353 participants, 355 two-phase commit protocol, 353 See also transactions example transactions example AccountsImpl service, 363–366 client, 366–371 description, 355–358 PayableFileClassifierImpl service, 358–363 transition match events, 231 Transmission Control Protocol (TCP), 306 transport layer as A/V parameter, 438 Transport Layer Security (TLS), 320–322 transport protocol choices, 122 trust certificates, signed, 178 trusted servers, 327–328 TTL (time to live), 43, 50 two-phase commit protocol, 353 ■U UDD, 466 UDP (User Datagram Protocol), 43 UIDescriptor class attributes, 378 description, 376 role, 377 toolkit, 377 UML sequence diagrams, 39, 40, 45 unencumbered formats, 438 unexporting, 119 unicast clients, 94–99 description, 35 discovery, 36–43, 175 server example, 61–64 UnicastRegister example, 39–43 UnicastRemoteObject class, 83 UnicastRemoteObject, extending, 118 universally unique identifier (UUID), 70, 77 unknown classes, 435 unknown services, 433 unlazy services, 401 uploading complete services, 105–115 UPnP solution to flashing clocks, 249 User Datagram Protocol (UDP), 43 user threads, 47 UUID (universally unique identifier), 70, 77 7168IDX.fm Page 484 Friday, September 1, 2006 11:02 AM 485■I N D E X Find it faster at ■V value error, 24 variables. See environment variables Venners, Bill, 181 verifiers, 325 versions of Jini and Java, 22 versions of Jini. See Jini 2.0 and Jini 2.1 ■W Waldo, Jim, 91 WAV format interface for, 446 uncompressed, 438 weak and strong references, 124 Web Services integrating with Jini, 465–467 simple, 467–469 XML data types, 90 Web sites author’s, 249 banking system, 4 failure modes of methods, 91 JAAS (Java Authentication and Authori- zation Service), 335–336 Java security model, 181 Jeri, 125 Jini, 5 Magneti Marelli Motorsport project, 4 Nedap N.V. project, 5 Orange project, 5 Orbitz project, 5 success stories, 3 wildcarding, 55 WindowFactory, 375 WindowListener, 191 ■Z zero administration, 21 zero configuration, 23 7168IDX.fm Page 485 Friday, September 1, 2006 11:02 AM

Các file đính kèm theo tài liệu này:

  • pdfFoundations of Jini 2 Programming.pdf
Tài liệu liên quan