
package com.github.airutech.cnets.runnablesContainer;

/*[[[cog
import cogging as c
c.tpl(cog,templateFile,c.a(prefix=configFile))
]]]*/

import com.github.airutech.cnets.types.*;
public class runnablesContainer{
  
  public runnablesContainer(){
    onCreate();
    initialize();
  }

  private void initialize(){
    
    onKernels();
    
  }
/*[[[end]]] (checksum: d3aa07db72ddfd84eb24c3a0afb195e6)*/

  private void onKernels() {

  }

  private void onCreate(){

  }

  private Kernel kernel = null;
  private runnablesContainer[] containers = null;
  private RunnableStoppable target = null;

  public void setContainers(runnablesContainer[] containers){
    this.containers = containers;
  }

  public void setCore(RunnableStoppable target){
    this.target = target;
  }

  public void launch(boolean lockLastElement){
    if(target!=null){
      kernel = new Kernel();
      kernel.launch(target, lockLastElement);
    }else if(containers!=null){
      for(int i=0;i<containers.length - 1;i++){
        containers[i].launch(false);
      }
      containers[containers.length - 1].launch(lockLastElement);
    }
  }

  public void stop(){
    if(target!=null){
      if(kernel!=null) {
        kernel.stopThread();
        kernel = null;
      }
    }else if(containers!=null){
      for(int i=containers.length-1;i>=0;i--){
        containers[i].stop();
      }
    }
  }
}


@@ -594,16 +594,18 @@
  null;%0A%0A
+%0A%0A
   public
@@ -693,24 +693,309 @@
 iners;%0A  %7D%0A%0A
+/*getTarget and getContainers allow third-party libraries to implement launch-stop algorithms*/%0A  public RunnableStoppable getTarget()%7Breturn target;%7D%0A  public runnablesContainer%5B%5D getContainers()%7Bif(target!=null)%7Breturn new runnablesContainer%5B%5D%7Bthis%7D;%7Delse%7Breturn containers;%7D%7D%0A/**/%0A%0A
   public voi

allow to implement 3rd party launchers/stoppers