Skip to content

Re-implement how we handle duplication #107

Description

@johann-petrak

Instead of the current approach that uses CustomDuplication and relies on a specific order in which the instances get initialized and the controllerStarted callback invoked, do something as suggested by @ianroberts

private MLEngine[] engineHolder;

@Sharable
// getter and setter for engineHolder

public Resource init() {
  if(engineHolder == null) {
    engineHolder = new MLEngine[1];
  }
}

public void reInit() {
  engineHolder = null;
}

public void controllerExecutionStarted() {
  synchronized(ThisClass.class) {
    if(engineHolder[0] == null) {
      engineHolder[0] = createEngine();
      engineOwner = true;
    } else {
      engineOwner = false;
    }
  }
}

public void execute() {
  // guaranteed to be not-null,
  MLEngine engine = engineHolder[0];
}

public void controllerExecutionFinished() {
  if(engineOwner) {
    doStuffWith(engineHolder[0]);
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions