| By Ashish Garg, Ashwini Garg | Article Rating: |
|
| July 19, 2005 10:30 AM EDT | Reads: |
20,755 |
Network speed has improved tremendously over the years and has revolutionized enterprise computing, but even with today's network infrastructure sending messages across a network is of several orders slower than sending messages locally. The latency caused by the network is a function of the size of the messages and the number of round trips. The delay due to message size is more or less constant as long as the data size stays within the size of the buffer transmission but cutting down the network crossings could have a more significant and direct impact. In light of these considerations, this article proposes the design and implementation of a framework, using core Java principles like Reflection, Dynamic Proxies, Byte Code Engineering, Java Beans, and Thread Local, to club multiple network calls and have them execute at the server in one go.
Objective
In an Enterprise Computing model multiple users access applications and data stored on servers scattered across many locations. The applications offer low-level data in the form of services. But often, the user really needs a more consolidated and unified view rather than the low-level view these services offer. The Session Façade pattern helps by logically grouping services keeping in mind the business needs of the user. In doing so the façade serves two other purposes:
- It precludes the clients from having to access the fine-grained remote interfaces thus reducing network traffic and latency.
- It also decouples lower-level business components from one another allowing them to be conceived and built independently, making designs more flexible and comprehensible.
- Maintainability issues due to uncontrolled growth in the number of views
- Delays and disruptions of service for existing clients while incorporating new changes
- Departmental politics may lead to some facades being preferred over others
Approach
The semantics of the Java language don't support clubbing network calls into batches so we are proposing a framework that imposes certain minimal but non-intrusive changes in the regular style of programming to help overcome the limitation.
The basic idea includes:
- Demarcating batch (façade) boundaries through a start and end call
- Objects used in the façade need to be batch-aware, i.e., object behavior is dependent on whether or not it's executing in a batch
- Delaying object state changes by postponing the execution of the code till the end of the batch
- A new framework bean to comprehend and service such requests is needed
Overview
- The client signals the start of the batch process by a call to begin the method of BatchContext. The call changes the state of the current thread by binding the BatchContext to a ThreadLocal variable.
- Objects modulate their behavior based on the availability/unavailability of the BatchContext in the current thread context. Unavailability triggers the usual behavior as programmed. On the other hand, availability results in:
a. An addition to the Participating-Objects list - All the objects created in the batch boundary are added to the list of participating objects and indexed (indexing helps reduce the final cost of serialization). Similarly, calls to methods with a non-void return type results in instantiation and initialization of the returned object by a no-argument constructor. The returned object is added to this participating objects list. The call execution doesn't result in any state changes.
b. The serialization of invocation - The serialized instruction is stacked in the InvocationHistory object bound to the BatchContext. Different types of invocation objects exist for the lookup instruction (LookupHomeInvocation), remote object creation (CreateRemoteInvocation), remote method invocation (RemoteMethodInvocation), instance method invocations (MethodInvocation), and constructor invocations (ConstructorInvocation). The invocation object maintains a reference, via an index, to the object invoked, the arguments passed, and the object returned besides information about the method invoked, i.e., method name. - Use of ServiceLocator pattern for looking up the EJBs. The ServiceLocator acts as a batch-aware class; it registers the client's intent to do a lookup while the actual lookup happens later along with other network calls. The ServiceLocator is described in greater detail in the following sections.
- The client then signals the end of the batch process. This is done by a call to the end method of the BatchContext class. The call results in the entire list of objects and the instructions being submitted to the server. The results of the entire sequence are processed and returned together as one call.
The following section describes in detail the internals of a batch call.
- Batch begin - The events accompanying a batch begin call are shown in Figure 1.
- Initialization of a Data Object in the batch call - The object is simply added to the list of Participating Objects. The conditional behavior of the service class's construction isn't the default behavior as programmed by the developer; instead it's injected post-build time through bytecode manipulation and is discussed in the components section later.
- Looking up an EJB using the modified ServiceLocator - In the batch mode the ServiceLocator would add a LookupHomeInvocation instruction and return a DynamicProxy implementation of the EJBHome and Home Interface as the home proxy. Returning a proxy implementation helps us trap and handle invocations to the home and remote interfaces.
- Calls on the Home interface - The home proxy (through it handler, EJBHomeHandler) in turn, on a create call on home proxy, adds a CreateRemoteInvocation instruction and returns a DynamicProxy implementation of the EJBObject and the Remote Interface as the remote proxy.
- Calls on the Remote interface - Calls on the remote proxy (through its handler, EJBRemoteHandler) translate to a RemoteMethodInvocation instruction and the return of a dummy instance of the relevant return type.
- Call to the end method of the BatchContext class - This call results in the entire list of objects and the instructions being submitted to the server. The server runs through the instructions sequentially and executes them. In the process it alters the state of the objects participating in the batch. The altered state is returned to the client where the original references are used to modify the client-side object states using accessor methods to reflect the new states. The lack of pointers restricts the return types to mutable types. Apache Commons BeanUtils libraries are used to facilitate copying the states.
Published July 19, 2005 Reads 20,755
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Ashish Garg
Ashish Garg is a Senior Technical Specialist with Infosys Technologies Ltd. He has more than 4 years of experience in J2EE Technologies.
![]() |
SYS-CON Spain News Desk 07/19/05 09:52:24 AM EDT | |||
Facading on the Fly: A Framework Proposal For Improving Network Speed |
||||
![]() |
News Desk 07/18/05 09:13:14 AM EDT | |||
Facading on the Fly: A Framework Proposal For Improving Network Speed |
||||
- Patterns for Building High Performance Applications
- It's the Java vs. C++ Shootout Revisited!
- Asynchronous Logging Using Spring
- Java for Programmers (2nd Edition)
- Cross-Platform Mobile Website Development – a Tool Comparison
- Three Buzzwords That Every CIO Hears but One They Should Listen To
- Write Once Run Anywhere or Cross Platform Mobile Development Tools
- Immersing into JavaScript Frameworks
- Workday Reportedly Prepping to Go Public
- Cloud Expo New York: The Java EE 7 Platform - Developing for the Cloud
- Book Review: Sams Teach Yourself Java in 24 Hours
- OpenOffice.com Lives
- Book Excerpt: Introducing HTML5
- Adobe Sends Flex to the Apache Foundation
- Five Years Waiting for JRE 7: Is It Justified? (Part 1)
- Book Excerpt: Java Application Profiling Tips and Tricks
- i-Technology in 2012: Five Industry Predictions
- Patterns for Building High Performance Applications
- It's the Java vs. C++ Shootout Revisited!
- OpenXava 4.3: Rapid Java Web Development
- The Next Web Architecture
- Asynchronous Logging Using Spring
- Java for Programmers (2nd Edition)
- Is Write Once Run Anywhere Ever Going to Be a Reality?
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- JavaServer Faces (JSF) vs Struts
- The i-Technology Right Stuff
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- What's New in Eclipse?
- i-Technology Predictions for 2007: Where's It All Headed?

























