Archive for October, 2007

EJB Fundamentals 47 When you write a local (Free web hosting music)

Wednesday, October 31st, 2007

EJB Fundamentals 47 When you write a local interface, you extend javax.ejb.EJBLocalObject, and when you write a local home interface, you extend javax.ejb.EJBLocalHome. Those interfaces are previewed in the following code, and are fully explained in Appendix E. public interface javax.ejb.EJBLocalObject { public javax.ejb.EJBLocalHome getEJBLocalHome() throws javax.ejb.EJBException; public Object getPrimaryKey() throws javax.ejb.EJBException; public boolean isIdentical(javax.ejb.EJBLocalObject) throws javax.ejb.EJBException; public void remove() throws javax.ejb.RemoveException, javax.ejb.EJBException; } public interface javax.ejb.EJBLocalHome { public void remove(java.lang.Object) throws javax.ejb.RemoveException, javax.ejb.EJBException; } Local interfaces have two important side effects: They only work when you re calling beans in the same process for example, if you have a bank teller session bean that calls a bank account entity bean in the same application server. But there lies the rub. You cannot call a bean remotely if your code relies on the local interface. If you decide to switch between a local or remote call, you must change your code from using the local interface to using the remote interface. This is an inherent drawback to local interfaces. They marshal parameters by reference rather than by value. While this may speed up your application because parameters are not copied, it also changes the semantics of your application. Be sure that you re aware of this when coding your clients and beans. For a while, the primary author of this book (Ed Roman) has been pushing for Sun to adopt some kind of flag that enables you to switch between local and remote access to beans without changing code. The idea is that this flag would determine whether the container-generated interceptor object would behave as a local object or remote object. We think this is the best approach because (in reality) many developers will misjudge whether to use remote or local interfaces when designing their object models, and will have to rewrite parts of their code later in their projects.
We provide special commissions and earns up to $125 us per referral for all website hosting directories. With such big commissions you should immediately sign up for our affiliate program for website hosting directory sites.

46 Chapter 2 As you can see, we (Email web hosting)

Tuesday, October 30th, 2007

46 Chapter 2 As you can see, we avoid the steps of the stub, skeleton, network, and marshaling/ demarshaling of parameters. This empowers us to write smaller beans that perform more fine-grained tasks, without fear of a performance hit at each and every cross-bean method call. You can create beans in a fast way as well. Rather than using the home interface and home object, you can call a special local home interface, which is implemented by the container as the local home object. These local interfaces are entirely optional; you can use them as a replacement or as a complement to the remote interfaces. For simplicity, in the remainder of this book, we will use the word EJB object to mean the request interceptor, the remote interface to mean the interface to the request interceptor, the home object to mean the factory, and the home interface to mean the factory interface. Unless it s pointed out explicitly, all information that applies to these remote interfaces and remote objects also apply to their local counterparts. Also note that the EJB specification has defined the term component interface to mean either the remote interface or local interface. We will occasionally use this term in this book. EJB OBJECTS AND BEAN INSTANCES One question we frequently are asked in our EJB training courses is How many home objects are there for each bean? The answer to this question is vendor- specific. Most containers will have a 1:N relationship between home objects and bean instances. This means that all clients use the same home object instance to create EJB objects. The home object will probably be written to be thread-safe so that it can service many client requests concurrently. It is perfectly fine for the container to do this because the container itself is multithreaded (only your beans are single-threaded). Another question we typically get is How many EJB object instances are there for each bean instance? Some containers can have a 1:N relationship, where each EJB object is multithreaded (just like home objects). Other containers might have an M:N relationship, where M represents the number of EJB objects instantiated (and corresponds exactly to the number of clients currently connected), and N represents the number of bean instances in the pool. In this case, each EJB object is single-threaded. None of this really matters to you as a bean provider because you should think of the container as a black box. However, it s sometimes fun to know what s going on behind the scenes in case low-level debugging is required.
Pay us little and get a lot! We will give you the cheapest web hosting available, trust us and check cheapest web hosting services.

