Tuesday, October 8, 2013

Integrate Quartz with ADF

In this blog entry, I will explain how to use Quartz to execute Background Jobs, where Jobs will eventually execute ADF Application Module methods.

I will be using JDBC Store for Quartz, which will allow me to execute jobs in Cluster environment. In addition, I have also included a Job Listener that will update job execution status in database table, which will help integrate with External Scheduler systems. Many companies have Enterprise Schedulers that control Jobs across various systems. Most of the time, these Enterprise Schedulers would call Shell scripts, and even if they can invoke Web Services, it is better to setup Asynchronous execution to avoid time outs. This approach will also be useful if you don't have an Enterprise Scheduler, in which case Quartz can act as your master scheduler.

1. Install Quart Libraries (1.6.4) in JDeveloper
  • Download - "myextensionsV2.zip".
  • Unzip downloaded myextensionsV2.zip in c:\temp.
  • Using command prompt, go to c:\temp\myextensions.
  • First set JDEVELOPER11_INSTALL_HOME environment variable, which should point to your JDeveloper installation. For example, set JDEVELOPER11_INSTALL_HOME=c:\jdeveloper
  • You can now run setup.bat file to install Jersey Library in your JDeveloper installation.

2. Create Scheduler tables
  • Download quartz-base.sql and quartz-myextension.sql.
  • Create SCHEDULER user using welcome1 password.
  • Create Database Objects using quartz-base.sql and quartz-myextension.sql.
  • This will create necessary tables for Quartz and my extension table for Job Listener.
3. Run JDeveloper Application
  • Download - Example3.zip
  • Unzip Example3.zip and Open using JDeveloper (11.1.1.7.0)
  • Perform Make All using Build menu.
  • Run MyDummyServlet. This is just to start Embedded WebLogic Server.
  • As Server starts, it will also start Quartz Scheduler, which is configured by QuartzInitializerServlet in web.xml.
  • When application and scheduler is started, you will see a new row in SCHEDULER.MY_SCHEDULER_STATE table.
  • Run ExecuteJob.java. This will schedule a Job in database, which will be picked up by running Quartz Scheduler in Embedded WebLogic Server.
  • You will notice output message in console.
  • While job is running, monitor SCHEDULER.MY_JOB_LISTENER table, you will notice State column value will change as Job State changes from Executing to Complete.
4. Next Steps
  • You can create proper implementation of ExecuteJob.java. For example, 
    • supply Input parameters to Job, using JobDataMap.
    • Poll MY_JOB_LISTENER for Status of Job - complete or error.
    • Create Shell script wrapper, which can be executed by External Scheduler.
  • You can create generic implementation of AMInvokeJob, that can take Application Module Definition and Operation Name as input, to invoke any Application Module's method.

11 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hello Chandersh, thank you for this good post. But I cannot get any downloads via links. Can you check and help me please?

    Regards,
    Devrim

    ReplyDelete
  3. I don't have the files and this post just has high level guidelines. But if you have any specific questions, i will be happy to answer.

    ReplyDelete
  4. Hello Chandersh, actually I meant the files like 'Download - "myextensionsV2.zip"' and some other files at 1., 2. and 3. items. I would like to use your quartz integration solution but I am not a java developer I just use jdeveloper with essential java knowledge. I am using Glassfish with ADF essentials libraries as app server and deploy adf apps there. Is it possible to use quartz with apps on Glassfish server? Is there any dependecy with Weblogic libraries?

    Best regards,
    Devrim

    ReplyDelete
  5. P.S. I am using Jdeveloper 12.1.3.0.0 and Glassfish Open Source Edition 3.1.2 (Build 23)

    ReplyDelete
  6. Hello Chandresh, I realised that I misspelled your name, so sory... :(

    ReplyDelete
  7. You would need to do this in Java as Quartz requires you to create job implementation in java, there are some out of the box job classes but they would only be useful in specific scenarios.

    And yes, you can use quartz with ADF essentials and glassfish.

    1. You can download quartz jar files from. http://quartz-scheduler.org/downloads. Just put it in your application's WEB-INF/lib folder and reference it on your jdeveloper view controller project using Libraries and Classpath.
    2. start scheduler in your application using this example - http://quartz-scheduler.org/documentation/quartz-2.2.x/cookbook/ServletInitScheduler
    3. If you need Clustered environment, then you will need to create tables for quartz, otherwise simple properties file based configuration should be fine.

    Reference - http://quartz-scheduler.org/documentation/quartz-2.2.x/tutorials/

    ReplyDelete
    Replies
    1. Hello Chandresh,

      It would be very helpful! Thank you for quick response and help :)
      May I ask again if I needed?

      Best wishes,
      Devrim

      Delete
  8. Replies
    1. Thank you again... One more request if you like : Do you have any working sample adf app which perodically run via quartz and insert a row in a table on a remote database? This is what exactly I intend to make :)

      Best
      Devrim

      Delete
  9. Hello, thanks for this wonderful article. Is there anyway that you can share the code for the links provided? The links does not seem to work now. Thank you.

    ReplyDelete