I was wondering why do we need separate Remote and Local intefaces for EJB 3.0 Session beans. I guess most of the time they would both be defining the same contract. Why cant I have a common interface and in my Bean I should just be able to say that I want this bean to be accessed remotely and/or locally.
thanks Vikas
Using the remote and local interfaces appropriately means that clients can access EJB components efficiently. That is, local clients use the local interface with pass-by-reference semantics, while remote clients use the remote interface with pass-by-value semantics.
Yes, it is possible for a bean to expose multiple views (Remote business, Local business, no-interface). The component can be the same - you just add another ways of accessing it.
The bean class must implement the javax. ejb. SessionBean interface.
An EJB has two client interfaces: Remote interface--The remote interface specifies the business methods that the clients of the object can invoke. Home interface--The home interface defines EJB life cycle methods, such as a method to create and retrieve a reference to the bean object.
This is what the EJB spec says:
The choice between the local and the remote programming model is a design decision that the Bean Provider makes when developing the enterprise bean.
While it is possible to provide both a remote client view and a local client view for an enterprise bean, more typically only one or the other will be provided.
JSR220 Chapter 3
So when writing a bean think about who is the client, it's very unlikely that a local client will need the same methods or even the same bean that a remote one.
I don't agree that at design time remote and local should be treated as trivially inter-changable.
First, there are overheads in remote invocation, so when designing remote interfaces you need to consider carefully whether you've got the granularity and parameter sizes right. So a reminder this is going to be comparatively expensive is helpful as a designer.
Also, Given that remote interfaces parameters are passed by value and local interface parameters are passed by reference there are fundamental semantic differences between the two cases hence you might choose to design the two interfaces differently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With