Start an asynchronous upload of the current block.

@throws IOException
Problems opening the destination for upload or initializing the
upload
760127
private synchronized void uploadCurrentBlock() throws IOException {
    if (!hasActiveBlock()) {
      throw new IllegalStateException("No active block");
    }
    LOG.debug("Writing block # {}", blockCount);
    if (multiPartUpload == null) {
      LOG.debug("Initiating Multipart upload");
      multiPartUpload = new MultiPartUpload();
    }
    try {
      multiPartUpload.uploadBlockAsync(getActiveBlock());
    } finally {
      // set the block to null, so the next write will create a new block.
      clearActiveBlock();
    }
  }
1003020
public void start() throws IOException {
    Preconditions.checkState(!isStarted(), "JN already running");
   
    journalNodes = getJournalHttpAddresses(conf);
    // crash the JournalNode if the DFS_JOURNALNODE_HOSTS is not configured.
    if (journalNodes.isEmpty()) {
      String msg = JournalConfigKeys.DFS_JOURNALNODE_HOSTS
          + " is not present in the configuration.";
      LOG.fatal(msg);
      throw new IOException(msg);
    }
    LOG.info("JournalNode hosts: " + journalNodes);
    
    validateAndCreateJournalDir(localDir);
    LOG.info("JournalNode storage: " + localDir.getAbsolutePath());
    
    InetSocketAddress socAddr = JournalNodeRpcServer.getAddress(conf);
    // TODO serverId has to be set correctly
    metrics = new JournalNodeMetrics(conf, socAddr.toString());
    
    httpServer = new JournalNodeHttpServer(conf, this);
    httpServer.start();

    rpcServer = new JournalNodeRpcServer(conf, this);
    rpcServer.start();
    
    journalSyncer = new JournalNodeJournalSyncer(journalNodes,
        httpServer.getAddress(), conf);
    journalSyncerThread = new Thread(journalSyncer, "Thread-JournalSyncer");
    journalSyncerThread.start();
  }
402855
public synchronized void start() throws IOException {
    Preconditions.checkState(mProcess == null, "Worker is already running");
    mProcess = new ExternalProcess(mProperties, LimitedLifeWorkerProcess.class,
        new File(mLogsDir, "worker.out"));
    mProcess.start();
  }
1170541
public void init()
    throws IOException
  {
    long now = CurrentTime.getExactTime();

    // server/0263
    // _nextRolloverCheckTime = now + _rolloverCheckPeriod;

    Path path = getPath();

    if (path != null) {
      Files.createDirectories(path.getParent());

      _rolloverPrefix = path.getName(path.getNameCount() - 1).toString();

      long lastModified = Files.getLastModifiedTime(path).toMillis();
      
      if (lastModified <= 0 || now < lastModified) {
        lastModified = now;
      }

      // _calendar.setGMTTime(lastModified);

      _nextPeriodEnd = nextRolloverTime(lastModified);
    }
    else {
      _nextPeriodEnd = nextRolloverTime(now);
    }
    
    if (_archiveFormat != null || getRolloverPeriod() <= 0) {
    }
    else if (_rolloverCron != null)
      _archiveFormat = _rolloverPrefix + ".%Y%m%d.%H";
    else if (getRolloverPeriod() % DAY == 0)
      _archiveFormat = _rolloverPrefix + ".%Y%m%d";
    else if (getRolloverPeriod() % HOUR == 0)
      _archiveFormat = _rolloverPrefix + ".%Y%m%d.%H";
    else
      _archiveFormat = _rolloverPrefix + ".%Y%m%d.%H%M";
    
    _isInit = true;

    _rolloverListener.requeue(_rolloverAlarm);
    rollover();
  }
760385
public void start() {
        if (this.started) {
            throw new IllegalStateException("Cannot start the EventStream because it isn't stopped.");
        }

        final long initialPosition;

        if (this.startingPosition == STREAM_POSITION_NOW) {
            BoxAPIRequest request = new BoxAPIRequest(this.api, EVENT_URL.build(this.api.getBaseURL(), "now"), "GET");
            BoxJSONResponse response = (BoxJSONResponse) request.send();
            JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
            initialPosition = jsonObject.get("next_stream_position").asLong();
        } else {
            assert this.startingPosition >= 0 : "Starting position must be non-negative";
            initialPosition = this.startingPosition;
        }

        this.poller = new Poller(initialPosition);

        this.pollerThread = new Thread(this.poller);
        this.pollerThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            public void uncaughtException(Thread t, Throwable e) {
                EventStream.this.notifyException(e);
            }
        });
        this.pollerThread.start();

        this.started = true;
    }
