Table of Contents

foreword ix
preface xi
acknowledgments xiv
about this book xvi
Goals of this book xxii
About the author xxiii
about the cover illustration xxiv
1 Enterprise Java 1
1.1 Enterprise development 1
What is enterprise development? 1 Developing the enterprise application 4 Reinventing the wheel 7
1.2 Three zeroes 8
Zero development 9 Zero deployment 11 Zero administration 12
1.3 Java in the enterprise 14
Sun?s view 14 Alternate views 14
1.4 Why Java? 15
Criticisms of Java as a server-side language 17
1.5 Summary 25
1.6 Additional reading 26
2 ClassLoaders 27
2.1 Dynamic linking 28
Run-time dynamic loading 28 Reflection 31
2.2 ClassLoaders: rules and expectations 37
Java .class file format 37 Using ClassLoader 39 java.lang.ClassLoader 41 Java name spaces 48
2.3 Java?s built-in ClassLoaders 49
java.security.SecureClassLoader 49 java.net.URLClassLoader 49 sun.applet.AppletClassLoader 57 java.rmi.server.RMIClassLoader 57 Bootstrap ClassLoader 57 sun.misc.Launcher$ExtClassLoader 58
2.4 Summary 58
2.5 Additional reading 59
3 Custom ClassLoaders 61
3.1 Extending ClassLoader 61
FileSystemClassLoader 62 HashtableClassLoader 66 CompilerClassLoader 67 StrategyClassLoader and ClassLoaderStrategy 71 CompositeClassLoader 75 Other ClassLoader tricks 79 Other ClassLoaders 80
3.2 On-the-fly code upgrades 80
3.3 GJAS: first steps 85
Goals 85 Service 86 Server 88 ServerManager 90
3.4 Summary 92
4 Extensions 93
4.1 Types of extensions 94
Installed extensions 94 Building an installed extension 95 Download extensions 96 Building a download extension 98
4.2 Implications of the extensions mechanism 100
Distributed libraries through download extensions 100 Java EXEs; relation to C++ static linking 101
4.3 Packaging extensions 102
The build-time vs. run-time dilemma 103
4.4 The plug-in 104
The plug-in concept 105 Enter plug-ins 107 Marking a .jar file as a plug-in 110 PluginClassLoader 111 Example: PluginApp 118 Uses for plug-ins 124
4.5 Summary 125
5 Threads 127
5.1 Why threads? 128
Concurrent processing 128 Scalability per machine 129 Encapsulation 130 Design and implementation 131
5.2 Java threads 131
java.lang.Thread and java.lang.Runnable 132 Starting threads 138 Stopping threads 140 Daemon threads 143 Threads and ClassLoaders 144 java.lang.ThreadGroup 145
5.3 Thread implementations in Java 147
Green threads 148 Native threads 148 Hybrids 148 Implications 149
5.4 Summary 149
5.5 Additional reading 149
6 Threading issues 150
6.1 Synchronization 151
Thread-local storage 153
6.2 Exception-handling with multiple threads 154
6.3 Thread idioms and patterns 159
Client-Dispatcher-Server 159 Fire-and-forget 160 Active Object 161 SpinLoop 161 Polling (PeriodicThread) 162 DelayedFire (ScheduledThread) 164 Futures 165
6.4 GJAS 167
Adding thread support to GJAS 168
6.5 Summary 174
6.6 Additional reading 174
7 Control 175
7.1 GJAS 176
Local implementation 176 Example: HelloService 187
7.2 Testing the LocalServer implementation 188
7.3 ExecService 190
7.4 HelloAgainService 194
ThreadServer 197 Example: ConsoleControlService 202
8 Remote control 209
8.1 RMI implementation 210
Analysis 218
8.2 Other implementations 219
8.3 Necessary improvements 220
8.4 Additional reading 225
9 Configuration 226
9.1 Java models 226
Interface: ConfigProperty and ConfigProperties 227 Usage 234 Configuration front ends 236
9.2 Summary 237
10 Sockets 238
10.1 Simple socket services 238
SocketClient 239 EchoService 244 TimeService 246 Analysis 247
10.2 Encapsulation and refactoring 248
SocketServer 248 Example: Echo2Service 255
10.3 Connection and ConnectionManager 256
Example: EchoConnection 263 Example: HTTPConnection 264 Servlets 273
10.4 Advanced Socket services 274
SocketClassLoader and SocketClassService 274 Concept: RedirectorService 280 Concept: FilterService 281 Other types 282
10.5 Summary 282
10.6 Additional reading 283
11 Servlets 284
11.1 Relationship to sockets 284
CodeServlet: A filtering servlet 286 HeaderFooter: a redirecting servlet 288 Server-side scripting capabilities 290 Servlets: Not just about HTML anymore 291
11.2 Servlets and the n-tier application 293
Separating logic from content 294
11.3 Servlets as a poor man?s RMI 294
Example: RemoteStorageServlet 296 Concept: poor man?s RMI 298 Concept: SOAP 299
11.4 Summary 299
11.5 Additional reading 299
12 Persistence 301
12.1 Java Serialization 302
Serialization to other places 303 Security and Serialization 304 Customized Serialization 307 Serialization and evolution 310 Replacement 314
12.2 Beyond the specification 318
Remote storage of objects 318 Example: RemoteStorageService and RemoteStorageClient 319 Remote construction of objects 324 Example: RemoteObjectFactory 326
12.3 JDBC 331
Transient data, state data, data that Isn?t data 333 Example: JDBCClassLoader 335
12.4 Summary 339
12.5 Additional reading 340
13 Business objects 341
13.1 Modeling data 341
Two-tier Systems vs. n-tier Systems 342 One-tier systems 342 Two-tier systems 343 n-tier systems 343 Benefits of an n-tier model 344 Business objects, entity relationships 347 Example: employee directory 347 Business objects layer interface layer 349
13.2 Using the Business Object layer 367
Classic Presentation Code: GUIs 367 Example: OrgTree 367 Feeling cheated? 371
13.3 Summary 371
13.4 Additional reading 372
14 Business object models 373
14.1 Example: HashtableModel 373
Overview 374 HashtablePerson, HashtableEmployee, HashtableManager 374 HashtableModel: Creating objects 376 HashtableModel: Finding objects 378 HashtableModel: Removing objects 379 Conclusion 380
14.2 Example: RDBMSModel 381
RDBMSModel: Storing Business Objects in an RDBMS 382 Overview 382 RDBMSPerson, RDBMSEmployee, RDBMSManager 385 RDBMSModel: Creating objects 392 RDBMSModel: Finding objects 395 RDBMSModel: Removing objects 396 Conclusion 398
14.3 Summary 401
14.4 Additional reading 402
15 Middleware 403
15.1 Why distribute? 403
Communication 404 Performance 405 Economics (clustering/fault-tolerance) 406 Reliability (clustering/load-balancing) 407
15.2 Distributed object design vs. classic object design 407
Stateful vs. stateless 407
15.3 Technologies 411
Raw access: Sockets 412 Java RPC: remote method invocation 413 Analysis 418 RMI/JRMP 420 Object Request Brokers: CORBA 429 Object Request Brokers: Distributed Component Object Model 433 Message-Oriented Middleware: JMS 434 Objects across the wire: Mobile objects 436 Objects across the wire: shared objects 442
15.4 Employee middleware models 449
RMI implementation 452 JSDTModel: Shared-object implementation 453 Analysis 461
15.5 Additional reading 462
16 Java Native Interface 464
16.1 Java Native Interface 465
Native code on the server 466
16.2 JNI essentials 473
Java calling native 473 Native calling Java 479 JNI invocation 485 JNI changes in JDK 1.2 493
16.3 Other methods of Java-to-native interaction 495
Sockets 495 CORBA 495
16.4 Integrating the server: GJAS goes native 496
Making GJAS an NT service 496 Using NT IPC mechanisms: Named pipe 497
16.5 Other JNI uses 507
Debugging support 507 JVMDI 508 JVMPI 509
16.6 Summary 509
16.7 Additional reading 509
17 Monitoring 511
17.1 Importance grows 511
Liveness 512 Notification 524
17.2 Summary 534
Epilogue 536
Where to go from here 543
Parting advice 545
Read all about COM, DCOM, and MTS 545 Read all about EJB 545 Read all about CORBA 545 Participate 546
Summary 546
 
index 547