<commit_before>/**
 * Copyright (c) 2014-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
#pragma once

#include <wdt/Sender.h>
// For Options
#include <wdt/WdtOptions.h>
// For ErrorCode
#include <wdt/ErrorCodes.h>
// For IAbortChecker and WdtTransferRequest - TODO: split out ?
#include <wdt/WdtBase.h>
#include <wdt/WdtResourceController.h>
#include <wdt/util/EncryptionUtils.h>
#include <ostream>

namespace facebook {
namespace wdt {

// Note: we use Wdt in the method names even if redundant with the class name
// so we can search callers easily

/**
 * This class is the main API and entry point for using WDT (Warp speed Data
 * Transfers).
 *
 * Example of use:
 * // During the single threaded part of your service's initialization
 * Wdt &wdt = Wdt::initializeWdt("app-name");
 * // Optionally: change the WdtOptions as you need, for instance:
 * wdt.getWdtOptions().overwrite = true;
 * // Will use the (possibly changed above) settings, to configure wdt,
 * // for instance throttler options
 * // Sender for already setup receiver: (abortChecker is optional)
 * wdtSend(transferRequest, myAbortChecker);
 */
class Wdt {
 public:
  /**
   * Initialize the Wdt library and parse options from gflags.
   * Also initialize crypto library if needed/not already initialized.
   * @param:
   *   applicationName is used at fb for scuba reporting to differentiate apps
   */
  static Wdt &initializeWdt(const std::string &appName);
  /**
   * Mutable reference to WdtOptions
   */
  WdtOptions &getWdtOptions();
  /**
   * Return Wdt lib handle which has been previously initialized by calling
   * @see initializeWdt()
   * This is only needed if the caller code doesn't want to pass the Wdt
   * instance around.
   */
  static Wdt &getWdt(const std::string &appName);

  /// High level APIs:

  // TODO: add receiver side...

  /**
   * Send data for the shard identified by shardId to an already running/setup
   * receiver whose connection url was used to make a WdtTransferRequest.
   * Optionally passes an abort checker.
   */
  virtual ErrorCode wdtSend(
      const std::string &wdtNamespace, const WdtTransferRequest &wdtRequest,
      std::shared_ptr<IAbortChecker> abortChecker = nullptr,
      bool terminateExistingOne = false);

  virtual ErrorCode printWdtOptions(std::ostream &out);

  /// Virtual Destructor (for class hierarchy)
  virtual ~Wdt() {
  }

 protected:
  /// Set to true when the single instance is initialized
  bool initDone_{false};

  /**
   * Set to true when settings are applied to avoid applying again
   * This is needed because you can call wdtSend() independent of the thrift<commit_msg>Adding streaming and thrift service to stargate<commit_after>/**
 * Copyright (c) 2014-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
#pragma once

#include <wdt/Sender.h>
// For Options
#include <wdt/WdtOptions.h>
// For ErrorCode
#include <wdt/ErrorCodes.h>
// For IAbortChecker and WdtTransferRequest - TODO: split out ?
#include <wdt/WdtBase.h>
#include <wdt/WdtResourceController.h>
#include <wdt/util/EncryptionUtils.h>
#include <ostream>

namespace facebook {
namespace wdt {

// Note: we use Wdt in the method names even if redundant with the class name
// so we can search callers easily

/**
 * This class is the main API and entry point for using WDT (Warp speed Data
 * Transfers).
 *
 * Example of use:
 * // During the single threaded part of your service's initialization
 * Wdt &wdt = Wdt::initializeWdt("app-name");
 * // Optionally: change the WdtOptions as you need, for instance:
 * wdt.getWdtOptions().overwrite = true;
 * // Will use the (possibly changed above) settings, to configure wdt,
 * // for instance throttler options
 * // Sender for already setup receiver: (abortChecker is optional)
 * wdtSend(transferRequest, myAbortChecker);
 */
class Wdt {
 public:
  /**
   * Initialize the Wdt library and parse options from gflags.
   * Also initialize crypto library if needed/not already initialized.
   * @param:
   *   applicationName is used at fb for scuba reporting to differentiate apps
   */
  static Wdt &initializeWdt(const std::string &appName);
  /**
   * Mutable reference to WdtOptions
   */
  WdtOptions &getWdtOptions();
  /**
   * Return Wdt lib handle which has been previously initialized by calling
   * @see initializeWdt()
   * This is only needed if the caller code doesn't want to pass the Wdt
   * instance around.
   */
  static Wdt &getWdt(const std::string &appName);

  /// High level APIs:

  // TODO: add receiver side...

  /**
   * Send data for the shard identified by shardId to an already running/setup
   * receiver whose connection url was used to make a WdtTransferRequest.
   * Optionally passes an abort checker.
   */
  virtual ErrorCode wdtSend(
      const std::string &wdtNamespace, const WdtTransferRequest &wdtRequest,
      std::shared_ptr<IAbortChecker> abortChecker = nullptr,
      bool terminateExistingOne = false);

  virtual ErrorCode printWdtOptions(std::ostream &out);

  WdtResourceController *getWdtResourceController() {
    return &resourceController_;
  }

  /// Virtual Destructor (for class hierarchy)
  virtual ~Wdt() {
  }

 protected:
  /// Set to true when the single instance is initialized
  bool initDone_{false};

  /**
   * Set to true when settings are applied to avoid applying again
   * This is needed because you can call wdtSend() independent of the thrift
{'fraction_non_alphanumeric': 0.08912747102931153, 'fraction_numerical': 0.0013633265167007499, 'mean_word_length': 3.613993710691824, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2685414', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1661, 'n_words': 685}