Delay in starting HASingletonDeployer EJB binding
prashanteb May 11, 2010 6:31 AMHi,
I have written timer using HASingletonDeployer type=Barrier. Below is code for that
@Stateless(name="GenerationEJBTimer") @Depends("jboss.ha:service=HASingletonDeployer,type=Barrier") @LocalBinding(jndiBinding=ISiteRegenerationTimer.EJB_JNDI) @TransactionManagement(TransactionManagementType.BEAN) @Interceptors(SpringBeanAutowiringInterceptor.class) public class GenerationEJBTimer implements IRegenerationTimer { /** * Start the EJB Timer */ public void startTimer() { LOGGER.debug("SiteGenerationEJBTimer : START TIMER"); // Check if any instances of the Timer already exists. If so kill it!!! //timer start code } ...
and Interface is
@Local public interface IRegenerationTimer { public final static String EJB_JNDI = "ejb/local/RegenerationTimer"; public static final String TIMER_NAME = "REGENERATION_TIMER"; public final Long FIVE_MINUTES = 1000L*60L*5L; public void startTimer(); public void stopTimer(); }
and I have written servlet listener which will call GenerationEJBTimer through JNDI lookup.
public class InitializeRegenerationTimer implements ServletContextListener { public void contextInitialized(ServletContextEvent aSce) { LOGGER.info("Initializing InitializeRegenerationTimerContext : START"); try { this.getRegenerationEJBTimer().startTimer(); } catch (NamingException e) { LOGGER.error("ERROR: Unable to locate RegenerationEJBTimer...", e); } LOGGER.info("Initializing InitializeRegenerationTimerContext : STOP"); } private IRegenerationTimer getRegenerationEJBTimer() throws NamingException { InitialContext ctx = new InitialContext(); return (ISiteRegenerationTimer)ctx.lookup(IRegenerationTimer.EJB_JNDI); }
and this will be declared in web.xml as below
<listener> <listener-class>com.web.servlet.InitializeRegenerationTimer</listener-class> </listener>
Now when I deploy this in Jboss 4.2.1.GA cluster server, I am getting javax.naming.NameNotFoundException: ejb not bound at exception even though EJB is deployed before the web app.
when I looked at the logs EJB is starting before web app starts but binding is happening after web app starts. Because of that InitializeRegenerationTimer.getRegenerationEJBTimer() is throwing ejb not bound at exception error.
Please help me how to overcome this problem.
thanks in advance.