13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

21.2 Expanding to EJBs477as we go al<strong>on</strong>g. For now, be aware that the c<strong>on</strong>tainer will start, stop, instantiate,destroy, and provide network services to the EJBs it c<strong>on</strong>tains.21.2.2 Bean TypesEnterprise JavaBeans come in more than <strong>on</strong>e variety. Let’s take a look at those.21.2.2.1 Sessi<strong>on</strong> BeansA sessi<strong>on</strong> bean is a reusable comp<strong>on</strong>ent that represents a collecti<strong>on</strong> of servermethods. The intenti<strong>on</strong> is that each such method represents some businessprocess, such as addCustomer(), createShoppingCart(), and so <strong>on</strong>.Sessi<strong>on</strong> beans are thus organized around business processes. Actually, asessi<strong>on</strong> bean is not much more than a facade that collects a business processAPI into a single class. But remember what EJBs give you—networked serverbasedfuncti<strong>on</strong>ality, load balancing, clustering features, reliability, failover, andthe ability to handle increased demand by merely adding more Bean instancesand server hardware. The power comes not from how EJBs extend the language,but from how they automate and hide infrastructure.Sessi<strong>on</strong> beans come in two major varieties: stateless and stateful. Let’s takea look at what they offer and the differences between the two.Stateless Sessi<strong>on</strong> BeansWhat they are. A stateless sessi<strong>on</strong> bean is <strong>on</strong>e where each method call iscompletely independent of any other method call, whether by <strong>on</strong>e or manyclients.An EJB applicati<strong>on</strong> designed this way has certain advantages. Since a singleBean instance can be switched from client to client <strong>on</strong> demand (because nostate informati<strong>on</strong> is kept between method invocati<strong>on</strong>s), a small number of Beaninstances can handle a large number of clients. Compare this with statefulsessi<strong>on</strong> beans described below.Why you would use them. In a sense, this is the optimum bean. If you candesign your applicati<strong>on</strong> to use nothing but stateless sessi<strong>on</strong> beans (perhapsbacked by entity beans), then you have a maximally flexible, extensible, andadaptable enterprise applicati<strong>on</strong>—<strong>on</strong>e that can be easily scaled from a singleapplicati<strong>on</strong> server to a very large cluster. Why? Because the lack of state informati<strong>on</strong>means that any single Bean instance can serve any given client at any

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!