eCommerce
|
SUN AUGUST 1998 Distributed Java
component model It doesn't always happen this way, but when Sun Microsystems raised Enterprise JavaBeans (EJB) up the flagpole, some really big vendors saluted. That's not surprising -- many of those vendors helped to put the flag together -- but one might legitimately wonder whether EJB is the outstanding technology we are told it is. Depending on their design, EJB servers could compete directly with Microsoft Transaction Server (MTS), Microsoft's Component Object Model (COM)-based transaction manager. On a larger scale, however, the EJB "container" model correlates closely with Microsoft's notion of "interception," a service-addition layer that the company is putting forth as a key element in its upcoming COM+ framework. This makes it a battle of server-side component models. Stepping back a few more paces, EJB's tight mappings to CORBA's Object Transaction Service (OTS) and Internet Inter-ORB Protocol (IIOP) suggest the real contenders will be full distributed component frameworks -- EJB and IIOP on one side, COM+ on the other. In that case, EJB becomes a pivotal player in the enterprise development platform contest and deserves close inspection.
Containers are software receptacles that know how to communicate with and manage the beans, a fact that adds significant value to the component proposition. The container places itself between the client and the bean, which gives it the opportunity to implement services most corporate application developers would rather not worry about. These include persistence management, transactions, concurrency, thread management, and security, among other things. Of central importance, EJB extends JavaBeans by letting container-based objects communicate with each other via a network. EJB container vendors seem to be coming from every direction, including traditional transaction-processing monitor vendors such as BEA Systems and IBM; Web application server vendors such as Netscape, NetDynamics, and WebLogic; database vendors such as Sybase and Oracle; and CORBA object request broker (ORB) vendors such as Inprise (formerly Borland).
We chose WebLogic's Tengah 3.0.4 Java application server for our container, which provided EJB support at the 0.8 level. The differences between 0.8 and 1.0 did not affect the operation of our application. We also enlisted the help of huge EJB-proponent IBM, which let us dissect the company's J-Store demo. J-Store is a simulated online-shopping service in which EJBs handle the business objects while Java servlets and JavaServer Pages take care of the page transmission and display logic. The application authenticates users, lets them browse GIF images and load items into a shopping cart, and tallies up the sale. The EJBs ran in a custom EJB container that is not currently an official IBM offering. One interesting aspect of the application is its use of servlets to act as clients to the EJBs, which lets you stay away from requiring Java support on the browsers.
To find the bean's home interface in the first place, the client appeals to the container via the Java Native Directory Interface (JNDI) and then requests the bean's location. Our application's server bean, "Bet," ran alone inside the Tengah container, but it is important to note that EJB lets multiple beans run side by side in a given container and lets multiple containers run on a given server. We were initially confused by the Tengah documentation, which stated that each EJB was associated with one and only one container, until we realized that the word container in the EJB-0.8 specification referred to the Container interface, which changed to the remote interface in Version 1.0. Had our application required it, or had multiple clients needed to activate the bean, the container could have created multiple instances of Bet and then associated Bet objects to service the additional load. The capability of EJB containers to dynamically manage the creation and destruction of server objects gives them the potential to scale well with increasing demand. It also means bean programmers don't need to worry about the number of clients activating a bean; you write beans as if only one client will use them. An additional advantage of wrapping is that an EJB doesn't know it is remotely accessible (that is, accessible across a network), because it is not required to expose its remote interface directly. Perhaps more to the point, the developer is freed from handling the low-level details of remote activation, because the container implements the necessary interfaces.
Session beans come in two flavors: stateless and stateful. The term "state" refers to the data an object carries with it. In the context of a session bean, it means "conversational" parameters passed to and from clients and between methods during the course of its operation. A stateless bean is perfectly anonymous: It looks the same to a client before and after an operation. The bean's methods can receive and return parameters, but the storage of those parameters is transient. Applications that implement stateless beans should generally scale better, because the container can activate and deactivate multiple instances of a stateless bean on the fly and based on demand. Stateful session beans, on the other hand, are semipersistent in that the developer can have them swap their parameters to disk, temporarily retirebring the beans and data back ("activate" them) when needed. A container may also passivate beans automatically. Stateful session beans can access persistent resources such as database tables, sockets, and files, but the beans do not actually represent the data. Session beans of both types are lost if the server crashes. Both types of session beans execute on behalf of a single client; two clients may not access the same instance of a session bean. Our betting application used a stateless session bean and stored state information, such as the user's log-in name, on the client. Of course, we could just as well have made our bean stateful, stored parameters on the bean, and passed the parameters directly among methods. The choice generally depends on how much load you want to place on the client and on the wire. Entity beans differ in that they do represent "persistent data," which in this case can mean stored data or it can mean an application that the bean accesses through function calls. Because the data is permanently stored, the object will survive server crashes. Further, multiple clients can access a single entity bean concurrently via a pool of instances. When a client activates the object, the container makes sure an instance is bound to the current data and passes its interface to the client. Entity beans have powerful implications for incorporating legacy data and code into an EJB framework. It might not be easy -- for bean-managed persistence someone will have to write custom access calls in the bean's methods -- but it might be easier than recoding or regenerating the data. Another possibility is for the container to generate access calls when entity beans are installed in the container, but this places the burden of writing the calls on the vendor. The current specification does not require the container to manage persistence on behalf of the bean, so vendors are off the hook unless they want to provide this as a value-add.
Transaction management is another EJB feature that you can specify at deployment time. Transaction support in EJB conforms to a subset of the CORBA Java Transaction Service (JTS), the Java-language mapping of OTS. Transaction support in EJB ensures that operations performed on important stored data are protected in the event of system, network, or application failure. EJB containers may implement a two-phase-commit protocol, which transaction-processing monitors have used for years to manage all-or-nothing changes to distributed stored data. (The EJB specification currently only requires flat transactions, which makes EJB support easier for database and transaction server vendors that do not currently support nested transactions.) The truly valuable feature of EJB's container framework for transactions, though, isn't the declarative programming model per se but the capability to automatically start, stop, suspend, commit, and rollback transactions on behalf of components. If an object represents an important piece of durable data, you can tell the container that the bean must always participate within the boundaries of a transaction. The transaction boundaries bracket the operations that happen between the start and end of a transaction, when persistent resources involved in the transaction such as database records are either committed via a two-phase-commit operation or aborted via a rollback. If a bean must participate in a transaction but the caller does not pass a transaction "context" to the object, the container simply starts one up. EJB defines five other transaction attributes that you assign to beans when you package them. Note that the client is the program that invokes a method on an object. The client may or may not be a remote program. Here is the complete list:
Security is partially left as an exercise for the container vendor. EJB specifies standard Java security interfaces, and the container does the job of mapping instances of the appropriate class to individual user accounts or groups on the server. But because the mapping depends on the security implementation of the container, you cannot count on EJB to provide the bomb-proof yet flexible security system you might want. A second way in which a developer can introduce security is by programming EJB methods that interrogate a client for its identity, but this seems like a throwback compared to a third method, security attributes the application assembler sets through the deployment descriptor. These also rely on the security implementation of the container or DBMS.
|
SUN Home JavaOne eJavaBean Distributed Model |