SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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)
 

Semelhante a 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
 

Semelhante a 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
 

Mais 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
 

Mais 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
 

Último

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Último (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

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