1366157
void completeUploading() throws IOException
  {
    LOGGER.debug("name: {}, currentSize: {}, Threshold: {},"
                 + " fileCount: {}, fileBucketSize: {}",
                 _file.getAbsolutePath(),
                 _currentSize, this._csvFileSize, _fileCount,
                 this._csvFileBucketSize);

    _outstream.flush();
    _outstream.close();
    //last file
    if (_currentSize > 0)
    {
      FileUploader fu = new FileUploader(_loader, _location, _file);
      fu.upload();
      _uploaders.add(fu);
    }
    else
    {
      // delete empty file
      _file.delete();
    }

    for (FileUploader fu : _uploaders)
    {
      // Finish all files being uploaded
      fu.join();
    }

    // Delete the directory once we are done (for easier tracking
    // of what is going on)
    _directory.deleteOnExit();

    if (this._rowCount == 0)
    {
      setState(State.EMPTY);
    }
  }
946869
void kickstart() throws IOException {
        if (state >= 0) {
            return;
        }

        HandshakeMessage m = getKickstartMessage();

        if (debug != null && Debug.isOn("handshake")) {
            m.print(System.out);
        }
        m.write(output);
        output.flush();

        state = m.messageType();
    }
859523
@Override
	public ISynchronizationPoint<Exception> start() {
		SynchronizationPoint<Exception> sp = new SynchronizationPoint<>();
		io.canStartReading().listenAsync(new Task.Cpu.FromRunnable(() -> {
			try {
				Starter start = new Starter(io, defaultEncoding, charactersBuffersSize, maxBuffers);
				stream = start.start();
				next().listenInline(sp);
			} catch (Exception e) {
				sp.error(e);
			}
		}, "Start parsing XML", io.getPriority()), true);
		return sp;
	}
1232532
@Override
  public ServerImpl start() throws IOException {
    synchronized (lock) {
      checkState(!started, "Already started");
      checkState(!shutdown, "Shutting down");
      // Start and wait for any ports to actually be bound.

      ServerListenerImpl listener = new ServerListenerImpl();
      for (InternalServer ts : transportServers) {
        ts.start(listener);
        activeTransportServers++;
      }
      executor = Preconditions.checkNotNull(executorPool.getObject(), "executor");
      started = true;
      return this;
    }
  }
330330
public void asyncPut(final byte[] data, final String key, final String token, StringMap params,
                         String mime, boolean checkCrc, UpCompletionHandler handler) throws IOException {
        checkArgs(key, data, null, token);
        if (mime == null) {
            mime = Client.DefaultMime;
        }
        params = filterParam(params);
        new FormUploader(client, token, key, data, params, mime, checkCrc, configuration).asyncUpload(handler);
    }
821334
private synchronized void initiateRetry() {
    retryCount += 1;
    currentListener = new RetryingBlockFetchListener();

    logger.info("Retrying fetch ({}/{}) for {} outstanding blocks after {} ms",
      retryCount, maxRetries, outstandingBlocksIds.size(), retryWaitTime);

    executorService.submit(() -> {
      Uninterruptibles.sleepUninterruptibly(retryWaitTime, TimeUnit.MILLISECONDS);
      fetchAllOutstanding();
    });
  }
