[Design of JMX on JBoss (JBoss/JMX)] - Mbean invoker.stopDelivery() not working
by 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();
}
}
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4080347#4080347
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4080347
17 years, 6 months
[Design of Clustering on JBoss (Clusters/JBoss)] - Re: Transaction Sticky LB policy for 4.2/trunk
by galder.zamarreno@jboss.com
"bstansberry(a)jboss.com" wrote : Good. Take the "don't deploy in AS" thing as just an idea I threw out. That comes from a general feeling I have that unit testing in clustering is inadequate because it's too hard to 1) write complex deployment descriptors that cover all the cases, package them and then deploy them 2) properly check system state when you can only expose that state via JMX or as part of a web or ejb response.
V good point. Testing having to start AS and deploy stuff is quite heavyweight and makes the tests take much longer. I agree with you and so, I'll look into how to resolve this via simpler UTs.
"bstansberry(a)jboss.com" wrote : anonymous wrote : 1.- Rather than implementing 4 brand new policies, it might be easier to add a new element to cluster-config XML called transaction-sticky with true/false values and modify the existing load balance policies to act upon the value of that element, what do you think? This hasn't been fully baked, it's just something that I had in mind.
|
| Hmm. I don't want to reject that idea yet, but I'm concerned about pushing more config stuff into both EJB3 and EJB2. Plus, theoretically these policies can be used outside of EJB, so we'd have to find a way to expose the option wherever they are used.
|
| Also, doing that requires a new field in the LBP impls, which changes their serialization. That will break clients using the old versions, so no good in 4.x and something to avoid in 5.
|
| Also means changing the LBP interface to add a setTransactionSticky(boolean) method.
|
| I know where you're coming from though. The proliferation of classes gets worse when we start talking about doing things properly for Remoting based proxies (e.g. EJB3) vs. the existing detached invoker-based ones. LoadBalancePolicy.chooseTarget (FamilyClusterInfo clusterFamily, Invocation routingDecision) is not meaningful in a Remoting based proxy, because the "org.jboss.invocation.Invocation" class is not used, "org.jboss.aop.joinpoint.Invocation" is. So, handling that doubles the number of classes. :(
|
Serialization change and having to add configuration for EJB3 on top of EJB2 seems two good reasons to create separate load balance policies.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4080302#4080302
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4080302
17 years, 7 months
[Design of JBossCache] - Re: Space versus time, e.g. JBCACHE-1157
by genman
Looking at the JIRA issue discussion, I can sort of see people are missing the point. The point is to save on space and mostly people talk of "time" performance improvements.
Along the lines of "space", there's a couple of changes I would suggest as well:
1. Don't keep the Fqn in the Node. Instead, keep a reference to the parent and only store the name. Build the Fqn when necessary. (Not sure this really saves tons of memory, but...)
2. Consolidate the boolean flags into a byte or short. Use some sort of utility class (with "enum" values) to set/check the bits of the byte/short.
3. Store the key/values/children in flat arrays.
4. Use lock striping, rather than a lock per node.
The problem with all of these, though, it really complicates the hell out of supporting the APIs that expose the data as a Set/Map/etc. And how do you manage concurrency?
What you need is some sort of obsessive/compulsive possibly autistic intern to come in and get this done. :-)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4080199#4080199
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4080199
17 years, 7 months