@Override
 protected void doStop() throws Exception {
   LOG.info("Stopping flowlet: " + flowletContext);
   try {
     driver.stopAndWait();
   } finally {
     // Close all consumers
     for (ConsumerSupplier consumerSupplier : consumerSuppliers) {
       Closeables.closeQuietly(consumerSupplier);
     }
     flowletContext.close();
   }
   LOG.info("Flowlet stopped: " + flowletContext);
 }
 /** Constructs an instance. The instance must be constructed before the flowlet driver starts. */
 FlowletProgramController(
     String programName,
     String flowletName,
     BasicFlowletContext flowletContext,
     FlowletRuntimeService driver,
     Collection<ProducerSupplier> producerSuppliers,
     Collection<ConsumerSupplier<?>> consumerSuppliers) {
   super(programName + ":" + flowletName, flowletContext.getRunId());
   this.flowletContext = flowletContext;
   this.driver = driver;
   this.producerSuppliers = producerSuppliers;
   this.consumerSuppliers = consumerSuppliers;
   listenDriveState(driver);
 }
 @Override
 protected void doResume() throws Exception {
   LOG.info("Resuming flowlet: " + flowletContext);
   // Open producers
   for (ProducerSupplier producerSupplier : producerSuppliers) {
     producerSupplier.open();
   }
   // Open consumers
   for (ConsumerSupplier consumerSupplier : consumerSuppliers) {
     consumerSupplier.open(flowletContext.getInstanceCount());
   }
   driver.resume();
   LOG.info("Flowlet resumed: " + flowletContext);
 }
 private void changeInstanceCount(BasicFlowletContext flowletContext, int instanceCount) {
   Preconditions.checkState(
       getState() == State.SUSPENDED,
       "Cannot change instance count of a flowlet without suspension.");
   flowletContext.setInstanceCount(instanceCount);
 }