[jboss-user] [Beginners Corner] - How can I Stop MDB via Programming ?
shankha
do-not-reply at jboss.com
Thu Aug 30 08:13:45 EDT 2007
I have deployed a MDB in the JBOSS.
I send a simple message to the JBOSS testQueue and the MDB reads that message.
Is there any way to stop the MDB to get the message from the testQueue ?
I already invoke the JMSContainerInvokerMBean for that MDB and also
invoke the stopDelivery();/stop(); method on it.
But it is not working.
when I send the message MDB is reading the message.
Please help me.
Code is listed below.
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,objName,mbeanServer );
| //invoker.stopDelivery();
| invoker.stop();
|
| }catch(Exception ex){
|
| ex.printStackTrace();
| }
| }
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4079580#4079580
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4079580
More information about the jboss-user
mailing list