EJB for noobs

Lets say we have a Java program and it has a multiply method which takes 2 arguments,multiply and send back the result. So in runtime we can just pass the references of the 2 varibles and get the result right.

What if the mutliply(arg1, arg2) method is not in the same machine. What if it is in a different machine. So it doesnt make sense to pass the memory references of the variables to a another machine's implementation. So if we have a server like that implemented a functionality like mutliply(arg1, arg2) we can serialize the arguments. Serialization means , you take the values or objects (not the referecnes) and convert that into a byte stream. So when you send serilaize arguments to a server, it can have a deserialize process and get the original messages. Typically for serialization and deseriaization process we have stubs in both ends.

  1. In the client side it is called client stub
  2. In the sever side it is called server skeleton
So how do we know which server to pass serialize messages and which server to call. That is when a registry comes in to play. So that is basic scenario in Java-RMI. Its all about talking with different JVMs. J2EE and EJB are also built up on this very same concepts.






Java bean : object or program that can handle business logic

Enterprise Java bean (EJB): Special type of Java bean that can handle business logic. Or a Java bean that is upto J2EE specifications.

  • EJBs properties are private. So need getters and setters.
  • Should have a no argument constructor
  • Should implement Serializeable API (because we can pass references across JVMs)

A typical EJB system/J2EE server environment  is composed of 3 parts.
  • Component
  • Container
  • Object and remote interface

Component 

A program/object that has functionality of an EJB. There are 2 types of EJB components.
  • Session beans(statefull, statlesss, singleton)
  • Message driven beans

Session beans

Clients can invoke session beans. It stores local data. So no persistancy.
  • Statefull session beans - Unique connection between client and session bean. When the connection is lost session is over.
  • Statelss session beans - Any client can invoke stateless session bean
  • Singleton session bean - One bean for an application. 

Message driven beans

These bean are invoked on special events. So according to events from external entities, they can react. Because not every action is to completed synchronously. For some action you can queue it up and execute when the server can.



Share:

0 comments: