Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need separate Remote and Local interfaces for EJB 3.0 session beans

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

like image 267
Vikas Kedia Avatar asked Sep 06 '09 13:09

Vikas Kedia


People also ask

What is the difference between local and remote interface in EJB?

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.

Can we define a bean with remote and @local?

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.

Which interface must be extended by all session beans?

The bean class must implement the javax. ejb. SessionBean interface.

What is EJB and interface used in EJB?

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.


2 Answers

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.

like image 98
rodrigoap Avatar answered Oct 13 '22 03:10

rodrigoap


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.

like image 45
djna Avatar answered Oct 13 '22 03:10

djna