Friday, June 25, 2010

EJB CONTINUES ... 6

QUESTION: Can the bean class implement the EJBObject class directly? If not why?
ANSWER: It is better not to do it will make the Bean class a remote object and its methods can be accessed without the containers? security, and transaction implementations if our code by mistake passed it in one of its parameters. Its just a good design practice.

QUESTION: What does isIdentical() method return in case of different type of beans?
ANSWER: Stateless ? true always
Stateful ? depends whether the references point to the same session object
Entity ? Depends whether the primary key is the same and the home is same

QUESTION: How should you type cast a remote object? Why?
ANSWER: A client program that is intended to be interoperable with all compliant EJB Container implementations must use the javax.rmi.PortableRemoteObject.narrow(...) method to perform type-narrowing of the client-side representations of the remote home and remote interfaces. Programs using the cast operator for narrowing the remote and remote home interfaces are likely to fail if the Container implementation uses RMI-IIOP as the underlying communication transport.

QUESTION: What should you do in a passivate method?
ANSWER: You try to make all nontransient variables, which are not one of the following to null. For the given list the container takes care of serializing and restoring the object when activated.
Serializable objects, null, UserTransaction, SessionContext, JNDI contexts in the beans context, reference to other beans, references to connection pools.
Things that must be handled explicitly are like a open database connection etc. These must be closed and set to null and retrieved back in the activate method.

QUESTION: What is the relationship between local interfaces and container-managed relationships?
ANSWER: Entity beans that have container-managed relationships with other entity beans, must be accessed in the same local scope as those related beans, and therefore typically provide a local client view. In order to be the target of a container-managed relationship, an entity bean with container-managed persistence must provide a local interface.

QUESTION: What does a remove method do for different cases of beans?
ANSWER: Stateless Session : Does not do anything to the bean as moving the bean from free pool to cache are managed by the container depending on load.
Stateful Session: Removes the bean from the cache.
Entity Bean: Deletes the bean (data) from persistent storage

QUESTION: How does a container-managed relationship work?
ANSWER: An entity bean accesses related entity beans by means of the accessor methods for its container-managed relationship fields, which are specified by the cmr-field elements of its abstract persistence schema defined in the deployment descriptor. Entity bean relationships are defined in terms of the local interfaces of the related beans, and the view an entity bean presents to its related beans is defined by its local home and local interfaces. Thus, an entity bean can be the target of a relationship from another entity bean only if it has a local interface.

QUESTION: What is the new basic requirement for a CMP entity bean class in 2.0 from that of ejb 1.1?
ANSWER: It must be abstract class. The container extends it and implements methods which are required for managing the relationships

QUESTION: What are the basic classes required in the client for invoking an EJB?
ANSWER: The home and the remote interfaces, the implementation of the Naming Context Factory, the stubs and skeletons.
In some App servers the stubs and the skeletons can be dynamically downloaded from the server

QUESTION: What is the difference between Message Driven Beans and Stateless Session beans?
ANSWER: In several ways, the dynamic creation and allocation of message-driven bean instances mimics the behavior of stateless session EJB instances, which exist only for the duration of a particular method call. However, message-driven beans are different from stateless session EJBs (and other types of EJBs) in several significant ways:
§ Message-driven beans process multiple JMS messages asynchronously, rather than processing a serialized sequence of method calls.
§ Message-driven beans have no home or remote interface, and therefore cannot be directly accessed by internal or external clients. Clients interact with message-driven beans only indirectly, by sending a message to a JMS Queue or Topic.
Note: Only the container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary.
§ The Container maintains the entire lifecycle of a message-driven bean; instances cannot be created or removed as a result of client requests or other API calls.

QUESTION: What are the benefits of Clustering (Workload Management)?
ANSWER: They are
1. It balances client processing requests, allowing incoming work requests to be distributed according to a configured Workload Management selection policy.
2. It provides fail over capability by redirecting client requests to a running server when one or more servers are unavailable. This improves the availability of applications and administrative services.
3. It enables systems to be scaled up to serve a higher client load than provided by the basic configuration. With server groups and clones additional instances of servers can easily be added to the configuration.
4. It enables servers to be transparently maintained and upgraded while applications remain available for users.
5. It centralizes administration of application servers and other objects.

QUESTION: What are the types of Scaling?
ANSWER: There are two types of scaling
1. Vertical Scaling
2. Horizontal Scaling.

QUESTION: What is Vertical Scaling?
ANSWER: When multiple server clones of an application server are defined on the same physical m/c, it is called Vertical Scaling. The objective is to use the processing power of that m/c more efficiently.

QUESTION: What is Horizontal Scaling?
ANSWER: When Clones of an application server are defined on multiple physical m/c, it is called Horizontal Scaling. The objective is to use more than one less powerful m/c more efficiently.