5 Replies Latest reply on Jun 19, 2006 12:50 PM by Alex Pardi

    Jndi context in calls from Scheduler

    Alex Pardi Newbie

      Hi,

      I'm working with JBoss 4.0.4.GA. I have an ear that contains a jar and a sar. The jar contains an ejb (SLSB) and the classes it needs, while the sar only content is a jboss-service.xml that defines a Scheduler, so that when the scheduler is deployed JBoss already knows about the class to call (which is in the same jar as the ejb).
      So far so good. I deploy everything successfully, but when the scheduler calls my class, and my class tries to lookup the ejb home in the jndi context, I get a "javax.naming.NameNotFoundException: env not bound".
      What looks weird to me is that as soon as I make an external call to that same ejb, which happens to be also exposed as a web service, the jndi context becomes valid, and the next round from the scheduler (and all the ones thereafter) succeed. Note that this is not time dependent: I can get the exception for hours, the lookup only succeeds after the first access to the ejb.
      Is this is normal behavior? Does anyone know a way around this?

      The jboss-service.xml inside the sar:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE server>
      
      <server>
       <mbean code="javax.management.timer.Timer" name=":service=IGPTimer" />
      
       <mbean code="org.jboss.varia.scheduler.Scheduler"
       name=":service=TokenCleanupScheduler">
       <attribute name="StartAtStartup">true</attribute>
       <attribute name="SchedulableClass">
       it.igp.ejb.jobs.TokenCleanupJob
       </attribute>
       <attribute name="SchedulableArguments"></attribute>
       <attribute name="SchedulableArgumentTypes"></attribute>
       <attribute name="InitialStartDate">NOW</attribute>
       <!-- Run every 10 minutes -->
       <attribute name="SchedulePeriod">600000</attribute>
       <attribute name="InitialRepetitions">-1</attribute>
       </mbean>
      </server>
      


      Thanks in advance,
      Alessandro

        • 1. Re: Jndi context in calls from Scheduler
          Alex Pardi Newbie

          Oops, things were quite not the way I first described them: it looks like the Schedulable class that is invoked has never a way to retrieve the ejb home, except that these Homes are cached (the lookup took place in a helper class), so that later retries didn't need to lookup the jndi context, but found the ejb Home in the cache.
          Sorry for the mis-post.
          The question can now be changed into: is there a way for the Schedulable class to access the jndi context where the ejbs are bound?
          This what the "java:/" context in the Schedulable class contains:

          - jaas (instance of javax.naming.Context)
          - TransactionPropagationContextImporter (instance of org.jboss.tm.TransactionPropagationContextImporter)
          - JmsXA (instance of org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
          - JBossCorbaNaming (instance of org.omg.CosNaming.NamingContextExt)
          - DefaultDS (instance of org.jboss.resource.adapter.jdbc.WrapperDataSource)
          - StdJMSPool (instance of org.jboss.jms.asf.StdServerSessionPoolFactory)
          - TransactionManager (instance of org.jboss.tm.TxManager)
          - JBossCorbaPOA (instance of org.omg.PortableServer.POA)
          - TransactionPropagationContextExporter (instance of org.jboss.tm.TransactionPropagationContextFactory)
          - ConnectionFactory (instance of org.jboss.mq.SpyConnectionFactory)
          - jdbc (instance of org.jnp.interfaces.NamingContext)
          - DefaultJMSProvider (instance of org.jboss.jms.jndi.JNDIProviderAdapter)
          - XAConnectionFactory (instance of org.jboss.mq.SpyXAConnectionFactory)
          - JBossCorbaInterfaceRepositoryPOA (instance of org.omg.PortableServer.POA)
          - Mail (instance of javax.mail.Session)
          - JBossCorbaORB (instance of org.omg.CORBA.ORB)
          - timedCacheFactory (instance of javax.naming.Context)
          - SecurityProxyFactory (instance of org.jboss.security.SubjectSecurityProxyFactory)
          - comp (instance of javax.naming.Context)


          • 2. Re: Jndi context in calls from Scheduler
            jaikiran pai Master

            The real problem here is that the code in the Scheduler class (which is a MBean) is executed even before the EJB is bound to the jndi name. This can be solved by having a dependency attribute on the MBean. Have a look at the following link, for the same:

            http://wiki.jboss.org/wiki/Wiki.jsp?page=HowCanAnMBeanDependOnASessionBean

            • 3. Re: Jndi context in calls from Scheduler
              Alex Pardi Newbie

              Thanks for your reply. I tried what you suggest, messages in the log file seem to confirm that everything went right, but the lookup still fails.
              In the log I saw a service which seems strictly related to the jndi binding:

              jboss.j2ee:jndiName=env/comp/GameInterface,service=EJB

              I tried also to add a dependency on this, JBoss didn't complain, duly logged that the dependency was there, but the scheduled class still can't see anything...

              • 4. Re: Jndi context in calls from Scheduler
                Alex Pardi Newbie

                Couldn't simply this be the key?

                The NamingService also creates the java:comp context such that access to this context is isolated based on the context ClassLoader of the thread that accesses the java:comp context.


                • 5. Re: Jndi context in calls from Scheduler
                  Alex Pardi Newbie

                  Problem solved: I tried to look it up in the java:/comp context rather than in the global context (env/comp).
                  Sorry for wasting the time of those who read, hope this may help others...