Upload
others
View
7
Download
0
Embed Size (px)
Citation preview
Java Programming
Advanced Techniquesfor Building
Distributed Applications
Gerald BroseAndreas Vogel
Keith Duddy
Third Edition
Wiley Computer Publishing
16339709
NEW YORK • CHICHESTER • WEINHEIM • BRISBANE • SINCAPORE • TORONTO
Contents
Foreword to the First EditionForeword to the Second EditionForeword to the Third EditionAcknowledgmentsIntroductionAbout the Authors
Chapter 1 Benefits of Java Programming with CORBA
1.1 What Does Java Off er CORBA Programmers?1.1.1 Object-Oriented Programming Language1.1.2 Portability of Applications across Platforms1.1.3 Web Integration
1.1.3.1 Problems in Traditional Web Applications1.1.3.2 Using Java Applets1.1.3.3 Java Servlets and JSP
1.1.4 Component Models1.1.4.1 JavaBeans1.1.4.2 Enterprise JavaBeans
1.2 What Does CORBA Offer Java Programmers?1.2.1 OMGIDL Defmed Interfaces1.2.2 Programming Language Independence1.2.3 Location Transparency and Server Activation
XXVII
xxixxxxi
xxxiiixxxv
xli
1
2234467889
10111112
xiv Contents
1.2.4 Automatic Stub and Skeleton Code Generation 121.2.5 Reuse of CORBA Services and Facilities 131.2.6 Vendor Independence through ORB Interoperability and CodePortability 14
1.3 Java ORBs and Java RMI 14
Chapter2 CORBA Overview 17
2.1 The Object Management Group 182.1.1 OMG's Goals 182.1.2 The Organizational Structure of OMG 19
2.1.2.1 PTC Task Forces and Special Interest Groups 192.1.2.2 DTC Task Forces and Special Interest Groups 212.1.2.3 Archi tecture Board Special Interes t Groups 23
2.1.3 OMG Technology Adoption Process 23
2.2 The Object Management Architecture 242.2.1 Overview of the OMA 252.2.2 Core Object Model 25
2.2.2.1 Scope of the Core Object Model 262.2.2.2 Components and Profiles 262.2.2.3 Concept Definitions 2 72.2.2.4 Interfaces and Substitutability 282.2.2.5 Inheritance 29
2.2.3 The Reference Model 302.2.3.1 Object Request Broker (ORB) 312.2.3.2 Object Services 322.2.3.3 Common Facilities 322.2.3.4 Domain Interfaces 332.2.3.5 Specification Adoption in the OMG 33
2.3 Common Object Request Broker Architecture (CORBA) 332.3.1 Overview 342.3.2 Object Model 36
2.3.2.1 Servants and Object References 362.3.2.2 Types 372.3.2.3 Interfaces 372.3.2.4 Valuetypes and Abstract Interfaces 372.3.2.5 Operation Semantics 382.3.2.6 Operation Signatures 382.3.2.7 Attributes 392.3.2.8 Exceptions 39
2.3.3 ORB Structure 402.3.3.1 Client Stubs 412.3.3.2 Dynamic Invocation Interface 412.3.3.3 Implementation Skeleton 422.3.3.4 Dynamic Skeleton Interface (DSI) 422.3.3.5 Object Adapters 42
Contents xv
2.3.4 OMG Interface Definition Language (IDL) 432.3.4.1 Lexical Analysis 432.3.4.2 Modules and Interfaces 442.3.4.3 Inheritance 462.3.4.4 Multiple Inheritance 472.3.4.5 Typesand Constants 482.3.4.6 Operations and Attributes 532.3.4.7 Valuetypes 542.3.4.8 Contexts 58
2.3.5 ORB and Object Interfaces 592.3.5.1 Stringified Object References 592.3.5.2 Managing Object Ref er ences 592.3.5.3 Initialization 66
2.3.6 The Portable Object Adapter 672.3.6.1 POA Overview 672.3.6.2 POA Architecture 682.3.6.3 Object and Servant Lifetimes 692.3.6.4 POA Policies 712.3.6.5 POA Life Cycle 742.3.6.6 Using the POA to Create Object Ref erences 772.3.6.7 Discovering the Mappings in a POA 782.3.6.8 The Current Interface 78
2.3.7 Language Mappings 792.3.7.1 C 792.3.7.2 C++ 792.3.7.3 Smalltalk 802.3.7.4 COBOL 802.3.7.5 Lisp 802.3.7.6 Python 80
2.3.8 Interoperability 812.3.8.1 The ORB Interoperability Architecture 812.3.8.2 General Inter-ORB Protocol 812.3.8.3 Internet Inter-ORB Protocol 822.3.8.4 Other Approaches 82
2.3.9 TVpeCode, Any, and Dynamic Any 822.3.9.1 Any 832.3.9.2 Language Mapping for Any 832.3.9.3 TypeCode 832.3.9.4 DynAny 87
2.3.10 Dynamic Invocation and Dynamic Skeleton Interfaces 902.3.10.1 Requests (DU) 902.3.10.2 Deferred Synchronous Invocation 912.3.10.3 ServerRequests (DSI) 912.3.10.4 Named Value Lists and Contexts 92
2.3.11 Interface Repository 922.3.11.1 The Abstract Base Interfaces 93
xvi Contents
2.3.11.2 Nondata-type Interfaces 952.3.11.3 Data Type Interfaces 952.3.11.4 IDL Definitions of the IR Interfaces 962.3.11.5 The Multiply Derived Interfaces 992.3.11.6 Interfaces Derived from TypedefDef 1022.3.11.7 Interfaces Derived from IDLType 1032.3.11.8 Interfaces Derived Directly from Contained 1052.3.11.9 Repositorylds 107
Chapter 3 Overview of Java and Java ORBs 109
3.1 Interface, Class, and Object 110
3.2 Inheritance 1103.2.1 Classes 110
3.2.2 Interfaces 112
3.3 Methods and Exceptions 113
3.4Packages 115
3.5Objects 116
3.6 Java Applets 118
3.7 Java Servlets 119
3.8 Hello World Example 1203.8.1 Interface Specification 1203.8.2 Implementation 1203.8.3 Application 1213.8.4 Applet 1223.8.5 Servlet 124
3.9 JavaBeans 126
3.10 Java ORB Terminology 129
3.11 Clients and Servers as Java Applications 1303.11.1 Stub and Skeleton Code 131
3.11.2 ORB and Object Adapter 132
3.12 Clients as Java Applets 133
3.13 Clients as Servlets 133
3.14 Servers as Java Applets 134
3.15 Clients and Servers Implemented with Non-Java ORBs 138
3.16 Standards and Products 138
Chapter 4 A First Java ORB Application 141
4.1 Summary of the CORBA Development Process 142
4.2 Environment Setup 144
4.3 Interface Specification 144
Contents xvii
Chapter 5
4.4 Compiling the IDL
4.5 A Client as a Java Application4.5.1 Generated Java Interface4.5.2 Initializing the ORB4.5.3 Obtaining an Object Reference4.5.4 Invoking the Operation4.5.5 Compiling and Executing the Client
4.6 A Client as an Applet4.6.1 Anchoring the Applet into HTML4.6.2 Initializing the Applet4.6.3 Locating Objects4.6.4 Handling Applet Events4.6.5 Compiling and Executing the Applet
4.7 An Object Implementation
4.8 A Server4.8.1 Compiling and Starting the Server
4.9 Extending the Hello World Example4.9.1 Interface Specification4.9.2 Parameter Mapping4.9.3 A Client
4.9.3.1 Invoking the Operation4.9.4 An Applet
4.9.4.1 Invoke the Operation4.9.5 Object Implementation
OMG IDL to Java Mapping
5.1 Reserved Names
5.2 Basic Data Types5.2.1 Boolean5.2.2 Char and Wide Char5.2.3 Octet5.2.4 Integer Types5.2.5 Floating-Point T^pes5.2.6 Fixed-Point5.2.7 String Types
5.3 Holder Classes
5.4 Helper Classes
5.5 Enums
5.6 Struct
5.7 Unions
5.8 TVpedef
145
146147147148149149
150150151152153154
155
156158
159159160160161162163164
167
167
168168168169169169169169
170
171
172
174
174
176
xviii Contents
Chapter 6
5.9 Exception Type5.9.1 User-Defined Exceptions5.9.2 CORBA System Exceptions
5.10 Arrays
5.11 Sequences
5.12 The Any Type5.12.1 General Methods on the Class Any5.12.2 IDL Predefmed Types5.12.3 User-Defined Types
5.13 Valuetypes5.13.1 Stateful Valuetypes5.13.2 Abstract Valuetypes5.13.3 Valuetype Inheritance5.13.4 Value Box TVpes
5.14 Interfaces5.14.1 Portability Issues5.14.2 Java ORB Portability Interfaces
5.14.2.1 A Portable CORBA Object Implementation5.14.2.2 Portable Streams
5.14.3 Client-Side Mapping5.14.4 Server-Side Mapping
5.14.4.1 Inheritance versus TieApproach5.14.4.2 Object Lifetime and Threading
5.15 Constants5.15.1 Constants within Interfaces5.15.2 Constants outside Interfaces
5.16 Attributes
5.17 Operations5.17.1 Parameter Semantics5.17.2 Mapping from Operations to Methods5.17.3 Portable Stub Implementation5.17.4 Portable Skeleton Implementation5.17.5 Parameter Management
5.18 Inheritance
5.19 Modules and Name-Scoping Rules
5.20 Mapping from Java to IDL5.20.1 The RMI/IDL Subset of Java
ORB Run-Time System
6.1 Object Interface6.1.1 get_interface()6.1.2 is_nil()6.1.3 duülicateO and releaseO
177177179
179
182
184184185185
188188190190191
192194196197197201205206208
210210210
211
211211213213215218
218
221
223224
227
228229229229
Contents xix
6.1.4 is_a() 2306.1.5 non_existent() 2306.1.6 is_equivalentO 2306.1.7 hashO 2316.1.8 get_policyO 2316.1.9 get_domain_managers() 2316.1.10 set_policy_overrides 232
6.2 ORB Interface 2326.2.1 ORB Initialization 2326.2.2 Converting Object References into Strings and Vice Versa 2336.2.3 Obtaining a POA Reference 234
6.3 Portable Object Adapter Interface 2356.3.1 Reference creation 2356.3.2 Implicit Activation and Deactivation 2356.3.3 Child POAs 238
6.4 IVpeCode Interface 2406.4.1 Types Used by TypeCodes 2406.4.2 Identifying and Comparing TypeCodes 2436.4.3 Navigating TypeCodes 244
6.4.3.1 Methods for Structured Types 2446.4.3.2 Methods for Unions 2456.4.3.3 Methods for Template Types 2456.4.3.4 Methods for Fixed Point Types 2466.4.3.5 Methods for Valuetypes 246
6.4.4 Creating TypeCodes 2476.4.4.1 Structured Types, Aliases, Valuetypes, and Interfaces 2476.4.4.2 Template Types 2506.4.4.3 Types Containing Recursion 251
6.5 Types Used for Dynamic Invocations 2526.5.1 Flags 2526.5.2 NamedValues 2536.5.3 NamedValue Lists 253
6.5.3.1 Adding Elements to NVLists 2546.5.3.2 List Management 255
6.5.4 Environment 2556.5.5 Context Interface 256
6.5.5.1 Creating a Context Object 2566.5.5.2 Manipulating a Context Object 2576.5.5.3 Manipulating the Context Object Tree 258
6.6 Dynamic Invocation Interface 2596.6.1 Creating a Request 2596.6.2 Request Interface 260
6.6.2.1 Initializing a Request 2616.6.2.2 Invoking a Request Synchronously 262
XX Contents
6.6.2.3 Invoking a Request Asynchronously 2636.6.2.4 Invoking a One-way Operation Request 2636.6.2.5 Invoking Multiple Requests 264
6.7 Dynamic Skeleton Interface 2646.7.1 ServerRequest Interface 2656.7.2 Dynamiclmplementation Class 266
6.8 Registering Valuetype Factories 266
Chapter 7 Discovering Services 269
7.1 The CORBA Naming Service 2697.1.1 Overview of the Naming Service 2 707.1.2 Interface Specification 271
7.1.2.1 The Name Type 2717.1.2.2 Bindings 2727.1.2.3 Adding Names to a Context 2 727.1.2.4 Removing Names from a Context 2 747.1.2.5 Name Resolution 2 747.1.2.6 Exceptions 2757.1.2.7 Context Creation 2767.1.2.8 Context Destruction 2767.1.2.9 Browsing Contexts 2 767.1.2.10 Binding Iterators 2777.1.2.11 Converting Names 278
7.1.3 Using the Naming Service from a Java Client 2807.1.4 The Java Naming and Directory Interface 284
7.2 Trading Service 2857.2.1 Overview of Trading 285
7.2.1.1 Service Types and Service Off ers 2897.2.1.2 Export and Lookup of Service Off ers 2897.2.1.3 Trader Federation 290
7.2.2 Overview of the Trading Service Interfaces 2907.2.2.1 Service Type Reposüory 2907.2.2.2 TraderComponents—Finding the Right Interface 2957.2.2.3 Lookup 2967.2.2.4 Iterators 2987.2.2.5 Register 2997.2.2.6 Link 3027.2.2.7 Admin 3027.2.2.8 Proxies and Dynamic Properties 302
7.2.3 Exporting a Service Offer 3037.2.3.1 Implementing the Printer Interface 3047.2.3.2 Implementing the Printer Server 308
7.2A Finding an Object Using a Trader 3147.2.4.1 Possible Enhancements to the Print Client 320
7.3 Bootstrapping 320
Contents xxi
Chapter 8 Building Applications 323
8.1 Application Specification 3248.1.1 IDL Specification 3248.1.2 Compiling the IDL Specification 327
8.2 Implementing Objects 3288.2.1 Implementing the Meeting Object 3288.2.2 Implementing the Room Object 329
8.3 Building Servers 3318.3.1 Initializing the ORB 3338.3.2 Creating and Activating a Servant 3348.3.3 Registering with the Naming Service 3348.3.4 Entering the Dispatch Loop 335
8.4 Building Factories 3358.4.1 Meeting Factory Object Implementation 3368.4.2 Meeting Factory Server 336
8.5 Starting Servers 338
8.6 Building Clients 3398.6.1 Client as Applet 3428.6.2 Client as Application 3438.6.3 Client-Type Independent Code 345
8.6.3.1 Overview of Methods 3458.6.3.2 Variable Declarations 3468.6.3.3 Constructors 34 78.6.3.4 initjGUIO 3488.6.3.5 initjrom_ns() 3508.6.3.6 view() 3508.6.3.7 canceLO 3548.6.3.8 process _slot() 3558.6.3.9 book() 3558.6.3.10 actionPerformedO 356
8.7 Extensions to the Example Application 357
Chapter 9 Advanced Features 359
9.1 The Any Type and TypeCodes 3599.1.1 Interface Specification 3609.1.2 Obj ect Implementation 3609.1.3 Client Implementation 362
9.1.3.1 Initialization and Invocation 3629.1.3.2 Obtaining TypeCodes 3639.1.3.3 Unpacking the Results 365
9.2 Interface Repository and Dynamic Invocation Interface 3669.2.1 Initializing the ORB 3679.2.2 Browsing the Interface Repository 368
xxii Contents
9.2.3 A Simple Unparser9.2.4 Creating Requests9.2.5 Initializing the Request9.2.6 Invoking Requests and Getting Results9.2.7 Executing the Client
9.3 Dynamic Skeleton Interface
9.4 Tie Mechanism
9.5 Portable Interceptors9.5.1 The Portable Interceptors Specification
9.5.1.1 Request Interceptors9.5.1.2 IOR Interceptors
9.5.2 Programming with Interceptors9.5.3.1 Writing the Interceptor9.5.3.2 Registering the Interceptor
9.6 Applet Server9.6.1 The Application9.6.2 The Interface Specification9.6.3 Structure of the Implementation9.6.4 Object Implementation9.6.5 Applet Implementation
9.6.5.1 Initializing the GUI9.6.5.2 Initializing the ORB and Object Creation
9.6.6 Executing the Application
370371372374375
377
380
385386387392392393395
396397397398399400401403410
Chapter 10 Practical POA Programming
10.1 POA Policies Revisited
10.2 Managing Objects with Persistent State10.2.1 A Multiuser Meeting Application10.2.2 The IDL Interfaces10.2.3 Common Data Structures10.2.4 Serializing Object References10.2.5 Implementing the Building Service
10.2.5.1 Implementing the Interfaces10.2.5.2 Configuring the POA
10.2.6 The Meeting Service10.2.6.1 Using Default Servants10.2.6.2 Implementing the Default Servant10.2.6.3 Implementing the Server10.2.6.4 Implementing the Factory
10.2.7 The Digital Secretary Service10.2.7.1 Implementing the Server10.2.7.2 Implementing the Interface
413
413
415417419424427429430436444446447452454456458462
Contents xxi i i
Chapter 11 Events
11.1 Events
11.2 CORBA Event Service Concepts11.2.1 Push Model Communications11.2.2 Pull Model Communications11.2.3 Mixed-Mode Communications11.2.4 Federated Event Channels11.2.5 Event Types
11.3 Interface Specifications11.3.1 Module CosEventComm
11.3.1.1 Push Model11.3.1.2 Pull Model
11.3.2 Module CosEventChannelAdmin11.3.2.1 Proxy Interfaces
11.3.3 Obtaining a Proxy11.3.4 Typed Event Communication
11.3.4.1 Typed Event Types11.3.4.2 The Typed Proxy Interfaces11.3.4.3 The Typed Admin Interfaces
11.4 An Event Service Example11.4.1 Implementing the Supplier11.4.2 Implementing the Consumer
11.5 The Notification Service11.5.1 Notification Service Architecture and Interfaces11.5.2. Structured Events11.5.3 Event Filtering
11.5.3.1 Filters11.5.3.2 Mapping Filters
11.5.4 Quality of Service
11.6 A Notification Service Example11.6.1 Implementing a Structured Event Supplier11.6.2 Implementing a Structured Event Consumer
11.7 Java Events and CORBA11.7.1 Java Events11.7.2 InfoBus
11.7.2.1 Membership11.7.2.2 Listeningfor InfoBus Events11.7.2.3 Rendezvous11.7.2.4 Access to Data Items
11.7.3 Java Message Service11.7.3.1 JMS Messages11.7.3.2 Message Selectors11.7.3.3 JMS Messaging Domains
469
470
472473473474475475
476476476477478478480481482483484
486488492
496497503505506508509
512512517
522523524524525526528528529530530
xxiv Contents T11.7.4 Comparison of the Various Event Models 53111.7.5 Distributing Java Events with CORBA 531
Chapter 12 Security 533
12.1 Applet Security Issues 534
12.2 Firewalls 53512.2.1 Types of Firewalls 536
12.2.1.1 Packet Filtering 53712.2.1.2 Application-Level Gateways 539
12.2.2 CORBA and Firewalls 54012.2.2.1 HTTP Tunneling 54112.2.2.2 GIOP Proxies 542
12.3 IIOP over Secure Socket Layer 54412.3.1 SSL 54512.3.2 Public Key Infrastructures 547
12.4 Overview of the CORBA Security Service 54812.4.1 Overview of Security Goals and Terminology 548
12.4.1.1 Security Requirements 54812.4.1.2 Threats to Security 54912.4.1.3 Features of the Security Service 55012.4.1.4 Security Conformance Levels 550
12.4.2 Security Model 55112.4.2.1 Principals and Security Attributes 55112.4.2.2 Non-repudiation Services 55412.4.2.3 Security Domains 555
12.4.3 Security Model Seen by Applications 55612.4.3.1 Finding the Security Features of an ORB 55612.4.3.2 Authentication ofa User Principal 55612.4.3.3 Selecting Privileges 55712.4.3.4 Making a Secure Invocation 55 712.4.3.5 Non-repudiation 558
12.4.4 Overview of Application Security Interfaces 55812.4.4.1 Common Security Types 55912.4.4.2 Security Level 1 56012.4.4.3 Security Level 2 56012.4.4.4 Current 56012.4.4.5 RequiredRights 56112.4.4.6 PrincipalAuthenticator 56212.4.4.7 Credentials 56212.4.4.8 Object 563
12.4.5 Common Secure Interoperability (CSI) 563
Chapter 13 The Persistent State Service 567
13.1PSSConcepts 569
Contents xxv
13.2 A PSS Example 57113.2.1 PSDL Definitions 57213.2.2 Servant and Server Implementation 574
13.3 The Persistent State Definition Language 57813.3.1 Abstract Storagetypes 57913.3.2 Abstract Storage Homes 58013.3.3 Catalogs 58113.3.4 Implementing Storage Objects 58213.3.5 Implementing Storage Homes 583
13.4 PSS Interfaces 583
Chapter 14 CORBA Components 589
14.1 The Component Model 59014.1.1 Facets 59114.1.2 Configuration and Composition Ports 595
14.1.2.1 Attributes and Inheritance 59514.1.2.2 Receptacles 59614.1.2.3 Event Sources and Sinks 598
14.1.3 Component Homes 601
14.2 The Component Container 60314.2.1 Component Categories 60414.2.2 Container API Types 607
14.2.2.1 The API Type Session 60814.2.2.2 The Entity Container API Type 610
14.3 Component Implementation 61114.3.1 Compositions 612
14.3.1.1 Persistent State 614
14.4 Component Packaging and Deployment 61714.4.1 Software Package Descriptor 61814.4.2 Component Descriptor 62114.4.3 Component Assembly Descriptor 62414.4.4 Property File Descriptor 627
14.5 CORBA Components versus EJB 62814.5.1 Interoperability 629
14.5.1.1 Vendor Interoperability 62914.5.1.2 Language Interoperability 630
14.5.2 Component Models and Containers 631
Chapter 15 Performance, Scalability, and Management 633
15.1 Scalability Issues 63415.1.1 Refining the Object Model 63515.1.2 Threading Models 640
15.1.2.1 Threading in Clients 640
xxvi Contents
15.1.2.2 Multithreaded Clients15.1.2.3 Threading in Servers
15.1.3 Distributed Callbacks15.1.4 Iterators
15.1.4.1 Pull Iterators15.1.4.2 Push Iterators
15.1.5 Client-Side Caching15.1.6 Monitoring Performance
15.1.6.1 A Test Client to Drive the Application15.1.6.2 Analysis of the Performance Data
15.2 Management15.2.1 Distributed Garbage Collection15.2.2 Design of Management Interfaces15.2.3 Implementing a Management Tool15.2.4 Implementing Managed Objects15.2.5 Using the Management Tool
15.3 Summary
Glossary
Index
641646648652653657661665668669
670671673676684687
688
689
695