0 Replies Latest reply on Sep 3, 2007 12:04 AM by shankha

    Mbean invoker.stopDelivery() not working

    shankha

      Hi,
      I am able to control my deployed MDB programatically.

      Basically my code invoke the responsible MBean for that MDB and call the invoker.stopDelivery() method on that MBean.

      It will restrict the MDB to get the message from Queue.

      I can also withdrow the restriction of the MDB to get message from queue by invoking invoker.startDelivery(); on the MBean.

      responsible MBean is

      Code:
      MBean Name: Domain Name: jboss.j2ee
      service: EJB
      plugin: invoker
      binding: message-driven-bean
      jndiName: MessageEJB
      MBean Java Class: org.jboss.ejb.plugins.jms.JMSContainerInvoker


      --------
      But the problem is after invoking invoker.stopDelivery() ,still the MDB reads the 1st queue message.

      That is If I send 4 message after stop It will read the 1st one - other 3 messages are blocked unless I invoke startDelivery();

      If I send 7 messages - MDB consume 1 st one :( other 6 are blocked .
      then when I invoke startDelivery(); I will get the 6 messages with MDB.

      Can any body help me -???


      Stop delivery Code

      Code:
      package com.test;

      import org.jboss.logging.Logger;
      import org.jboss.mx.util.MBeanServerLocator;
      import org.jboss.mx.util.MBeanProxy;
      import org.jboss.ejb.plugins.jms.JMSContainerInvokerMBean;

      import javax.ejb.SessionBean;
      import javax.ejb.CreateException;
      import javax.ejb.SessionContext;
      import javax.ejb.EJBException;
      import javax.management.MBeanServer;
      import javax.management.ObjectName;
      import javax.management.MalformedObjectNameException;
      import javax.management.MBeanInfo;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      /**
      * Created by IntelliJ IDEA.
      * User: 151054
      * Date: Aug 30, 2007
      * Time: 2:29:30 PM
      * To change this template use File | Settings | File Templates.
      */

      public class MBeanTestBean implements SessionBean {

      //private static Logger log;
      private SessionContext mContext;
      private MBeanServer mbeanServer;
      private ObjectName mManagementService;

      private Context jndiCtx=null;
      private JMSContainerInvokerMBean invoker = null;


      public MBeanTestBean() {
      }

      public void ejbCreate() throws CreateException {

      if(mbeanServer == null)
      try {
      jndiCtx = new InitialContext();
      String serverName = (String)jndiCtx.lookup("java:comp/env/Server-Name");
      serverName = serverName.trim();
      if(serverName == null || serverName.length() == 0 || serverName.equals("null")) {
      try {
      mbeanServer = MBeanServerLocator.locateJBoss();
      System.out.println("@@@ --------- mbeanServer = "+mbeanServer.getDefaultDomain());
      System.out.println("@@@ --------- mbeanServer No of MBean = "+mbeanServer.getMBeanCount());

      }
      catch(IllegalStateException e) {
      throw new CreateException("No local JMX MBeanServer available");
      }
      } else {
      Object lServer = jndiCtx.lookup(serverName);
      if(lServer != null) {
      if(lServer instanceof MBeanServer)
      mbeanServer = (MBeanServer)lServer;
      else
      throw new CreateException("Server: " + lServer + " reference by Server-Name: " + serverName + " is not of type MBeanServer");
      } else {
      throw new CreateException("Server-Name " + serverName + " does not reference an Object in JNDI");
      }
      }
      }
      catch(NamingException ne) {
      throw new EJBException(ne);
      }
      }

      public void setSessionContext(SessionContext sessionContext) throws EJBException {
      }

      public void ejbRemove() throws EJBException {
      }

      public void ejbActivate() throws EJBException {
      }

      public void ejbPassivate() throws EJBException {
      }

      public void invokeMBeanFeatures(){

      try{

      //Object name = jndiCtx.lookup("MessageEJB");

      ObjectName objName = new ObjectName("jboss.j2ee:service=EJB,plugin=invoker,binding=message-driven-bean,jndiName=MessageEJB");
      //ObjectName objName = new ObjectName((String)name);
      MBeanInfo objMBeanInfo = mbeanServer.getMBeanInfo(objName);
      System.out.println("@@ -- MBeanTestBean :invokeMBeanFeatures : "+objMBeanInfo.getClassName());

      invoker = (JMSContainerInvokerMBean) MBeanProxy.get(JMSContainerInvokerMBean.class,objNa
      me,mbeanServer );
      //invoker.stopDelivery();
      System.out.println("@@ Invoker Name = " +invoker.getName());
      System.out.println("@@ Invoker Pllo Size = " +invoker.getMinPoolSize());
      //System.out.println("@@ Invoker Name = " +);
      System.out.println("@@ Invoker Message = " +invoker.getMaxMessages());

      invoker.stopDelivery();

      System.out.println("@@ Invoker Message = stopDelivery ");

      //invoker.getClass().newInstance().stopDelivery();
      //invoker.getClass().newInstance().stop();



      }catch(Exception ex){

      ex.printStackTrace();
      }
      }
      }


      Start delivary code

      Code:

      package com.test;

      import org.jboss.ejb.plugins.jms.JMSContainerInvokerMBean;
      import org.jboss.mx.util.MBeanServerLocator;
      import org.jboss.mx.util.MBeanProxy;

      import javax.ejb.SessionBean;
      import javax.ejb.CreateException;
      import javax.ejb.SessionContext;
      import javax.ejb.EJBException;
      import javax.management.MBeanServer;
      import javax.management.ObjectName;
      import javax.management.MBeanInfo;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      /**
      * Created by IntelliJ IDEA.
      * User: 151054
      * Date: Aug 30, 2007
      * Time: 7:09:22 PM
      * To change this template use File | Settings | File Templates.
      */

      public class MBeanStartBean implements SessionBean {

      private SessionContext mContext;
      private MBeanServer mbeanServer;
      private ObjectName mManagementService;

      private Context jndiCtx=null;
      private JMSContainerInvokerMBean invoker = null;

      public MBeanStartBean() {
      }

      public void ejbCreate() throws CreateException {

      if(mbeanServer == null)
      try {
      jndiCtx = new InitialContext();
      String serverName = (String)jndiCtx.lookup("java:comp/env/Server-Name");
      serverName = serverName.trim();
      if(serverName == null || serverName.length() == 0 || serverName.equals("null")) {
      try {
      mbeanServer = MBeanServerLocator.locateJBoss();
      System.out.println("@@@ --------- mbeanServer = "+mbeanServer.getDefaultDomain());
      System.out.println("@@@ --------- mbeanServer No of MBean = "+mbeanServer.getMBeanCount());

      }
      catch(IllegalStateException e) {
      throw new CreateException("No local JMX MBeanServer available");
      }
      } else {
      Object lServer = jndiCtx.lookup(serverName);
      if(lServer != null) {
      if(lServer instanceof MBeanServer)
      mbeanServer = (MBeanServer)lServer;
      else
      throw new CreateException("Server: " + lServer + " reference by Server-Name: " + serverName + " is not of type MBeanServer");
      } else {
      throw new CreateException("Server-Name " + serverName + " does not reference an Object in JNDI");
      }
      }
      }
      catch(NamingException ne) {
      throw new EJBException(ne);
      }
      }

      public void setSessionContext(SessionContext sessionContext) throws EJBException {
      }

      public void ejbRemove() throws EJBException {
      }

      public void ejbActivate() throws EJBException {
      }

      public void ejbPassivate() throws EJBException {
      }


      public void invokeMBeanStart(){
      try{

      //Object name = jndiCtx.lookup("MessageEJB");

      ObjectName objName = new ObjectName("jboss.j2ee:service=EJB,plugin=invoker,binding=message-driven-bean,jndiName=MessageEJB");
      //ObjectName objName = new ObjectName((String)name);
      MBeanInfo objMBeanInfo = mbeanServer.getMBeanInfo(objName);
      System.out.println("@@ -- MBeanTestBean :invokeMBeanFeatures : "+objMBeanInfo.getClassName());

      invoker = (JMSContainerInvokerMBean) MBeanProxy.get(JMSContainerInvokerMBean.class,objNa
      me,mbeanServer );
      //invoker.stopDelivery();
      System.out.println("@@ Invoker Name = " +invoker.getName());
      System.out.println("@@ Invoker Pllo Size = " +invoker.getMinPoolSize());
      //System.out.println("@@ Invoker Name = " +);
      System.out.println("@@ Invoker Message = " +invoker.getMaxMessages());

      invoker.startDelivery();
      //invoker.
      System.out.println("@@ Invoker Message = startDelivery ");

      //invoker.getClass().newInstance().stopDelivery();
      //invoker.getClass().newInstance().stop();



      }catch(Exception ex){

      ex.printStackTrace();
      }
      }
      }