DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Playwright JavaScript Tutorial: A Complete Guide
  • Building A Log Analytics Solution 10 Times More Cost-Effective Than Elasticsearch
  • Front-End: Cache Strategies You Should Know
  • The SPACE Framework for Developer Productivity
  1. DZone
  2. Culture and Methodologies
  3. Team Management
  4. Lightweight Workflow Execution Using Dexecutor

Lightweight Workflow Execution Using Dexecutor

Organizing your tasks in a manageable way can be difficult and unwieldly. Add in something like Dexecutor, and your life gets a whole lot easier.

Mohammad Nadeem user avatar by
Mohammad Nadeem
·
Nov. 10, 16 · Tutorial
Like (6)
Save
Tweet
Share
36.08K Views

Join the DZone community and get the full member experience.

Join For Free

Dexecutor can be used very easily for workflow like cases as depicted in the following diagram.

dexecutor-workflow-example

Dexecutor instance is created using DexecutorConfig, which in turn requires ExecutionEngine and TaskProvider, Default Implementation of ExecutionEngine uses ExecutorService, so lets create a Dexecutor Instance first (source code can be found here):

private static ExecutorService buildExecutor() {
   ExecutorService executorService = Executors.newFixedThreadPool(ThreadPoolUtil.ioIntesivePoolSize());
   return executorService;
 }
private Dexecutor<String, Boolean> buildDexecutor(final ExecutorService executorService) {
   DexecutorConfig<String, Boolean> config = new DexecutorConfig<>(executorService, new WorkFlowTaskProvider());
   return new DefaultDexecutor<>(config);
 }

TaskProvider comes into action, when it is the time to execute the task, for this example we will have simple implementation WorkFlowTaskProvider

public class WorkFlowTaskProvider implements TaskProvider<String, Boolean> {

    private final Map<String, Task<String, Boolean>> tasks = new HashMap<String, Task<String, Boolean>>() {

        private static final long serialVersionUID = 1L;
        {
            put(TaskOne.NAME, new TaskOne());
            put(TaskTwo.NAME, new TaskTwo());
            put(TaskThree.NAME, new TaskThree());
            put(TaskFour.NAME, new TaskFour());
            put(TaskFive.NAME, new TaskFive());
            put(TaskSix.NAME, new TaskSix());
            put(TaskSeven.NAME, new TaskSeven());
        }    
    };

    @Override
    public Task<String, Boolean> provideTask(final String id) {
        return this.tasks.get(id);
    }
}

For simplicity, we have implemented Task for each of the tasks (1..7), those can be found here, Most of the task implementations are same except for TaskTwo (if task 2 result is TRUE then tasks 3 and 4 would be executed otherwise task 5 would be executed) and TaskFive (If task 5 is executed (not skipped) then task task 6 would be executed).

dexecutor-task

TaskFive (TaskThree, TaskFour and TaskSix) overrides shouldExecute() method, to signal if the task should be executed or skipped.

dexecutor-skipping-task-execution

Next step is to build the graph:

dexecutor-workflow-graph-building

If WorkFlowApplication is executed, the following output can be observed.

Output if TaskTwo Is False

Executing TaskOne , result : true
Executing TaskTwo , result : false
Executing TaskFive , result : true
Executing TaskSix , result : true
Executing TaskSeven , result : true

Output if TaskTwo Is True

Executing TaskOne , result : true
Executing TaskTwo , result : true
Executing TaskFour , result : true
Executing TaskThree , result : true
Executing TaskSeven , result : true


Task (computing) workflow Execution (computing)

Published at DZone with permission of Mohammad Nadeem, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Playwright JavaScript Tutorial: A Complete Guide
  • Building A Log Analytics Solution 10 Times More Cost-Effective Than Elasticsearch
  • Front-End: Cache Strategies You Should Know
  • The SPACE Framework for Developer Productivity

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: