SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
MONTREAL JUNE 30, JULY 1ST AND 2ND 2012




COScheduler In Depth
Philippe Rabier - twitter.com/prabier
Sophiacom
Agenda

•   Reminder: what is COScheduler?

•   Job Validation

•   Extend COScheduler: part 1

•   Extend COScheduler: part 2

•   Q&A
Use It!
Reminder
what is COScheduler?
Quartz Job Scheduler

•   Very popular open source java library

•   Exists for a long time (earlier than 2004)

•   Can be used to create simple or complex schedules for
    executing tens, hundreds, or even tens-of-thousands of jobs

•   Quartz 2.1.x is the current release
Quartz Main Components

•   The JobDetails (JobDetail.java)

•   The Triggers (Trigger.java)

•   The Jobs (Job.java)

•   The Scheduler (Scheduler.java)

•   The Job Store (JobStore.java)
COScheduler Overview
COScheduler Goals

•   Hide the (relative) complexity of Quartz

•   Make simple job scheduling very simple to implement

•   EOF integration

•   Based on Project Wonder but with few dependancies (ERJars,
    ERExtensions and ERJavaMail)

•   Based on the “Framework Principal” pattern (mandatory)
    http://wiki.objectstyle.org/confluence/display/WONDER/Creating+a+ERXFrameworkPrincipal+subclass
COScheduler Main Classes
•   COJobDescription
    •Interface that your EOs must implement

•   COSchedulerServiceFrameworkPrincipal
    •Abstract class that you have to subclass.

•   COJob
    •Abstract class that you can use to implement your jobs
COScheduler Main Classes
•   COJobSupervisor
    •Job running periodically which updates the list of jobs handled
     by Quartz

•   COJobListener
    •Send informations when a job is done (emails, log, …)

    •   Update the job description (firstExecutionDate, last and next)
Validation (what is it?)
Subclass COJob

•   The validation methods are:
    • willDelete(final COJobDescription jobDescription)
    • willSave(final COJobDescription jobDescription)
    • validateForDelete(final COJobDescription jobDescription)
    • validateForSave(final COJobDescription jobDescription)
Example of Validation
    Example of a job that executes remote procedures on MySql.

	   public void validateForSave(final COJobDescription jobDescription)
	   {
	   	    // We get the list of remote procedures as a string
	   	    String inputData = ((NOJobDescription)jobDescription).inputData();
	   	    if (ERXStringUtilities.stringIsNullOrEmpty(inputData))
	   	    	    throw new ValidationException("You have to enter at least one stored procedure.");
	   	
	   	    else
	   	    {
	   	    	    NSArray<String> parameters = null;
	   	    	    try
	   	    	    {
	   	    	    	    parameters = ERXValueUtilities.arrayValue(inputData);
	   	    	    } catch (Exception e)
	   	    	    {
	   	    	    	    throw new ValidationException("The data you enter are incorrect.");
	   	    	    }
	   	    	
	   	    	    String sql = "SELECT ROUTINE_NAME FROM `information_schema`.`ROUTINES` where specific_name = ";
	   	    	    EOEditingContext ec = ERXEC.newEditingContext();
	   	    	    for (String aStoredProcedure : parameters)
	   	    	    {
	   	    	    	    NSArray<NSDictionary<String, String>> objects = EOUtilities.rawRowsForSQL(ec, "NOBusiness", sql + "'" + aStoredProcedure + "'", null);
	   	    	    	    if (log.isDebugEnabled())
	   	    	    	    	    log.debug("method: validateForSave: aStoredProcedure: " + aStoredProcedure +" has been checked: " + (objects.count() > 0));
	   	    	    	    if (objects.count() == 0)
	   	    	    	    	    throw new ValidationException("The stored procedure: " + aStoredProcedure + " doesn't exist.");
	   	    	    }
	   	    }
	   }
EO modification

•   Modify the following methods
    •willDelete
    •willUpdate
    •willInsert
    •validateForDelete
    •validateForSave
