File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JBoss/WildFly and the fly likes Singleton MDB in a clustered environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Singleton MDB in a clustered environment" Watch "Singleton MDB in a clustered environment" New topic
Author

Singleton MDB in a clustered environment

Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
So I want a singleton MDB on my clustered app server. I thought that I could just deploy my MDB (in a jar or ear) to the deploy-hasingleton directory and I would essentially limit access to this bean to one. But it looks like jboss is trying to deploy my MDB before it deploys all the JMS stuff (I get a DefaultJMSProvider nnot found exception).

Has anyone created a singleton MDB before?

Thanks in advance.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Maybe it is starting up JMS on one server. (It is a Singleton too), and trying to deploy the MDB on a different server.

What happens if you try to deploy your MDB into the deploy directory of just one of the nodes and not in the farm directory. Then it is literally deployed in one machine, and will be in the local JNDI tree. And in Clustering with HA-JNDI, then any machine can still find the MDB from that one machine.

Now the other big question is why you need the MDB to be deployed on only one machine. Can't think of a good use case why I would need that.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
I am not sure what you are proposing. If I only deploy to the deploy directory on one machine, if that machine goes down then I am in trouble. I want it to failover to another node in the cluster. That is what the deploy-hasingleton is for. According to the documentation it will deploy to the master only and if the master goes down it will deploy to whatever machine takes over as the master. The jboss documentation says you can put ears, wars, jars, etc in there if you want a singleton.

This also happens when I only have one server up. deploy-hasingleton is not hot deploy so you need to bring the cluster down. When I try and bring up the first machine (the master) jboss tries to deploy my MDB before jms is deployed. This should not happen.

Why do I want this? Seems the same reason everyone else wants this as well, for processing message driven beans one at a time in order. In my case I only care about one at a time as I am writing to a lucene index. This solution is actually recommend by lucene for writing and index in a clustered env.

I see a ton of posts about people wanting to use the deploy-hasingleton and having problems but no one seems to have any answers. Any ideas would be greatly appreciated.

Thanks again.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9932
    
159

I guess you have read this?

When I try and bring up the first machine (the master) jboss tries to deploy my MDB before jms is deployed.


This is then a dependency issue. You can add a "depends" to the MDB to add an dependency on the JMS topic/queue. The depends can either be added as a annotation (for EJB3) or in the jboss.xml (for EJB2.x as well as EJB3).

[My Blog] [JavaRanch Journal]
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114

You can add a "depends" to the MDB to add an dependency on the JMS topic/queue.


To clarify it looks like the problem is that jms as a whole is not up when my MDB tries to deploy. But you are saying to add a dependency on the queue my MDB uses??? If so I am not really sure how this might help. Also not sure how to depend on my queue.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9932
    
159

Billy Newman wrote:

To clarify it looks like the problem is that jms as a whole is not up when my MDB tries to deploy.


Can you please post the console logs and the entire exception stacktrace along with any relevant MDB configurations?
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
I will post the code shortly. As an aside you should be able to reproduce this by creating an ear with a simple MDB in it. Deploy that ear to deploy-hasingleton, and you will see that you MDB is deployed before jms is finished. If you can get that simple test to work that would be great because I cannot!

Also I have read that instead of deploying to deploy-hasingleton to get a singleton I can annotate with:


I guess this might save the trouble of creating an ear with just the MDB in it that you want as a singleton, and you can just deploy an ear with a bunch of stuff in it including your MDB in the farm directory. Bummer is that I cannot get this to work either.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
I see a ton of posts about people wanting to use the deploy-hasingleton and having problems but no one seems to have any answers. Any ideas would be greatly appreciated.


Basically, anything remotely related to Singleton is crappy and will not work. The answer is not to depend upon a Singleton for anything. Singletons are only good for cleaning the toliets and sweeping up after everyone has gone home for the day )
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
The exception I get is (I cannot get the exception from the server so the best I can do is type in the exception without the stack trace):
javax.naming.NameNotFoundException: DefaultJMSProvider not bound


Simple MDB:


Queue:

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Check out the server log file and you should see the exception, if one was thrown.

Really the odd thing is that the default deployment sorter would deploy the jms.sar service archive before any ear, war or jar. So it is very strange that the MDB is being deployed first, when they are both in the HA-SINGLETON directory.

Mark
Mark Evans
Greenhorn

Joined: Apr 02, 2010
Posts: 1
Bobby Anderson wrote:The exception I get is (I cannot get the exception from the server so the best I can do is type in the exception without the stack trace):
javax.naming.NameNotFoundException: DefaultJMSProvider not bound


Simple MDB:


Queue:



Hey Bobby, did you resolve your issue? I have the same issue and would appreciate any pointers to resolve the issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Singleton MDB in a clustered environment
 
Similar Threads
If singletons are bad, how does a factory help?
JMS in Clusterd Weblogic
How to sync the java object in clustered weblogic?
Singletons with Clustering
A question about clustering and jms