127691
private void init() throws IOException {
        if (initialized.compareAndSet(false, true)) {
            log.debug("Init: {}", mode);
            // if the path is null, the consumer has been uninitialized
            if (path != null) {
                if (log.isDebugEnabled()) {
                    Path parent = path.getParent();
                    log.debug("Parent abs: {} dir: {}", parent.isAbsolute(), Files.isDirectory(parent));
                }
                if (IClientStream.MODE_APPEND.equals(mode)) {
                    if (Files.notExists(path)) {
                        throw new IOException("File to be appended doesnt exist, verify the record mode");
                    }
                    log.debug("Path: {}\nRead: {} write: {} size: {}", path, Files.isReadable(path), Files.isWritable(path), Files.size(path));
                    writer = new FLVWriter(path, true);
                } else if (IClientStream.MODE_RECORD.equals(mode)) {
                    try {
                        // delete existing file
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                        // ensure parent dirs exist
                        Files.createDirectories(path.getParent());
                        // create the file
                        path = Files.createFile(path);
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                    if (!Files.isWritable(path)) {
                        throw new IOException("File is not writable");
                    }
                    log.debug("Path: {}\nRead: {} write: {}", path, Files.isReadable(path), Files.isWritable(path));
                    writer = new FLVWriter(path, false);
                } else {
                    try {
                        // delete existing file since we're not recording nor appending
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                }
            } else {
                log.warn("Consumer is uninitialized");
            }
            log.debug("Init - complete");
        }
    }
1034007
private HttpResponse executeUploadInitiation(GenericUrl initiationRequestUrl) throws IOException {
    updateStateAndNotifyListener(UploadState.INITIATION_STARTED);

    initiationRequestUrl.put("uploadType", "resumable");
    HttpContent content = metadata == null ? new EmptyContent() : metadata;
    HttpRequest request =
        requestFactory.buildRequest(initiationRequestMethod, initiationRequestUrl, content);
    initiationHeaders.set(CONTENT_TYPE_HEADER, mediaContent.getType());
    if (isMediaLengthKnown()) {
      initiationHeaders.set(CONTENT_LENGTH_HEADER, getMediaContentLength());
    }
    request.getHeaders().putAll(initiationHeaders);
    HttpResponse response = executeCurrentRequest(request);
    boolean notificationCompleted = false;

    try {
      updateStateAndNotifyListener(UploadState.INITIATION_COMPLETE);
      notificationCompleted = true;
    } finally {
      if (!notificationCompleted) {
        response.disconnect();
      }
    }
    return response;
  }
962961
private void putObject() throws IOException {
    LOG.debug("Executing regular upload for {}", writeOperationHelper);

    final COSDataBlocks.DataBlock block = getActiveBlock();
    int size = block.dataSize();
    final COSDataBlocks.BlockUploadData uploadData = block.startUpload();
    final PutObjectRequest putObjectRequest = uploadData.hasFile()
        ? writeOperationHelper.newPutRequest(uploadData.getFile())
        : writeOperationHelper.newPutRequest(uploadData.getUploadStream(), size);

    final ObjectMetadata om = new ObjectMetadata();
    om.setUserMetadata(mMetadata);
    if (contentType != null && !contentType.isEmpty()) {
      om.setContentType(contentType);
    } else {
      om.setContentType("application/octet-stream");
    }
    putObjectRequest.setMetadata(om);
    ListenableFuture<PutObjectResult> putObjectResult =
        executorService.submit(new Callable<PutObjectResult>() {
          @Override
          public PutObjectResult call() throws Exception {
            PutObjectResult result;
            try {
              // the putObject call automatically closes the input
              // stream afterwards.
              result = writeOperationHelper.putObject(putObjectRequest);
            } finally {
              closeAll(LOG, uploadData, block);
            }
            return result;
          }
        });
    clearActiveBlock();
    // wait for completion
    try {
      putObjectResult.get();
    } catch (InterruptedException ie) {
      LOG.warn("Interrupted object upload", ie);
      Thread.currentThread().interrupt();
    } catch (ExecutionException ee) {
      throw extractException("regular upload", key, ee);
    }
  }
295010
@Override
    public void start(boolean block) throws InterruptedException, ExecutionException {
        Future<?> task = m_es.submit(new ParentEvent(null));
        if (block) {
            task.get();
        }
    }
289807
def run(self):
        
        self._running.set()
        self._status = TransferState.RUNNING
        self._time_started = time.time()

        # Initializes the upload
        self._initialize_upload()

        # Opens the file for reading in binary mode.
        try:
            with io.open(self._file_path, mode='rb') as fp:
                # Creates a partitioned file
                parted_file = UPartedFile(
                    fp, self._file_size, self._part_size, self._upload_id,
                    self._retry, self._timeout, self.session, self._api
                )

                # Iterates over parts and submits them for upload.
                for _ in parted_file:
                    if self._stop_signal:
                        return
                    self._running.wait()
                    self._bytes_done += self._part_size
                    # If the progress callback is set we need to provide a
                    # progress object for it.
                    if self._progress_callback:
                        progress = Progress(
                            parted_file.total, parted_file.total_submitted,
                            self._bytes_done, self._file_size, self.duration
                        )
                        self._progress_callback(progress)
        except IOError:
            raise SbgError('Unable to open file {}'.format(self._file_path))
        except Exception as e:
            # If the errorback callback is set call it with status
            self._status = TransferState.FAILED
            if self._errorback:
                self._errorback(self._status)
            else:
                raise SbgError(six.text_type(e))

        # Finalizes the upload.
        self._finalize_upload()
        self._status = TransferState.COMPLETED
        # If the callback is set call it.
        if self._callback:
            self._callback(self._status)
517602
public void start() throws IOException {
    try {
      int port = 0;
      int oriPort = listener.getPort(); // The original requested port
      while (true) {
        try {
          port = webServer.getConnectors()[0].getLocalPort();
          LOG.info("Port returned by webServer.getConnectors()[0]." +
          		"getLocalPort() before open() is "+ port + 
          		". Opening the listener on " + oriPort);
          listener.open();
          port = listener.getLocalPort();
          LOG.info("listener.getLocalPort() returned " + listener.getLocalPort() + 
                " webServer.getConnectors()[0].getLocalPort() returned " +
                webServer.getConnectors()[0].getLocalPort());
          //Workaround to handle the problem reported in HADOOP-4744
          if (port < 0) {
            Thread.sleep(100);
            int numRetries = 1;
            while (port < 0) {
              LOG.warn("listener.getLocalPort returned " + port);
              if (numRetries++ > MAX_RETRIES) {
                throw new Exception(" listener.getLocalPort is returning " +
                		"less than 0 even after " +numRetries+" resets");
              }
              for (int i = 0; i < 2; i++) {
                LOG.info("Retrying listener.getLocalPort()");
                port = listener.getLocalPort();
                if (port > 0) {
                  break;
                }
                Thread.sleep(200);
              }
              if (port > 0) {
                break;
              }
              LOG.info("Bouncing the listener");
              listener.close();
              Thread.sleep(1000);
              listener.setPort(oriPort == 0 ? 0 : (oriPort += 1));
              listener.open();
              Thread.sleep(100);
              port = listener.getLocalPort();
            }
          } //Workaround end
          LOG.info("Jetty bound to port " + port);
          webServer.start();
          // Workaround for HADOOP-6386
          port = listener.getLocalPort();
          if (port < 0) {
            LOG.warn("Bounds port is " + port + " after webserver start");
            for (int i = 0; i < MAX_RETRIES/2; i++) {
              try {
                webServer.stop();
              } catch (Exception e) {
                LOG.warn("Can't stop  web-server", e);
              }
              Thread.sleep(1000);
              
              listener.setPort(oriPort == 0 ? 0 : (oriPort += 1));
              listener.open();
              Thread.sleep(100);
              webServer.start();
              LOG.info(i + "attempts to restart webserver");
              port = listener.getLocalPort();
              if (port > 0)
                break;
            }
            if (port < 0)
              throw new Exception("listener.getLocalPort() is returning " +
                                "less than 0 even after " +MAX_RETRIES+" resets");
          }
          // End of HADOOP-6386 workaround
          break;
        } catch (IOException ex) {
          // if this is a bind exception,
          // then try the next port number.
          if (ex instanceof BindException) {
            if (!findPort) {
              throw (BindException) ex;
            }
          } else {
            LOG.info("HttpServer.start() threw a non Bind IOException"); 
            throw ex;
          }
        } catch (MultiException ex) {
          LOG.info("HttpServer.start() threw a MultiException"); 
          throw ex;
        }
        listener.setPort((oriPort += 1));
      }
    } catch (IOException e) {
      throw e;
    } catch (Exception e) {
      throw new IOException("Problem starting http server", e);
    }
  }