Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What exception will be thrown if ejbRemove() is called in onMessage method?

 
calvin zhu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just curious.
Because the Spec just said ejbRemove will be called by the container in Message bean. But I didn't find words about bean provider can not call this method in the onMessage code.
The reason I have this question is from this thread.
http://www.coderanch.com/t/158405/java-EJB-SCBCD/certification/Message-Driven-beans
 
Keith Rosenfield
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Calvin:
Originally posted by calvin zhu:
just curious.
Because the Spec just said ejbRemove will be called by the container in Message bean.

I would like to try to answer your question. Where in the spec did you find this?
Keep in mind that container callback methods(ejb<method> are only supposed to be called by the container. I'm not sure what the container does if you attempt to circumvent its lifecyle management.
Thanks,
[ January 13, 2004: Message edited by: Keith Rosenfield ]
 
calvin zhu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Keith, the spec does mention in lots of place that the ejbRemove will be called by the container, right?
e.g:
in page 318,
"The Bean Provider cannot assume that the Container will always invoke the ejbRemove() method on a message-driven bean instance."
which indicate most of the situaion, the Container will call the ejbRemove().
But I didn't find any place say Bean Provider cann't call ejbRemove(). So I'm intereted in the result, but I don't have the environment setup to do the test.
 
Keith Rosenfield
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Calvin,
I'm not quite sure what happens. I will research it and let you know what I discover.
 
Keith Rosenfield
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The client can not get a reference to the bean and therefore can not call ejbRemove or any of the callback methods for that matter. Clients can only get a reference to the home or component interface. The component interface doesn't define the callback methods. So the answer to your question is that it can never happen.
Hope this helps.
 
calvin zhu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Keith, for your effort and time.
But I'm not talking about invoke ejbRemove through client, which will never happen in Message Bean, since it doesn't have any client, just like you said.
What I'm asking is what will happy if I code like this:
public void onMessage(javax.jms.Message.){
.
other business related code;
.
.
ejbRemove();
}
After I chatted with my colleague with this question, I think this is the answer:
On Spec Page 315:
"The ejbRemove notification signals that the instance is in the process of being removed by the container.In the ejbRemove method, the instance releases the resources that it is holding."
So Bean Provider implements ejbRemove() just for doing clean-up works, the actually removing the Message Bean instance is done by the Container outside of ejbRemove method. So calling ejbRemove in the onMessage will result in doing the clean-up work in the onMessage method, that's it, nothing else will happen.
 
Keith Rosenfield
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Calvin
That makes sense. I thought you meant calling ejbRemove outside of the bean. That is similar to calling the run method of a thread directly instead of calling start.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic