1 Reply Latest reply on Oct 20, 2009 6:10 PM by Brian Stansberry

    Lifecycle methods with HASingletonDeployer

    Mattias Andersson Newbie

      I'm sorry if this is a common noob question, but I can't find a solution reading FAQs and the wiki.

      What I'm trying to do is writing a bean that should do some work when a new master gets elected. I've read that the recomended way is to use a MDB with dependency on 'jboss.ha:service=HASingletonDeployer,type=Barrier', and then do the work in the start lifecycle method.
      I guess I have to register a listener on the lifecycle phase or something since I don't get any calls to my start() method, but I don't know how to do that.
      The version I'm using is 4.2.2.GA.

      This is my tiny test bean:

      import javax.ejb.ActivationConfigProperty;
      import javax.ejb.MessageDriven;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import org.jboss.annotation.ejb.Depends;
      @MessageDriven(name = "DummyMDBean", activationConfig = {
       @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
       @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue"),
       @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
      public class DummyMDBean implements MessageListener {
       public void start() throws Exception {
       System.out.println("=== START ===");
       public void onMessage(Message message) {
       System.out.println("message = " + message);
       public DummyMDBean() {
       System.out.println("=== CREATE ===");

      I have also tried using a Service bean without any luck.
      If the bean recieves a message DummyMDBean() and onMessage() gets called, but start() never gets called.

      The bean are stopped/started correct on all slaves and master, it's just the start() I can't get to work.

      Does anyone know of an alternative way to do the tasks when going from slave to master?