• Post Reply Bookmark Topic Watch Topic
  • New Topic

MDB Design Decisions  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I working on my first MDB and would like your comments about several design decisions:
1) Should I send a TextMessage or an ObjectMessage ? Any performance implications ? One of the cons of TextMessage is that I will need to invent my old packet format and reparse it to an object later on.
2) How do you handle a JMSException within onMessage(Message) ? I just log it and return.
3) In this MDB as a listener article, the MDB doesn't do any work. It delegates the processing of the message to a worker SLSB (Stateless session bean). This is following the Message Dispatcher Pattern. Any other alternatives other than performing the processing within the MDB itself ?
Thanks
Pho
[ January 28, 2004: Message edited by: Pho Tek ]
[ January 28, 2004: Message edited by: Pho Tek ]
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) You should send TextMessages only if you are sending plain text. If you are sending objects of your own you could wrap them in ObjectMessages and then unwrap them when receiving the messages. The code at the MDB should be like:
if(msg instanceof ObjectMessage){
try {
ObjectMessage om = (ObjectMessage) msg;
if (om.getObject() instanceof your_object_class) {
..............
}
}
2) When catching a JMSException you could only log the problem or you could retry the operation, depeding on the importance of what you were doing.
3) This is a common practice of using MDBs only for delegating the calls to Session Beans which do all the work. You could use one MDB facading each of your Session Beans or you could use a master MDB which,depending on the message, knows to whome to delegate the call. If the process is asynchronous you should use MDBs as a layer of delegation, and if it's synchronous you should consider the Business Delegate pattern. This is an extra layer of simple java objects whitch hide from the client the logic of accessing the Session Beans and simply delegate the calls to the Session Beans.
Hope this helps,
Sergiu.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergiu,
I have decided against using ObjectMessage. Doing so would mean that the client and server are coupled.
Digressing a bit: Initially I wanted to create multiple SLSB worker classes, one for each operation type. However since there are some common functionality, is it possible to use inheritance to share functionality among the SLSBs (I've heard that EJB does not allow inheritance?).
Thanks
Pho
[ January 28, 2004: Message edited by: Pho Tek ]
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using an ObjectMessage indeed couples the client and the server through the DTO object. But this is the main purpose of the DTO, transferring data between the server and the client. After all, DTO is an Inter-tier-data-transfer-pattern.
You could use TextMessages to send data to the server, but as you project grows bigger and more complex, you might have more complex data objects to handle, and the parsing logic of the received text from the client would grow more and more complex.
Of course, this is a design issue but you have to think in perspective and take into account the possible features that might be added to your project.
About using iheritance in EJBs, I don't see why not. There is a pattern I know of that uses inheritance, called Dual Persistent Entity Bean.
You might try using inheritance inside your SLSBs too.
Anyways, I haven't seen using inheritance between EJBs in any project I've worked on. You might try, though.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pho Tek:
Digressing a bit: Initially I wanted to create multiple SLSB worker classes, one for each operation type. However since there are some common functionality, is it possible to use inheritance to share functionality among the SLSBs (I've heard that EJB does not allow inheritance?).

No, inheritance works fine -- I'm using it in my SLSBs too. If you're using XDoclet to process your beans, make sure the subclasses implement the J2EE bean interfaces along with extending the base classes.
With entity beans it can become quite tricky. I have a BaseEJB that adds utility methods, but the real entities have all the attributes (even the common ones). I haven't tried pushing the common fields to the superclass yet (got other high priority stuff already).
 
Hu Chong
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, as i was looking at this topic on MDB, i like to know for what kind of situations can MDB be used effectively?
One example i can think is processing of book reservations in the library. The web application will send the request to the queue, which then is picked up by the MDB and processed it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!