Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-implement how we handle duplication #107

Open
johann-petrak opened this issue Jan 31, 2019 · 0 comments
Open

Re-implement how we handle duplication #107

johann-petrak opened this issue Jan 31, 2019 · 0 comments

Comments

@johann-petrak
Copy link
Collaborator

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]);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant