3 Replies Latest reply on Aug 8, 2004 7:03 AM by ware

    Referencing an EJB from a scheduled task

    jgkenned

      I have written a class that runs on a schedule. I'm using the Schedulable interface. Here's a snippet:

      public class PropertyAutoNotify implements Schedulable
      {
       private static final Logger log = Logger.getLogger(PropertyAutoNotify.class);
      
       private String mail_jndi = null;
       private String ds_jndi = null;
       private String mail_from = null;
      
      
       public PropertyAutoNotify(String mail_jndi, String ds_jndi, String mail_from)
       {
       this.mail_jndi = mail_jndi;
       this.ds_jndi = ds_jndi;
       this.mail_from = mail_from;
       log.info("mail jndi name = " + mail_jndi);
       log.info("datasource jndi name = " + ds_jndi);
       log.info("mail from addr = " + mail_from);
       }
      
       public void perform(Date now, long remainingRepetitions)
       {
       log.info("perform, now: " + now +
       ", remainingRepetitions: " + remainingRepetitions );
      
       //processUserSearch();
       executeAgent();
       }
      
      
       private void executeAgent()
       {
       try
       {



      I'm trying to reference an EJB from this code. It does not make sense to use the ENC because I'm not in a J2EE container. So how do a get a home interface from a scheduled task? I tried this:


      try
       {
       Context initCtx = new InitialContext();
       Object ref = initCtx.lookup("java:/ejb/rwTenantSearch");
       TenantSearchHome home = (TenantSearchHome)
       PortableRemoteObject.narrow(ref, TenantSearchHome.class);
      
       Collection searches = home.findByAutoNotify("Y");
       log.info("number of searches = " + searches.size());
       }
       catch (Exception e)
       {
       log.error("Service Exception", e);
       }


      Didn't work.

      Thanks for any help. Code examples would be good. I don't want to have to clone my business logic in 2 places.