Example of Validation
    Example: modify the validateForSave method.

	   public void validateForSave()
	   {
	   	    super.validateForSave();
	   	    try
	   	    {
	   	    	    COUtilities.validateForSave(this);
	   	    } catch (COJobInstanciationException e)
	   	    {
	   	    	    if (e.getErrorType() == ErrorType.CLASS_NOT_FOUND)
	   	    	    	    throw new NSValidation.ValidationException("The class " + this.classPath() + " doesn't exist.");
	   	    	    else
	   	    	    	    throw new NSValidation.ValidationException("There is an error when trying to run " + this.classPath() + ".");
	   	    }

    }

    Code of COUtilities.validateForSave

	   public static Job validateForSave(final COJobDescription jobDescription) throws COJobInstanciationException
	   {
	   	    Job aJob = createJobInstance(jobDescription);
	   	    if (aJob instanceof COJob)
	   	    	    ((COJob)aJob).validateForSave(jobDescription);
	   	    return aJob;
	   }
Extend COScheduler: part 1
Problem To Solve

  Be warned when a job
execution time is too long.
The solution
•   Add an attribute maxDuration in our entity
•   Create our own job listener by subclassing COJobListener
    • add a method isJobExecutionTooLong
    • override the methods:
        •
        getMailSubject
        •
        getMailContent
        •
        recipients (to force to send an email to the client)
Code of job listener
    	

    private boolean isJobExecutionTooLong(final JobExecutionContext jobexecutioncontext)
	   {
	   	   if (jobexecutioncontext.getMergedJobDataMap().containsKey(JOB_TOO_LONG_KEY))
	   	   	    return jobexecutioncontext.getMergedJobDataMap().getBoolean(JOB_TOO_LONG_KEY);

	   	   boolean status = false;
	   	   EOEditingContext ec = editingContext();
	   	   ec.lock();
	   	   try
	   	   {
	   	   	    NOJobDescription aJobDescription = (NOJobDescription) getJobDescription(jobexecutioncontext, editingContext());
	   	   	    if (aJobDescription.maxDuration() != null)
	   	   	    {
	   	   	    	    // get the duration in minutes.
	   	   	    	    long duration = jobexecutioncontext.getJobRunTime()/(1000*60);
	   	   	    	    if (duration > aJobDescription.maxDuration())
	   	   	    	    	    status = true;
	   	   	    }
	   	   } catch (Exception e)
	   	   {
	   	   	    log.error("method: jobWasExecuted: exception when saving job description: ", e);
	   	   } finally
	   	   {
	   	   	    ec.unlock();
	   	   }
	   	   jobexecutioncontext.getMergedJobDataMap().put(JOB_TOO_LONG_KEY, status);
	   	   return status;
	   }
Code of job listener



	   public void jobToBeExecuted(final JobExecutionContext jobexecutioncontext)
	   {
	   	    super.jobToBeExecuted(jobexecutioncontext);
	   	    if (jobexecutioncontext.getMergedJobDataMap().containsKey(JOB_TOO_LONG_KEY))
	   	    	    jobexecutioncontext.getMergedJobDataMap().remove(JOB_TOO_LONG_KEY);
	   }




    protected String getMailSubject(final JobExecutionContext jobexecutioncontext)
	   {
	   	    if (isJobExecutionTooLong(jobexecutioncontext))
	   	    {
	   	    	    NOJobDescription aJobDescription = (NOJobDescription) getJobDescription(jobexecutioncontext, editingContext());
	   	    	    return "ERROR: the expected max duration is: " + aJobDescription.maxDuration() + ". " + super.getMailSubject(jobexecutioncontext);
	   	    }
	   	    return super.getMailSubject(jobexecutioncontext);
	   }
Extend COScheduler: part II
Problem To Solve

Prevent a job to be executed
      after some time
Problem To Solve
         Case 1   Case 2   Case 2
8:00




10:00




12:00




14:00




16:00




18:00
The solution