EJB Fundamentals 45 Client Code, Such as Servlets (Free web hosting music)

Monday, October 29th, 2007

EJB Fundamentals 45 Client Code, Such as Servlets or Applets EJB Container/Server 3: Return EJB Object Reference 1: Create a New EJB Object Enterprise Beans Home Interface 2: Create EJB Object Home Object EJB Object Remote Interface Figure 2.6 Home interfaces and objects. 1. The client calls a local stub. 2. The stub marshals parameters into a form suitable for the network. 3. The stub sends the parameters over a network connection to the skeleton. 4. The skeleton de-marshals parameters into a form suitable for Java. 5. The skeleton calls the EJB object. 6. The EJB object performs needed middleware, such as connection pooling, transactions, security, and life cycle services. 7. Once the EJB object calls the enterprise bean instance, and the bean does its work, each of the preceding steps must be repeated for the return trip home. Ouch! That s a lot of overhead. Figure 2.4 shows this process. Since version 2.0 of EJB, you can call enterprise beans in a fast, efficient way through their local objects rather than EJB objects. Local objects implement a local interface rather than a remote interface. The local objects are speed demons that enable you to make high-performance enterprise beans. The process works as follows: 1. The client calls a local object. 2. The local object performs needed middleware, such as connection pooling, transactions, security, and life cycle services. 3. Once the enterprise bean instance does its work, it returns control to the local object, which then returns control to the client.
We provides quality the CPanel Web Hosting. All our web hosting plans regular, business and expert are competitively priced and unsurpassed in reliability, uptime, and quality of service.

44 Chapter 2 integer as a parameter, and (Web site hosting)

Sunday, October 28th, 2007

44 Chapter 2 integer as a parameter, and another EJB object might take a string instead. The container needs to know this information to generate home objects. You provide this information to the container by specifying a home interface. Home interfaces simply define methods for creating, destroying, and finding EJB objects. The container s home object implements your home interface (see Figure 2.6). As usual, EJB defines some required methods that all home interfaces must support. These required methods are defined in the javax.ejb.EJBHome interface an interface that your home interfaces must extend. Source 2.3 shows javax.ejb.EJBHome. You will learn about these methods later. public interface javax.ejb.EJBHome extends java.rmi.Remote { public EJBMetaData getEJBMetaData() throws java.rmi.RemoteException; public javax.ejb.HomeHandle getHomeHandle() throws java.rmi.RemoteException; public void remove(javax.ejb.Handle handle) throws java.rmi.RemoteException, javax.ejb.RemoveException; public void remove(Object primaryKey) throws java.rmi.RemoteException, javax.ejb.RemoveException; } Source 2.3 A preview of the javax.ejb.EJBHome interface. Notice that the parent javax.ejb.EJBHome derives from java.rmi.Remote. This means your home interfaces do as well, implying that home objects are also fully networked Java RMI remote objects, which can be called across virtual machines. The types of parameters passed in the home interface s methods must be valid types for Java RMI-IIOP. The Local Interfaces One problem with the home interface is that creating beans through that interface is very slow. The same is true for calling beans through the remote interface. Just to give you an idea of what happens when you call an EJB object, the following steps may occur:
Pay us little and get a lot! We will give you the cheapest web hosting available, trust us and check cheapest web hosting services.

How to cite a web site - EJB Fundamentals 43 LOCATION TRANSPARENCY EJB inherits a

Saturday, October 27th, 2007

