Java workflow development

I would like to ask about the development of a "workflow merger". I have several workflows that are not very similar to each other. However, sometimes I want to combine them, slightly modifying them. Let me give you an example:

Workflow 1 - Shutdown

A1 (pack the bag) β†’ A2 (leave the house) β†’ A3 (catch the bus) β†’ A4 ...

Workflow 2 - Daily Watering of Plants

B1 (turn on the water) β†’ B2 (leave the house) β†’ B3 (plant water) β†’ B4 (enter the house) β†’ B5 (turn off the water)

On Sunday I want to go on a trip, and I also need to water the plants. So I want to create something like A1 β†’ B1 - B5 β†’ A2 .... I also want to be able to tell my friend to finish watering, which would be something like A1 β†’ B1 to B2 β†’ C1 (transfer the task to a friend) β†’ A3 ... As you can see, the flow is simple - there are no plugs and connections in it, and I don’t need such functions. All I need to do is create a linear list of commands with the ability to easily merge them. All code fragments are Java methods at the moment (and I would like to make them something like atomic threads).

The main goal of my approach is to avoid entering the same code again and again. A stream can have hundreds of steps. I would like to make an expression like Run thread A, but instead of starting A2 and A3, do B2 to B6 and continue with A.

I have two main questions:

  • Is there any infrastructure that already supports this? If so, is it not too difficult for my purpose?
  • If not, what would be the best way to implement such a thing?

Note. Could you indicate what is so incomprehensible in my question?

+6
source share
4 answers

I personally believe that this requirement can be implemented without the use of any specific structure. You can create an application as follows:

  • TaskPerformer: an interface with a method named executeTask. Represents the Task to be completed.

  • BagPackTask: a concrete class that implements TaskPerformer. It also defines the executeTask method, which contains the code to package the package.

  • WaterPlantsTask: Another specific class that implements TaskPerformer. Also defines the executeTask method, which contains code for watering the plants. Similarly, you have one class for each task that implements the Taskperformer and defines the behavior of the task using the executeTask method.

  • Workflow: A class that will be used to perform two or more tasks and allow you to mix and match existing tasks. The class will contain a TaskPerformer list, and the constructor for this class will have a List parameter to request the execution of tasks. The class will contain the executeWorkflow method, which will iterate over the list and call the executeTask method for each element in the list. In other words, this class can be used to perform all the tasks that were passed to its constructor during instance creation using the executeWorkflow method. It is important to note that the order in which you insert items into the list is the order in which tasks are performed.

Using this approach, you eliminate the need for any if-else conditions to determine which task to perform. You can reuse TaskPerformer implementations in how many instances of Workflow you want. You get a super clean design. Let me know if you need any clarification, as I feel this project should solve your problem. It would be nice to clarify all your doubts before accepting any answers :)

+1
source

... or implement a command template . This should be pretty easy without any frameworks.

+1
source

Spring Batch is very simple to get up and running and allows you to submit tasks that run tasks in any order. I would recommend this as a starting point to find out if it fits your needs. For your case, I would recommend running it using an in-memory database, such as HSQLDB, to avoid the overhead of tuning. You can always write the results of your work to a log file.

This is probably the most mature JBPM enterprise business process engine , but it seems a bit heavy for what you need to do.

0
source

Take a look at OSWorkflow , it is really nice, easy and ensures that all FSM machines are out of the box.

0
source

Source: https://habr.com/ru/post/927456/


All Articles