•   Add an attribute maxExecutionTime in our entity
•   Create a trigger listener by subclassing COAbstractListener and
    implementing TriggerListener
    • only 2 methods need some works: getName and
      vetoJobExecution
        •
        getName (just return a name like this.getClass().getName()
        •
        vetoJobExecution (see code next slide)
Code of job listener


	   public boolean vetoJobExecution(final Trigger trigger, final JobExecutionContext context)
	   {
	   	    EOEditingContext ec = editingContext();
	   	    ec.lock();
	   	    try
	   	    {

	   	   	    NOJobDescription jd = (NOJobDescription) getJobDescription(context, ec);
	   	   	    if (jd != null && !ERXStringUtilities.stringIsNullOrEmpty(jd.maxExecutionTime()))
	   	   	    {
	   	   	    	    DateTime maxExecutionTime = NOJobDescription.hourAndSecondFormatter.parseDateTime(jd.maxExecutionTime());
	   	   	    	    LocalTime maxExecutionLocalTime = maxExecutionTime.toLocalTime();
	   	   	    	    LocalTime currentLocalTime = new DateTime().toLocalTime();
	   	   	    	    boolean tooLate = currentLocalTime.compareTo(maxExecutionLocalTime) > 0;
	   	   	    	    return tooLate;
	   	   	    }
	   	   } catch (Exception e)
	   	   {
	   	   	    log.error("method: vetoJobExecution: exception when getting the job description: ", e);
	   	   } finally
	   	   {
	   	   	    ec.unlock();
	   	   }
	   	   return false;
	   }
Code of job listener
      Modify your FrameworkPrincipal class and add the method finishInitialization()

@COMyJobListener("fr.sophiacom.ynp.schedulerservice.foundation.NSJobListener")
public class NSSchedulerServiceFrameworkPrincipal extends COSchedulerServiceFrameworkPrincipal
{
	    static
	    {
	    	    log.debug("NSSchedulerServiceFrameworkPrincipal: static: ENTERED");
	    	    setUpFrameworkPrincipalClass(NSSchedulerServiceFrameworkPrincipal.class);
	    	    log.debug("NSSchedulerServiceFrameworkPrincipal: static: DONE");
	    }

...

	     public void finishInitialization()
	     {
	     	    super.finishInitialization();
	     	    if (schedulerMustRun())
	     	    {
	     	    	    try
	     	    	    {
	     	    	    	    // We add the trigger listener
	     	    	    	    TriggerListener tl = new NSTriggerListener(this);
	     	    	    	    getScheduler().getListenerManager().addTriggerListener(tl);
	     	    	    } catch (SchedulerException e)
	     	    	    {
	     	    	    	    log.error("method: finishInitialization: unable to add the trigger listener.", e);
	     	    	    }
	     	    }
	     }
}
MONTREAL JUNE 30, JULY 1ST AND 2ND 2012




Q&A

Contenu connexe

Tendances

Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...julien.ponge
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 SpringKiyotaka Oku
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84Mahmoud Samir Fayed
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」matuura_core
 
Smarter Testing with Spock
Smarter Testing with SpockSmarter Testing with Spock
Smarter Testing with SpockDmitry Voloshko
 
The Ring programming language version 1.8 book - Part 74 of 202
The Ring programming language version 1.8 book - Part 74 of 202The Ring programming language version 1.8 book - Part 74 of 202
The Ring programming language version 1.8 book - Part 74 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196Mahmoud Samir Fayed
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legione-Legion
 

Tendances (20)

Java 7 LavaJUG
Java 7 LavaJUGJava 7 LavaJUG
Java 7 LavaJUG
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
Server1
Server1Server1
Server1
 
The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196
 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
 
Smarter Testing with Spock
Smarter Testing with SpockSmarter Testing with Spock
Smarter Testing with Spock
 
The Ring programming language version 1.8 book - Part 74 of 202
The Ring programming language version 1.8 book - Part 74 of 202The Ring programming language version 1.8 book - Part 74 of 202
The Ring programming language version 1.8 book - Part 74 of 202
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202
 
The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196
 
The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180
 
JDK Power Tools
JDK Power ToolsJDK Power Tools
JDK Power Tools
 
The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
 
Testing (eng)
Testing (eng)Testing (eng)
Testing (eng)
 

Similaire à COScheduler In Depth

Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3Simon Su
 
NetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience ReportNetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience ReportAnton Arhipov
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScriptkvangork
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascriptkvangork
 
Test-driven Development with AEM
Test-driven Development with AEMTest-driven Development with AEM
Test-driven Development with AEMJan Wloka
 
Build Widgets
Build WidgetsBuild Widgets
Build Widgetsscottw
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql JOYITAKUNDU1
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++nsm.nikhil
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent codeDror Helper
 
Repetition is bad, repetition is bad.
Repetition is bad, repetition is bad.Repetition is bad, repetition is bad.
Repetition is bad, repetition is bad.wellD
 
Repetition is bad, repetition is bad.
Repetition is bad, repetition is bad.Repetition is bad, repetition is bad.
Repetition is bad, repetition is bad.Michele Giacobazzi
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42Yevhen Bobrov
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴명신 김
 
AutoTest Refactoring. Архитектурные семинары Softengi
AutoTest Refactoring. Архитектурные семинары SoftengiAutoTest Refactoring. Архитектурные семинары Softengi
AutoTest Refactoring. Архитектурные семинары SoftengiSoftengi
 
Code refactoring of existing AutoTest to PageObject pattern
Code refactoring of existing AutoTest to PageObject patternCode refactoring of existing AutoTest to PageObject pattern
Code refactoring of existing AutoTest to PageObject patternAnton Bogdan
 

Similaire à COScheduler In Depth (20)

COScheduler
COSchedulerCOScheduler
COScheduler
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3
 
NetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience ReportNetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience Report
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 
Test-driven Development with AEM
Test-driven Development with AEMTest-driven Development with AEM
Test-driven Development with AEM
 
Build Widgets
Build WidgetsBuild Widgets
Build Widgets
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent code
 
Repetition is bad, repetition is bad.
Repetition is bad, repetition is bad.Repetition is bad, repetition is bad.
Repetition is bad, repetition is bad.
 
Repetition is bad, repetition is bad.
Repetition is bad, repetition is bad.Repetition is bad, repetition is bad.
Repetition is bad, repetition is bad.
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
 
AutoTest Refactoring. Архитектурные семинары Softengi
AutoTest Refactoring. Архитектурные семинары SoftengiAutoTest Refactoring. Архитектурные семинары Softengi
AutoTest Refactoring. Архитектурные семинары Softengi
 
Code refactoring of existing AutoTest to PageObject pattern
Code refactoring of existing AutoTest to PageObject patternCode refactoring of existing AutoTest to PageObject pattern
Code refactoring of existing AutoTest to PageObject pattern
 

Plus de WO Community

In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engineWO Community
 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsWO Community
 
Build and deployment
Build and deploymentBuild and deployment
Build and deploymentWO Community
 
Reenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSReenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSWO Community
 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldWO Community
 
D2W Stateful Controllers
D2W Stateful ControllersD2W Stateful Controllers
D2W Stateful ControllersWO Community
 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on WindowsWO Community
 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnitWO Community
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache CayenneWO Community
 
Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to WonderWO Community
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative versionWO Community
 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" patternWO Community
 
Filtering data with D2W
Filtering data with D2W Filtering data with D2W
Filtering data with D2W WO Community
 
Localizing your apps for multibyte languages
Localizing your apps for multibyte languagesLocalizing your apps for multibyte languages
Localizing your apps for multibyte languagesWO Community
 

Plus de WO Community (20)

KAAccessControl
KAAccessControlKAAccessControl
KAAccessControl
 
In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engine
 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systems
 
Build and deployment
Build and deploymentBuild and deployment
Build and deployment
 
High availability
High availabilityHigh availability
High availability
 
Reenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSReenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWS
 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real World
 
D2W Stateful Controllers
D2W Stateful ControllersD2W Stateful Controllers
D2W Stateful Controllers
 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on Windows
 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnit
 
Life outside WO
Life outside WOLife outside WO
Life outside WO
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache Cayenne
 
Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to Wonder
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
 
iOS for ERREST
iOS for ERRESTiOS for ERREST
iOS for ERREST
 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" pattern
 
Filtering data with D2W
Filtering data with D2W Filtering data with D2W
Filtering data with D2W
 
WOver
WOverWOver
WOver
 
Localizing your apps for multibyte languages
Localizing your apps for multibyte languagesLocalizing your apps for multibyte languages
Localizing your apps for multibyte languages
 

Dernier

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Dernier (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

COScheduler In Depth

  • 1. MONTREAL JUNE 30, JULY 1ST AND 2ND 2012 COScheduler In Depth Philippe Rabier - twitter.com/prabier Sophiacom
  • 2. Agenda • Reminder: what is COScheduler? • Job Validation • Extend COScheduler: part 1 • Extend COScheduler: part 2 • Q&A
  • 5. Quartz Job Scheduler • Very popular open source java library • Exists for a long time (earlier than 2004) • Can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs • Quartz 2.1.x is the current release
  • 6. Quartz Main Components • The JobDetails (JobDetail.java) • The Triggers (Trigger.java) • The Jobs (Job.java) • The Scheduler (Scheduler.java) • The Job Store (JobStore.java)
  • 8. COScheduler Goals • Hide the (relative) complexity of Quartz • Make simple job scheduling very simple to implement • EOF integration • Based on Project Wonder but with few dependancies (ERJars, ERExtensions and ERJavaMail) • Based on the “Framework Principal” pattern (mandatory) http://wiki.objectstyle.org/confluence/display/WONDER/Creating+a+ERXFrameworkPrincipal+subclass
  • 9. COScheduler Main Classes • COJobDescription •Interface that your EOs must implement • COSchedulerServiceFrameworkPrincipal •Abstract class that you have to subclass. • COJob •Abstract class that you can use to implement your jobs
  • 10. COScheduler Main Classes • COJobSupervisor •Job running periodically which updates the list of jobs handled by Quartz • COJobListener •Send informations when a job is done (emails, log, …) • Update the job description (firstExecutionDate, last and next)
  • 12. Subclass COJob • The validation methods are: • willDelete(final COJobDescription jobDescription) • willSave(final COJobDescription jobDescription) • validateForDelete(final COJobDescription jobDescription) • validateForSave(final COJobDescription jobDescription)
  • 13. Example of Validation Example of a job that executes remote procedures on MySql. public void validateForSave(final COJobDescription jobDescription) { // We get the list of remote procedures as a string String inputData = ((NOJobDescription)jobDescription).inputData(); if (ERXStringUtilities.stringIsNullOrEmpty(inputData)) throw new ValidationException("You have to enter at least one stored procedure."); else { NSArray<String> parameters = null; try { parameters = ERXValueUtilities.arrayValue(inputData); } catch (Exception e) { throw new ValidationException("The data you enter are incorrect."); } String sql = "SELECT ROUTINE_NAME FROM `information_schema`.`ROUTINES` where specific_name = "; EOEditingContext ec = ERXEC.newEditingContext(); for (String aStoredProcedure : parameters) { NSArray<NSDictionary<String, String>> objects = EOUtilities.rawRowsForSQL(ec, "NOBusiness", sql + "'" + aStoredProcedure + "'", null); if (log.isDebugEnabled()) log.debug("method: validateForSave: aStoredProcedure: " + aStoredProcedure +" has been checked: " + (objects.count() > 0)); if (objects.count() == 0) throw new ValidationException("The stored procedure: " + aStoredProcedure + " doesn't exist."); } } }
  • 14. EO modification • Modify the following methods •willDelete •willUpdate •willInsert •validateForDelete •validateForSave
  • 15. Example of Validation Example: modify the validateForSave method. public void validateForSave() { super.validateForSave(); try { COUtilities.validateForSave(this); } catch (COJobInstanciationException e) { if (e.getErrorType() == ErrorType.CLASS_NOT_FOUND) throw new NSValidation.ValidationException("The class " + this.classPath() + " doesn't exist."); else throw new NSValidation.ValidationException("There is an error when trying to run " + this.classPath() + "."); } } Code of COUtilities.validateForSave public static Job validateForSave(final COJobDescription jobDescription) throws COJobInstanciationException { Job aJob = createJobInstance(jobDescription); if (aJob instanceof COJob) ((COJob)aJob).validateForSave(jobDescription); return aJob; }
  • 17. Problem To Solve Be warned when a job execution time is too long.
  • 18. The solution • Add an attribute maxDuration in our entity • Create our own job listener by subclassing COJobListener • add a method isJobExecutionTooLong • override the methods: • getMailSubject • getMailContent • recipients (to force to send an email to the client)
  • 19. Code of job listener private boolean isJobExecutionTooLong(final JobExecutionContext jobexecutioncontext) { if (jobexecutioncontext.getMergedJobDataMap().containsKey(JOB_TOO_LONG_KEY)) return jobexecutioncontext.getMergedJobDataMap().getBoolean(JOB_TOO_LONG_KEY); boolean status = false; EOEditingContext ec = editingContext(); ec.lock(); try { NOJobDescription aJobDescription = (NOJobDescription) getJobDescription(jobexecutioncontext, editingContext()); if (aJobDescription.maxDuration() != null) { // get the duration in minutes. long duration = jobexecutioncontext.getJobRunTime()/(1000*60); if (duration > aJobDescription.maxDuration()) status = true; } } catch (Exception e) { log.error("method: jobWasExecuted: exception when saving job description: ", e); } finally { ec.unlock(); } jobexecutioncontext.getMergedJobDataMap().put(JOB_TOO_LONG_KEY, status); return status; }
  • 20. Code of job listener public void jobToBeExecuted(final JobExecutionContext jobexecutioncontext) { super.jobToBeExecuted(jobexecutioncontext); if (jobexecutioncontext.getMergedJobDataMap().containsKey(JOB_TOO_LONG_KEY)) jobexecutioncontext.getMergedJobDataMap().remove(JOB_TOO_LONG_KEY); } protected String getMailSubject(final JobExecutionContext jobexecutioncontext) { if (isJobExecutionTooLong(jobexecutioncontext)) { NOJobDescription aJobDescription = (NOJobDescription) getJobDescription(jobexecutioncontext, editingContext()); return "ERROR: the expected max duration is: " + aJobDescription.maxDuration() + ". " + super.getMailSubject(jobexecutioncontext); } return super.getMailSubject(jobexecutioncontext); }
  • 22. Problem To Solve Prevent a job to be executed after some time
  • 23. Problem To Solve Case 1 Case 2 Case 2 8:00 10:00 12:00 14:00 16:00 18:00
  • 24. The solution • Add an attribute maxExecutionTime in our entity • Create a trigger listener by subclassing COAbstractListener and implementing TriggerListener • only 2 methods need some works: getName and vetoJobExecution • getName (just return a name like this.getClass().getName() • vetoJobExecution (see code next slide)
  • 25. Code of job listener public boolean vetoJobExecution(final Trigger trigger, final JobExecutionContext context) { EOEditingContext ec = editingContext(); ec.lock(); try { NOJobDescription jd = (NOJobDescription) getJobDescription(context, ec); if (jd != null && !ERXStringUtilities.stringIsNullOrEmpty(jd.maxExecutionTime())) { DateTime maxExecutionTime = NOJobDescription.hourAndSecondFormatter.parseDateTime(jd.maxExecutionTime()); LocalTime maxExecutionLocalTime = maxExecutionTime.toLocalTime(); LocalTime currentLocalTime = new DateTime().toLocalTime(); boolean tooLate = currentLocalTime.compareTo(maxExecutionLocalTime) > 0; return tooLate; } } catch (Exception e) { log.error("method: vetoJobExecution: exception when getting the job description: ", e); } finally { ec.unlock(); } return false; }
  • 26. Code of job listener Modify your FrameworkPrincipal class and add the method finishInitialization() @COMyJobListener("fr.sophiacom.ynp.schedulerservice.foundation.NSJobListener") public class NSSchedulerServiceFrameworkPrincipal extends COSchedulerServiceFrameworkPrincipal { static { log.debug("NSSchedulerServiceFrameworkPrincipal: static: ENTERED"); setUpFrameworkPrincipalClass(NSSchedulerServiceFrameworkPrincipal.class); log.debug("NSSchedulerServiceFrameworkPrincipal: static: DONE"); } ... public void finishInitialization() { super.finishInitialization(); if (schedulerMustRun()) { try { // We add the trigger listener TriggerListener tl = new NSTriggerListener(this); getScheduler().getListenerManager().addTriggerListener(tl); } catch (SchedulerException e) { log.error("method: finishInitialization: unable to add the trigger listener.", e); } } } }
  • 27. MONTREAL JUNE 30, JULY 1ST AND 2ND 2012 Q&A