Announcement Announcement Module
Collapse
No announcement yet.
ContextSingletonBeanFactoryLocator MDB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ContextSingletonBeanFactoryLocator MDB

    I am facing serious problem spending nights not getting any clue.

    My Flow : MDB > SessionBean > Service Objects.

    I have issue of duplicate ApplicationContext. It is loading ApplicationContext 100 time (=number of beans) and application server (weblogic 9.2 )is dying eventually

    I have several Message-driven beans and I want them all to share the same applicationContext.xml ("applicationContext-main");


    My MDB Initiation Code :
    ================================================== ========

    public class DareBEMEMSGatewayMDB extends AbstractJmsMessageDrivenBean {

    /** Logger available to subclasses */
    protected final Log logger = LogFactory.getLog(getClass());

    private MessageDrivenContext ctx;

    public void setMessageDrivenContext(MessageDrivenContext
    messageDrivenContext) {
    this.ctx = messageDrivenContext;
    setBeanFactoryLocator(ContextSingletonBeanFactoryL ocator.getInstance("file:/app/fao/dare/applications/properties/beanRefContext.xml"));
    setBeanFactoryLocatorKey("applicationContext-main");
    }

    MessageData messageData = null;

    public DareBEMEMSGatewayMDB() {

    }

    public void onEjbCreate() {
    logger.debug("DareBEMEMSGatewayMDB instance created");
    messageProcessor = ((CoreMessageProcessor) getBeanFactory().getBean(
    DareCoreConstants.CORE_MESSAGE_PROCESSOR));
    edmService = ((EdmService) getBeanFactory().getBean(
    DareCoreConstants.EDM_SERVICE));
    //System.out.println("DareBEMEMSGatewayMDB :"+messageProcessor);
    }

    ================================================== ========

    My Session Bean Code :

    ================================================== ========public class MessageProcessorEJB extends AbstractStatelessSessionBean implements CoreMessageProcessor {

    private SessionContext sessionContext;

    private DareMessageFlowHandler dareMessageFlowHandler = null;


    public MessageProcessorEJB() {
    logger.debug("MessageProcessorEJB constructor called");
    }

    public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
    setBeanFactoryLocator(ContextSingletonBeanFactoryL ocator.getInstance("file:/app/fao/dare/applications/properties/beanRefContext.xml"));
    setBeanFactoryLocatorKey("applicationContext-main");
    }

    public void onEjbCreate() {
    logger.debug("MessageProcessorEJB instance created");
    dareMessageFlowHandler = ((DareMessageFlowHandler) getBeanFactory().getBean(
    DareCoreConstants.FLOW_HANDLER));
    //System.out.println("DareGatewayMDB :"+messageProcessor);
    }

    ================================================== ========

    My ejb-jar.xml
    ================================================== ========

    <message-driven>
    <ejb-name>dareBEMEMSGatewayMDB</ejb-name>
    <ejb-class>com.dare.jms.support.DareBEMEMSGatewayMDB</ejb-class>
    <transaction-type>Container</transaction-type>
    <activation-config>
    <activation-config-property>
    <activation-config-property-name>subscriptionDurability</activation-config-property-name>
    <activation-config-property-value>NonDurable</activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
    <activation-config-property-name>acknowledgeMode</activation-config-property-name>
    <activation-config-property-value>auto-acknowledge</activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
    <activation-config-property-name>destinationType</activation-config-property-name>
    <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
    </activation-config-property>
    </activation-config>
    <env-entry>
    <env-entry-name>ejb/BeanFactoryPath</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>file:/app/fao/dare/applications/properties/dareCoreConfig.xml</env-entry-value>
    </env-entry>
    </message-driven>
    ================================================== ========

    weblogic-ejb-jar.xml
    ================================================== =======
    <weblogic-enterprise-bean>
    <ejb-name>dareBEMEMSGatewayMDB</ejb-name>
    <message-driven-descriptor>
    <pool>
    <max-beans-in-free-pool>10</max-beans-in-free-pool>
    <initial-beans-in-free-pool>5</initial-beans-in-free-pool>
    </pool>
    <destination-jndi-name>com.csfb.dare.EmsDareInputQueue</destination-jndi-name>
    <connection-factory-jndi-name>com.csfb.dare.EMSQueueConnectionFactory</connection-factory-jndi-name>
    <generate-unique-jms-client-id>true</generate-unique-jms-client-id>
    <max-messages-in-transaction>5</max-messages-in-transaction>
    </message-driven-descriptor>
    <jndi-name>jms/DareBEMEMSGatewayMDB</jndi-name>
    </weblogic-enterprise-bean>
    ================================================== =======


    Pls tell me where am I lacking ...

  • #2
    This is serious issue for me has anybody got any solution. I wonder If I should use ClassPathXmlApplicationContext instead of FileSystemXmlApplicationContext as I have seen in previous post, they are keeping beanRefFactory.xml in application classpath (root), where as I am keeping it in File absolute path.

    Comment


    • #3
      Why don't you load the context in a static object(once) and give it out to MDBs and EJBs as required?

      Comment


      • #4
        Could u pls tell me how to load context, and how mdb and ejb can share same context .?

        Comment


        • #5
          The ContextSingletonBeanFactoryLocator should work, as it keeps a static map. I assume you use the Abstract*Bean from Spring. You should set them however in your constructor and not in your setSessionContext (however I'm am a bit lost on the EJB lifecycles, way to long that I used them ).

          I also wonder WHY you are specifing a JNDI reference to the file containing your application context. Which could also be the problem.

          The initial context is created using the ContextJndiBeanFactoryLocator because that is called on the creation of the ejb (and before the setSessionContext and setMessageDrivenContext).

          So set the stuff you now set in yuor setSessionContext in your constructor and you should be good to go.

          [edit]
          Just checked the life cycle the setSessionContext/setMessageDrivenContext is called before the ejb create, however I would still remove the ejb/BeanFactoryPath from your configuration.
          [/edit]
          Last edited by Marten Deinum; Oct 2nd, 2007, 04:37 AM.

          Comment


          • #6
            Originally posted by shivnarayan View Post
            Could u pls tell me how to load context, and how mdb and ejb can share same context .?
            What I meant was, create a static ref. to the application context in your ejb layer something like this:
            Code:
            public  class ContextGenerator {
            	private static ApplicationContext ctx;
            	static {
            		ApplicationContext sc= new ClassPathXmlApplicationContext("applicationContext.xml");
            		assert (sc != null);
            		ctx=sc;
            	}
            	public static Object getSpringContext() {
            		return ctx;
            	}
            And in MDBs, always call this to get the context

            Code:
            onMessage() {
            ....
            ApplicationContext handle=(ApplicationContext)ContextGenerator.getSpringContext();
            			
            			Object o=handle.getBean("Some bean");
            I also did try the singleton factory method, but under stress test I see that it is being loaded more than once.

            Comment


            • #7
              Originally posted by ghosh007 View Post

              I also did try the singleton factory method, but under stress test I see that it is being loaded more than once.
              Actually the singleton method does work. I just had an issue with my code.

              Comment


              • #8
                If the singleton works the ContextSingletonBeanFactoryLocator should also work, because it actually does the same as your singleton. Load the configuration one, put it in a static map, retrieve it using the BeanFactoryLocatoryKey.

                Comment


                • #9
                  Thanks All for your replies... I was trying ContextSingletonBeanFactoryLocator, but some how it was not working...I have given my code and implementation details already.. But I find idea having our own spring context and referring it everywhere worth considering.. Thanks once again.

                  Comment

                  Working...
                  X