01 package com.bea.medrec.registration;
02
03 import com.bea.medrec.controller.PatientSession;
04 import com.bea.medrec.utils.JNDINames;
05 import com.bea.medrec.utils.MedRecLog4jFactory;
06 import com.bea.medrec.utils.ServiceLocator;
07 import com.bea.medrec.value.Registration;
08 import javax.ejb.EJBException;
09 import javax.ejb.MessageDrivenContext;
10 import javax.jms.JMSException;
11 import javax.jms.Message;
12 import javax.jms.MessageListener;
13 import javax.jms.ObjectMessage;
14 import javax.naming.NamingException;
15 import org.apache.log4j.Logger;
16 import weblogic.ejb.GenericMessageDrivenBean;
17 import weblogic.ejbgen.*;
18
19 /**
20 * <p>Handles the flow of incoming registration.</p>
21 *
22 * @author Copyright (c) 1999-2006 by BEA Systems, Inc. All Rights Reserved.
23 *
24 * Note: Recommend initial-beans-in-free-pool == max-beans-in-free-pool
25 * for production system.
26 */
27 @EjbRefs({
28 @EjbRef(name = "ejb/patientsession",
29 home = "com.bea.medrec.controller.PatientSessionHome",
30 remote = "com.bea.medrec.controller.PatientSession",
31 type = Constants.RefType.SESSION,
32 link = "PatientSessionEJB",
33 jndiName = "PatientSessionEJB.PatientSessionHome")
34 })
35 @MessageDriven(ejbName = "RegistrationBean",
36 destinationJndiName = "jms/REGISTRATION_MDB_QUEUE",
37 destinationType = "javax.jms.Queue",
38 initialBeansInFreePool = "0",
39 maxBeansInFreePool = "10",
40 defaultTransaction = MessageDriven.DefaultTransaction.REQUIRED)
41 @ResourceEnvRefs({
42 @ResourceEnvRef(name = "jms/MAIL_MDB_QUEUE",
43 type = "javax.jms.Queue",
44 jndiName = "jms/MAIL_MDB_QUEUE")
45 })
46 public class RegistrationEJB
47 extends GenericMessageDrivenBean implements MessageListener {
48
49 private static Logger logger =
50 MedRecLog4jFactory.getLogger(RegistrationEJB.class.getName());
51
52 // Member variables
53 private MessageDrivenContext ctx;
54 private PatientSession patientSession;
55
56 public void setMessageDrivenContext(MessageDrivenContext mdc) {
57 ctx = mdc;
58 try {
59 ServiceLocator locator = ServiceLocator.getInstance();
60 Object obj = locator.getObj(JNDINames.PATIENT_SESSION_REMOTE_HOME,
61 com.bea.medrec.controller.PatientSessionHome.class);
62 patientSession = (PatientSession) obj;
63 } catch (NamingException ne) {
64 throw new EJBException(ne);
65 }
66 }
67
68 /**
69 * <p>Retrieve the Patient Value Object and print it out.</p>
70 */
71 public void onMessage(Message msg) {
72 logger.debug("Message from registration queue: "+msg);
73
74 // Declare and initialize local variables
75 ObjectMessage message = (javax.jms.ObjectMessage) msg;
76 Registration registration = null;
77 try {
78 registration = (Registration) message.getObject();
79 patientSession.processNewRegistration(registration);
80 } catch (JMSException jmsex) {
81 logger.error("Unable to register the following user: \n" +
82 registration.toString(), jmsex);
83 getMessageDrivenContext().setRollbackOnly();
84 } catch (Exception ex) {
85 logger.error("Unable to register the following user: \n" +
86 registration.toString(), ex);
87 }
88 }
89 }
90
|