EJB Fundamentals 43 LOCATION TRANSPARENCY EJB inherits a significant benefit from RMI-IIOP. In RMI-IIOP, the physical location of the remote object you re invoking is masked from you. This feature spills over to EJB. Your client code is unaware of whether the EJB object it is using is located on a machine next door or a machine across the Internet. It also means the EJB object could be located on the same JVM as the client. This is called location transparency. Why is location transparency beneficial? For one thing, you aren t writing your bean s client code to take advantage of a particular deployment configuration because you re not hard-coding machine locations. This is an essential part of reusable components that can be deployed in a wide variety of multitier situations. Location transparency also enables container vendors to provide additional value-adds, such as the ability to take down a machine on the network temporarily to perform system maintenance, install new software, or upgrade components on that machine. During maintenance, location transparency allows another machine on the network to serve up components for a component s client because that client is not dependent on the hard locations of any components. If a machine that has components on it crashes due to hardware or software error, you may be able to reroute client invocations to other machines without the client even knowing about the crash, allowing for an enhanced level of fault tolerance. To acquire a reference to an EJB object, your client code asks for an EJB object from an EJB object factory. This factory is responsible for instantiating (and destroying) EJB objects. The EJB specification calls such a factory a home object. The chief responsibilities of home objects are the following: Create EJB objects Find existing EJB objects (for entity beans, which we ll learn about in Chapter 6) Remove EJB objects Just like EJB objects, home objects are proprietary and specific to each EJB container. They contain interesting container-specific logic, such as load-balancing logic, logic to track information on a graphical administrative console, and more. And just like EJB objects, home objects are physically part of the container and are autogenerated by the container vendor s tools. The Home Interface We ve mentioned that home objects are factories for EJB objects. But how does a home object know how you d like your EJB object to be initialized? For example, one EJB object might expose an initialization method that takes an
Our window web hosting plans are bursting with features and FREE tools, at the very small rate. Sign up today window web hosting.

42 Chapter 2 THE INSTANCE-POOLING (Php5 web hosting) CONCEPT A multitier

Saturday, October 27th, 2007

42 Chapter 2 THE INSTANCE-POOLING CONCEPT A multitier architecture s overall scalability is enhanced when an application server intelligently manages needed resources across a variety of deployed components. The resources could be threads, socket connections, database connections, and more. For example, database connections could be pooled by application servers and reused across heterogeneous components. In the EJB realm, the container is responsible for providing all resource management services behind the scenes. In addition to resource management, the EJB container is responsible for controlling the life cycle of the deployed enterprise bean components. As bean client requests arrive, the EJB container dynamically instantiates, destroys, and reuses beans as appropriate. For example, if a client requests a certain type of bean that does not yet exist in memory, the EJB container may instantiate a new in-memory instance on behalf of the client. On the other hand, if a bean already exists in memory, it may not be appropriate to instantiate a new bean, especially if the system is low on memory. It might make more sense to reassign a bean from one client to another instead. It might also make sense to destroy some beans that are not being used anymore. This is called instance pooling. The benefit of bean instance pooling is that the pool of beans can be much smaller than the actual number of clients connecting. This is due to client think time, such as network lag or human decision time on the client side. The classic example of this is an HTML (Web) client interacting with a human being. Web users often click a button that executes some business logic in a component, but then read text before initiating another action. While the user is waiting and reading, the application server could reuse that component to service other clients. While the client is thinking, the container can use the bean instances to service other clients, saving previous system resources. The take-away point here is that the EJB container is responsible for coordinating the entire effort of resource management as well as managing the deployed beans life cycle. Note that the exact scheme used is EJB container- specific. The Home Object As we ve discussed, client code deals with EJB objects and never with beans directly. The next logical question is, how do clients acquire references to EJB objects? The client cannot instantiate an EJB object directly because the EJB object can exist on a different machine than the one the client is on. Similarly, EJB promotes location transparency, so clients should never be aware of exactly where an EJB object resides.
We are comcast web hosting company willing to take you step further, please look comcat web hosting services.

Web site developers - EJB Fundamentals 41 throws java.rmi.RemoteException; public boolean isIdentical(javax.ejb.EJBObject)

Friday, October 26th, 2007

