Java and CORBA - external.dandelon.com
Transcript of Java and CORBA - external.dandelon.com
FachgeoS t̂ Praktisctwinformalik. 11 c
64289Wrmstadt
fny^fr.
Client/ServerProgramming with
Java and CORBAFachbereichsbibliothek Inform atik
TU Darmstadt
Robert Orfali • Dan
WILEY COMPUTER PUBLISHING
HarkeyTechnische Universtiat Darmstadt
FACHBEREICH (WFORMATIK
R I B L I O T H E K
ln..nntnrhtT. /40^-oo(,cPh _
Sachgebiete: — — —
Standoff. — j
JOHN IVILEV& SONS, INC.
New York Chichester Weinheim Brisbane Singapore Toronto
Contents
Foreword HiPreface v
Part 1 . CORBA Meets Java 1
Chapter 1. Client/Server, CORBA-Style 3
Distributed Objects, CORBA-Style 4What Is a Distributed CORBA Object? 4Everything Is in IDL 5CORBA Components: From System Objects to Business Objects 6
OMG's Object Management Architecture 7The Object Request Broker (ORB) 7The Anatomy of a CORBA 2.0 ORB 10
CORBA 2 . 0 : The Intergalactic ORB 14CORBAservices 15
Object Services: Build-to-Order Middleware 17CORBAfacilities 18CORBA Business Objects 18
Cooperating Business Objects 20The Anatomy of a CORBA Business Object 21The Anatomy of a Client/Server Business Object 22CORBA Component Nirvana 23
3-Tier Client/Server, Object-Style 25Conclusion 26
Chapter 2. Client/Server, Java-Style 27
Java and Objects 29Web Client/Server, Java-Style 29Java's Mobile Code System 30The Magic of Bytecodes 31The Java Verifier 32Java's Defense System 33
Client/Server Programming with Java and CORBA
The Java Language. 35JAVA as a Portable OS 36
The Java Platform 36JavaOS 37JavaChip 38Java Core Classes 38Java Standard Extension Classes 41
Conclusion 43
Chapter 3. Client/Server, CORBA/Java-Style 45
CORBA and the Internet 4 6C6I/HTTP: The Protocol That Won't 60 Away 46The 3-Tier Object Web 46Client/Server Interactions on the Object Web 48
CORBA and Java 50What CORBA Brings to Java 50What Java Brings to CORBA 52The Client/Server Object Web 53
Conclusion 55
Chapter 4. Meet the CORBA/Java ORBs 57
r W ^ J J Sun's Joe 58NEO and Joe: A Short History 58What Is Joe? 58
lona's OrbixlVeb 59What Is OrbixWeb? 60
Visigenic's VisiBroker for Java 6 0What Is VisiBroker for Java? 61VisiBroker and Netscape ONE 62
Which Java ORB? 63The Other CORBA ORBs 63Conclusion 6 4
Part 2. Core CORBA/Java 65
CODE * Chapter 5. Your First CORBA Program 67
tv. The Static CORBA 68
Contents
CORBA Method Invocations: Static Versus Dynamic 68CORBA Static Method Invocations: From IDL to Interface Stubs 71
Your First CORBA Program 72The Count IDL 73Mapping CORBA IDL to Java 74The Server Side of Count 76The Client Side of Count 79Compile the Java Code Using Symantec Visual Cafe 82Run the Client/Server Program 84
Looking at Some Test Results 84Local Versus Remote Pings 84Symantec JIT Versus Sun JDK 85
Conclusion 86
C O D E * Chapter 6. ORBIets Meet Applets 87
;L:I(- Applets 101 88Applet Life Cycle Management 88The HTML Applet Tag 89
Your First CORBA-Enabled Applet 91The Count IDL 91So, What Exactly Does This Applet Do? 92The Client Applet Code 93Compile the Java Applet 97Create a Web Page 97Test the Applet 97Run the Client/Server Program 98
Let's Look at Some Test Results 99Local Versus Remote Pings 99Applets Versus Applications 100
Conclusion 100
C O D E * Chapter 7. Java ORBs Meet C+ + ORBs 101
•i-.i,' The C + + Count Program 102The Count IDL 102Mapping CORBA IDL to C+ + 102The Server Side of the C + + Count 104The Client Side of C + + Count 108Compile the C+ + Code 110Run the Client/Server Program 110
Looking At Some Test Results I l l
XVIClient/Server Programming with Java and CORBA
Local Versus Remote Pings I l lC + + Client To Java Count Server 112Java Client to C + + Count Server 113
Conclusion 115
Part 3. The Dynamic CORBA 117
C O D E ® Chapter 8. The Dynamic Count 119
W CORBA 101: Dynamic Invocations 120Dynamic Invocations: The Big Picture 120The Dynamic Invocation Interfaces 122Dynamic Invocation Scenarios 124Dynamic Invocation: The Do-It-Yourself Scenario 125Dynamic Invocation: The ORB-Can-Help Scenario 126Dynamic Invocation: The Yet-Another-Way Scenario 128
The Dynamic Count 129The Count IDL 130The Client Side of Count 130Compile the Java Code Using The Symantec Compiler 133Run the Client/Server Program 133
Looking At Some Test Results 134When to Use Dynamic 135Conclusion 135
C O D E * Chapter 9. MultiCount: The Jazzed-Up Count 137
The Design of MultiCount 138Meet the Players 139The MultiCount CORBA Interfaces 140A MultiCount Callback Scenario 141
The MultiConsole Applet 143What the Applet Looks Like 144The MultiConsole Applet HTML 144The MultiConsoleApplet Class 144
The Client 148Client Classes and Threads 148A Multithreaded Client/Server Scenario 150The Client Code 152
The Coordinator 156
y *Contents
The Coordinator Classes 157The Coordinator Code 158
Compile the Client and Server Programs 160Run the Client/Server Programs 161Conclusion 162
Part 4. CORBA and Its Competitors 163
C0>DE% Chapter 10. Sockets Versus Java/CORBA ORBs 165
nT Berkeley Sockets 101 166What Is a Socket? 166How Do You Like Your Socket? 166Socket Ports 169Java's InetAddress Class 169The Anatomy of a Sockets Exchange 170
Java Sockets 101 172The Java Datagram Sockets Classes 172A Java Datagram Scenario 175The Java Stream Sockets Classes 176
Java Streams 101 180The Java Output Stream Classes 182The Java Input Stream Classes 186A Java Buffered-Stream Socket Scenario 190
The Java Datagram Socket Count 194The Datagram Socket Count Client 194The Datagram Socket Count Server 196
The Buffered Socket Count 198The Buffered Socket Count Client 198The Buffered Socket Count Server 200
The Data Stream Socket Count 2 0 2The Data Stream Socket Count Client 202The Data Stream Socket Count Server 204
Compile the Socket Counts 206Run the Client/Server Programs 206Looking at Some Test Results 206Sockets Versus CORBA MOP 207Conclusion 208
Client/Server Programming with Java and CORBA
Chapter 11 . HTTP/CGI Versus Java/CORBA ORBs 209
HTTP 101 210So What Exactly Is HTTP? 210HTTP Data Representations 211So What Does an HTTP Request Look Like? 211HTTP Methods 213So What Does an HTTP Response Look Like? 217
CG1101 219HTML 2.0's Web-Based Forms 220
The Form Tag 221The Form Interface Elements 2223-Tier Client/Server, CGI-Style 223CGI and State 226
The HTTP/CGI Count 228The CGI Count Client Applet 228The CGI Count Server 232
Compile the Client/Server Program 234Create a Web Page 234Run the Client/Server Programs 235Looking At Some Test Results 236Conclusion 237
C O D E A Chapter 12. RMI Versus Java/CORBA ORBs 239
' RM1101 239How RMI Extends Local Java Calls 241RMI's Garbage Collection of Remote Objects 241The RMI Development Process 242
RMI Interfaces and Classes 245The RMI Core 245The Java RMI Naming Service 250RMI's Dynamic Stub Loading Classes 253The RMI Marshaling Objects 258
RMI Scenario 258The RMI Count 2 6 0
The RMI Count Client 260The RMI Count Server 262
Compile the Client/Server Program 265Run the Client/Server Programs 265Looking At Some Test Results 2 6 6
xixContents
CODE*
HA'f
CODE*
RMI Versus CORBA/IIOP 266Conclusion 268
Chapter 13. Caffeine: The "Pure" Java/CORBA ORB 269
Caffeine 101 270Java2llOP—Look Ma, No IDL 270Java2idl: CORBA IDL Without Pain 271The Caffeine Development Process 273The Caffeine URL Name Service 275A URL-Naming Scenario 276
The Caffeinated Count 277The Caffeinated Count Client 278The Caffeinated Count Server 279
Compile the Client/Server Program 282Run the Client/Server Programs 282Looking At Some Test Results 283RMI Versus Caffeinated CORBA/IIOP 284Conclusion 286
Chapter 14. DCOM Versus Java/CORBA ORBs 287
DCOM 101 288
Looking at DCOM Through CORBA Eyes 288DCOM Style Interfaces 289So, What's a DCOM Object? 291What's a DCOM Server?. 292DCOM Local/Remote Transparency 294The Ubiquitous lUnknown Interface 295Interface Negotiations Using Querylnterface 296ICIassFactory2: Object Creation and Licensing 298A DCOM Object Creation Scenario 300DCOM Style Inheritance: Aggregation and Containment 302The DCOM IDL 303DCOM's Dynamic Invocation Facilities 303What's a Dispinterface? 304The IDispatch Interface 305The DCOM ODL 309Building and Registering Type Libraries 311Finding and Loading a Type Library 311
DCOM and Java 311The DCOM for Java Development Process 312
I.
XXClient/Server Programming with Java and CORBA
DCOM Programming: Java Vs. C + + 315DCOM/Java Mappings 318
The DCOM Java Count 319The DCOM Count Client 319The DCOM Count IDL 321Run MIDL and JavaTLB 322The DCOM Count Server 323
Compile The Client/Server Program 324Run the Client/Server Programs 324Looking At Some Test Results 327DCOM Versus CORBA/IIOP 327Conclusion 329
1! Chapter 15. And the Winner Is 331
The Report Card 332
Part 5. The Existential CORBA 339
Chapter 16. How Do I Find My ORB? 341
The CORBA 2.0 Initialization Interface 341An Initialization Scenario 342How You Find Your Other Objects 343
CORBA Trader 101 343Conclusion 345
.,,. Chapter 17. Who Activates My Objects? 347
The Server Side of CORBA 348The CORBA::BOA Interface 348BOA and Other Object Adapters 349BOA Shared Server 350BOA Unshared Server 352BOA Server-per-Method 352BOA Persistent Server 353An Object Activation Scenario 354
The VisiBroker Activation Daemon 356Conclusion 358
xxi iContents
Chapter 18. Metadata: Who Am I? 359
The CORBA IDL: A Closer Look 360What Does an IDL Contract Cover? 361The Structure of the CORBA IDL 361An IDL Example 363Type Codes: CORBA's Self-Describing Data 365
The CORBA 2 . 0 Interface Repository 3 6 6What's an Interface Repository? 366Why Is an Interface Repository Needed Anyway? 366Interface Repository Classes: The Containment Hierarchy 367The Interface Repository Class Hierarchy 368Federated Interface Repositories 372What Does a Global Repository ID Look Like? 373
CORBA IDL-to-Java Mappings 374Summary of IDL-to-Java Mappings 374CORBA Modules 375CORBA Const Values 376Basic CORBA Type: Boolean 376Basic CORBA Type: Char 376Basic CORBA Type: Octet 377Basic CORBA Type: String 377Basic CORBA Type: Integer 378Basic CORBA Type: Floating Point 378Constructed CORBA Type: Enum 379Constructed CORBA Type: Struct 379Constructed CORBA Type: Union 380Constructed CORBA Type: Sequence and Array 381Constructed CORBA Type: Any 381CORBA Type Codes 383CORBA Interface 385Parameter passing modes 386Attributes 386
Conclusion 387
C O D E * Chapter 19. The Introspective CORBA/Java Object 389
,;v.l CORBA Introspection 3 9 0Java Introspection 391The Ask Me Program 393
The AskMe Code 393Compile AskMe 401
Client/Server Programming with Java and CORBA
Run AskMe 402The Walk IR Program 403
The WalkIR Code 403Compile WalkIR 404Run WalkIR 405
Conclusion 407
Part 6. JDBC 2-Tier Versus 3-Tier 409
Chapter 20. JDBC Primer 411
The Origins of JDBC 412The X/Open SAG CLI 412The Microsoft ODBC CLI 413CLI Versus Embedded SQL 416
The JDBC Architecture 418JDBC Drivers 418The JDBC URL Naming Conventions 419Registering Drivers 420JDBC Security 420Mapping SQL Data Types to Java 420JDBC Transactions 421JDBC Stored Procedures 422
JDBC Interfaces: An Overview 4 2 2The JDBC Core 423The JDBC Java Language Extensions 424The JDBC Java Utilities 425JDBC Metadata 426
JDBC Interfaces: In-Depth 4 2 6JDBC Core: The Driver Interfaces 427JDBC Core: The Connection Interface 430JDBC Core: The Statement Interfaces 432JDBC Core: The ResultSet Interfaces 437JDBC Java Language Extensions: The Exception Classes 443JDBC Java Language Extensions: The Bignum Class 446JDBC Date and Time Classes 449JDBC DatabaseMetaData Interface 451
JDBC Scenarios 4 6 0JDBC Scenario 1: Invoking a SQL Query 461
<XXiiiContents
CODE*
CODE*
'CODE*
JDBC Scenario 2: Invoking a Prepared Command 462JDBC Scenario 3: Invoking a Stored Procedure 464
Conclusion 4 6 6
Chapter 2 1 . The JDBC Debit-Credit Benchmark 467
Designing the Benchmark 468What To Look for in an OLTP Benchmark 468The Debit-Credit Benchmark 469The Debit-Credit Database 470The Debit-Credit Transaction 470The Debit-Credit Constraints 471Price/Performance of Debit-Credit 472
The JDBC Debit-Credit Benchmark Facility 472Build Your Java Debit-Credit Benchmark in One Afternoon 4732-Tier Versus 3-Tier 474JDBC 2-Tier 475JDBC 2-Tier Plus 476JDBC 3-Tier 478
Let's Create a Bank 478The CreateBank Class 479The BankAdmin Class 479
Compile the Create Bank Program 487Run the Create Bank Program 488
Debit-Credit: To Cheat or Not To Cheat? 488Conclusion 489
Chapter 22. 2-Tier Debit-Credit with JDBC 491
The Debit-Credit 2-Tier Environment 492
The 2-Tier Client/Server Code Structure 494
Meet the Players 494
A Multithreaded Scenario 495
The Debit-Credit 2-Tier Code 498
Compile Debit-Credit 2-Tier 507
Run the Debit-Credit 2-Tier Benchmark 508
Conclusion 509
Chapter 23. 3-Tier Debit-Credit with JDBC and CORBA 511
The 3-Tier Debit-Credit Environment 512
De(,jt_(;re(|jt 3-Tier The Code Structure 513
Client/Server Programming with Java and CORBA
Meet the Client Players 514The Server: What the Client Sees 515Meet the New Server Players 515A 3-Tier Client/Server Scenario 519
The 3-Tier Debit-Credit Code 521The Debit-Credit 3-Tier Client Code 521The 3-Tier Debit-Credit Server Code 527
Compile the 3-Tier Debit-Credit 534Run the Debit-Credit 3-Tier Benchmark 5352-Tier Versus 3-Tier 536Conclusion 538
Part 7. The Grand Finale: CORBA/Java Club Med S39
fcoDE* Chapter 24. The Club Med 3-Tier Client/Server 541; I _ 1 1 | L
The C|ub Me<| C|ient 542
---'- J Ten Minutes in the Life of a Club Med Applet 542Club Med Applet: What the User Sees 544
Club Med Server 5 4 8The 3-Tier Club Med 548The Club Med Server: What the Client Sees 549The Club Med IDL Contract. 550
Club Med Database 552The CreateClubMed Program 552Compile The CreateClubMed Program 557Run the CreateClubMed Program 557
Conclusion 558
C O D E * Chapter 25. The Club Med Client Applet 559
1
The Club Me<l Client Applet 560T(|e A|)()|et C)ass Hierarchy 560So, What Exactly Is a CardLayout? 562What Is 6ridBagLayout? 564
The Applet Code 567Compile The Code 587The Applet HTML 587Conclusion 588
Contents
CODE® Chapter 26. The Club Med Server 589
Club Med Server: The Code Structure 5 9 0The 3-Tier Club Med 590The ClubMedDispenser 591Meet the Server Players 592A Club Med Client/Server Scenario 593
The Club Med Server Code 595Compile the Club Med Server 606Running Club Med 607Conclusion 607
Chapter 2 7 . CORBA/Java: The Good, the Bad, and the Ugly . . . 6 0 9
So, What Did We Learn? 610CORBA ORBs: The Good, the Bad, and the Ugly 610CORBA/Java Clients: The Good, the Bad, and the Ugly 613CORBA/Java Servers: The Good, the Bad, and the Ugly 615
The Object Web Vision 617Compound Documents as Open Web Browsers 618The Desktop Is the Browser 619Compound Documents as Portable Component Stores 619What Is a Shippable Place? 620The Future Web Client 622The Object Web 622Back to Reality 624
It's Time To Say Good-Bye. 625
Where to Go for More Information 627Index 631