Package ca.carleton.gcrc.couch.submission

Source Code of ca.carleton.gcrc.couch.submission.SubmissionRobot

package ca.carleton.gcrc.couch.submission;

import ca.carleton.gcrc.couch.submission.impl.SubmissionRobotThread;

public class SubmissionRobot {
 
  private SubmissionRobotThread workerThread = null;
  private SubmissionRobotSettings settings = null;

  public SubmissionRobot(SubmissionRobotSettings settings){
    this.settings = settings;
  }
 
  synchronized public void start() throws Exception {
    if( null == settings.getSubmissionDesignDocument() ) {
      throw new Exception("Submission DB design document must be specified for submission worker");
    }
    if( null == settings.getDocumentDesignDocument() ) {
      throw new Exception("Document DB design document must be specified for submission worker");
    }
    if( null == settings.getUserDb() ) {
      throw new Exception("User DB must be specified for submission worker");
    }
    if( null != workerThread ) {
      // Already started
      return;
    }
    workerThread = new SubmissionRobotThread(settings);
    workerThread.start();
  }
 
  synchronized public void stop() throws Exception {
    if( null == workerThread ) {
      return;
    }
    SubmissionRobotThread thread = workerThread;
    workerThread = null;

    thread.shutdown();
    thread.join();
  }

  synchronized public void stopTimeoutMillis(int millis) throws Exception {
    if( null == workerThread ) {
      return;
    }
    SubmissionRobotThread thread = workerThread;
    workerThread = null;

    thread.shutdown();
    thread.join(millis);
    thread.interrupt();
  }

}
TOP

Related Classes of ca.carleton.gcrc.couch.submission.SubmissionRobot

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.