EJB Fundamentals 41 throws java.rmi.RemoteException; public boolean isIdentical(javax.ejb.EJBObject) throws java.rmi.RemoteException; } Source 2.2 (continued) The client code that wants to work with your beans calls the methods in javax.ejb.EJBObject. This client code could be standalone applications, applets, servlets, or anything at all even other enterprise beans. In addition to the methods listed in Source 2.2, your remote interface duplicates your beans business methods. When a bean s client invokes any of these business methods, the EJB object delegates the method to its corresponding implementation, which resides in the bean itself. Java RMI-IIOP and EJB Objects You may have noticed that javax.ejb.EJBObject extends java.rmi.Remote. The java.rmi.Remote interface is part of Java Remote Method Invocation over the Internet Inter-ORB Protocol (RMI-IIOP). Any object that implements java.rmi.Remote is a remote object and is callable from a different JVM. This is how remote method invocations are performed in Java. (We fully describe this in Appendix A.) Because the EJB object provided by the container implements your remote interface, it also indirectly implements java.rmi.Remote. Your EJB objects are fully networked RMI-IIOP objects, able to be called from other JVMs or physical machines located elsewhere on the network. Thus, EJB remote interfaces are really just RMI-IIOP remote interfaces except that EJB remote interfaces must also be built to conform to the EJB specification. EJB remote interfaces must conform to the RMI-IIOP remote interface rules. For example, any method that is part of a remote object callable across virtual machines must throw a special remote exception. A remote exception is a java.rmi.RemoteException, or (technically) a subclass of it. A remote exception indicates that something unexpected happened on the network while you were invoking across virtual machines, such as a network, process, or machine failure. Every method shown in Source 2.2 for javax.ejb.EJBObject throws a java.rmi.RemoteException. Remote interfaces must conform to the RMI-IIOP parameter-passing conventions as well. Not everything can be passed over the network in a cross-VM method call. The parameters you pass in methods must be valid types for RMI-IIOP. This includes primitives, serializable objects, and RMI-IIOP remote objects. The full details of what you can pass are in Appendix A.
We provide special commissions and earns up to $125 us per referral for all website hosting directories. With such big commissions you should immediately sign up for our affiliate program for website hosting directory sites.

40 Chapter 2 THE EJB (Cheap web hosting) CONTAINER: YOUR SILENT

Thursday, October 25th, 2007

40 Chapter 2 THE EJB CONTAINER: YOUR SILENT PARTNER EJB containers are responsible for managing your beans. Containers can interact with your beans by calling your beans required management methods as necessary. These management methods are your beans callback methods that the container, and only the container, invokes. The management methods allow the container to alert your beans when middleware events take place, such as when an entity bean is about to be persisted to storage. The most important responsibility of an EJB container is to provide an environment in which enterprise beans can run. EJB containers house the enterprise beans and make them available for clients to invoke remotely. In essence, EJB containers act as invisible middlemen between the client and the beans. They are responsible for connecting clients to beans, performing transaction coordination, providing persistence, managing a bean s life cycle, and other tasks. The key to understanding EJB containers is to realize that they are abstract entities. Neither the beans nor the clients that call beans ever explicitly code to the API of an EJB container. Rather, the container implicitly manages the overhead of a distributed component architecture. The container is analogous to a behind-the-scenes stage manager in a theater, providing the lighting and backdrop necessary for a successful stage performance by the actors on stage. Neither the actors nor the audience interact directly with the stage manager. The same is true for EJB containers. Clients that call the beans never code directly to an EJB container API. javax.ejb.EJBObject lists a number of interesting methods. For now, don t worry about fully understanding the meanings just know that these are required methods that all EJB objects must implement. And remember that you don t implement the methods the EJB container does when it autogenerates the EJB objects for you. public interface javax.ejb.EJBObject extends java.rmi.Remote { public javax.ejb.EJBHome getEJBHome() throws java.rmi.RemoteException; public java.lang.Object getPrimaryKey() throws java.rmi.RemoteException; public void remove() throws java.rmi.RemoteException, javax.ejb.RemoveException; public javax.ejb.Handle getHandle() Source 2.2 A preview of the javax.ejb.EJBObject interface.
Try discount web hosting services, our team’s aim is to offer the best possible web hosting services, at the lowest possible price.

EJB Fundamentals 39 (Web server extensions) EJB Container/Server Enterprise Bean Client

Wednesday, October 24th, 2007

EJB Fundamentals 39 EJB Container/Server Enterprise Bean Client Code, such as Servlets or Applets 1: Call a Method EJB Object Remote Interface 4: Method Returns 5: Return Result 3: Call a Bean Transaction Service, Security Service, Persistence Sevice, etc 2: Call Middleware APIs Figure 2.5 EJB objects. Each EJB container ships with a suite of glue-code tools. These tools are meant to integrate beans into the EJB container s environment. The tools generate helper Java code stubs, skeletons, data access classes, and other classes that this specific container requires. Bean providers do not have to think about the specifics of how each EJB container works because the container s tools generate its own proprietary Java code automatically. The container s glue-code tools are responsible for transforming an enterprise bean into a fully managed, distributed server-side component. This involves logic to handle resource management, life cycle, state management, transactions, security, persistence, remote accessibility, and many other services. The generated code handles these services in the container s proprietary way. The Remote Interface As mentioned previously, bean clients invoke methods on EJB objects, rather than the beans themselves. Therefore, EJB objects must clone every business method that your bean classes expose. But how do the tools that autogenerate EJB objects know which methods to clone? The answer is in a special interface that a bean provider writes. This interface duplicates all the business logic methods that the corresponding bean class exposes. This interface is called the remote interface. Remote interfaces must comply with special rules that the EJB specification defines. For example, all remote interfaces must derive from a common interface supplied by Sun Microsystems. This interface is called javax.ejb.EJBObject, and it is shown in Source 2.2.
Do you want truly affordable web hosting? With us, what you see is what you get, just click on affordable web hosting services.

Web hosting india - 38 Chapter 2 instances of your bean class.

Monday, October 22nd, 2007

38 Chapter 2 instances of your bean class. This saves you from having to worry about networking issues (the container provides networking as a service to you). Thus EJB products automatically convert your standalone, networkless components into distributed, network-aware entities. Implicit support. EJB containers automatically handle concurrent requests from clients. EJB containers provide built-in thread support, instantiating multiple copies of your component as necessary by instantiating lots of instances of your enterprise bean and pushing one thread through each instance. If multiple clients simultaneously invoke methods on a bean, the invocations are serialized, or performed lock step. The container will allow only one client to call a bean at a time. The other clients are routed to other bean instances of the same class or are forced to wait. (Behind the scenes, the container might use Java thread synchronization to aid with this. The actual algorithm used is container- specific.) The value of threading is obvious who enjoys writing multithreaded code? Implicit component location transparency. Clients of components are decoupled from the specific whereabouts of the component being used. Implicit monitoring. The EJB container can track which methods are invoked, display a real-time usage graph on a system administrator s user interface, gather data for intelligent load balancing, and more. An EJB container is not required to perform these tasks; however, high-end EJB containers perform these tasks at the point of interception. Thus, the EJB container acts as a layer of indirection between the client code and the bean. This layer of indirection manifests itself as a single network- aware object called the EJB object. The EJB object is the request interceptor we alluded to earlier. As the old saying goes, a layer of indirection solves every problem in computer science. The EJB object is a surrogate object that knows about networking, transactions, security, and more. It is an intelligent object that knows how to perform intermediate logic that the EJB container requires before a method call is serviced by a bean class instance. An EJB object is the request interceptor, or the glue, between the client and the bean. EJB objects replicate and expose every business method that the bean itself exposes. EJB objects delegate all client requests to beans. Figure 2.5 depicts EJB objects. You should think of EJB objects as physical parts of the container; all EJB objects have container-specific code inside of them. (Each container handles middleware differently and provides different qualities of service.) Because each bean s EJB object is different, your container vendor generates the class file for your EJB objects automatically.
Need a managed web hosting provider to help maintain your website? Our web hosting service is the preferred choice of thousands of demanding customers.