2 Replies Latest reply on Mar 27, 2007 8:29 AM by Ronald van Kuijk

    task node implementation

    Tom Baeyens Master

      i'm thinking about the implementation of the task node. i see 3 options implement how the created task gets inserted into the the database. any comments are appreciated.

      In the first approach, we could just add Task to the pvm package. Process languages should have the ability to ignore that member field. This violates a little bit the language pluggability in the sense that processes that don't use it will have the tasks property. But on the other hand, if we decouple everything, the simple things become quite complex (also for the user) as you can see in the other alternatives below.

      public void execute(Execution execution) throws Exception {
       Task task = createTask(execution);
      
       execution.addTask(task);
      


      In this second approach, we could have a task repository in the context. Pretty modular, but the user is confronted with the task repository in his configuration files. The service could keep track of all the created tasks and inserts them in the db.

      public void execute(Execution execution) throws Exception {
       Task task = createTask(execution);
      
       TaskRepository taskRepository = (TaskRepository) execution.getContext().find("taskRepository");
       taskRepository.addTask(task);
      


      // OR //

      Assume the execution implements a kind of TaskExecution interface. In that case, the process languages that want to make use of tasks, can make sure that their Execution will implement that interface. The concrete execution class can have a member field called tasks that will be persisted with JPA in cascading mode.

      One of the advantages here is that in testing, you don't require a context to be set up.

      public void execute(Execution execution) throws Exception {
       Task task = createTask(execution);
      
       if (! (execution instanceof TaskExecution)) {
       throw new JbpmException("couldn't add task because execution doesn't implement TaskExecution");
       }
       TaskExecution taskExecution = (TaskExecution) execution;
       taskExecution.addTask(task);
      



      a last approach might be to have a kind of generic extensions mechanism in the execution (just like we have the modules now with ModuleInstance). It could be a hashmap that stores any runtime information keyed by name.

      public void execute(Execution execution) throws Exception {
       Task task = createTask(execution);
      
       TaskExtension taskExtension = (TaskExtension)execution.getExtension(Task.EXTENSIONKEY_TASK);
       taskExtension.addTask(task);