• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local and remote component args

 
Peter Warde
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been thinking about the difference in arguments of business methods for local and remote components as described in Headfirst EJB. If the component is local then what is passed as the business method arg is a copy of the reference to the object on the same heap, if it's remote it's a copy of the object from the clients heap to the server's heap.

I know that this relates to business logic, normal Java rules etc rather than being EJB specific, but can anybody think of a scenario where the internal coding of a business method would be different for both cases. It would help reinforce the idea.
 
Leena Diwan
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want to say the difference in the business method accepting arguments locally or remotly? Like if the business methods needs to wrok on the args differently?
So far as I know, its not so.

Leena
 
Harpreet Hira
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One major difference is that when an object is passed as an argument to EJB's method and EJB's method does some action on that object and after the method returns the client works further on that object.
1. In case of Remote component, we need to explicitly return the object.
2. In case of Local component, we might not want to return anything as we are already working on the same object.

I always perfer to use remote components rather than local components. One reason is that in most of the application servers you can make the method invocations on remote components to "pass by reference" instead of "pass by value" by just checking a checkbox. The benefit of keeping remote components always is that in future if you want to move your EJBs on different machine, you don't need to make changes to the code.
 
Peter Warde
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harpreet - I like your above example. One solution to the problem suggested by HeadFirst EJB is to maintain consistency have all arguments a copy of an object. You can do this with local interfaces by cloning the object and then passing a reference to the cloned object as a method argument.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic