init method

void init()

Initializes the Link. There is no guarantee that the link will be ready when this method returns. If the configure method is not called prior to calling this method, it is called.

This method handles the following:

  • calling configure if it has not been called.
  • creating a provider if it has not been created.
  • loading the nodes.json file.
  • creating the actual link.
  • discovering brokers if that was enabled.

Implementation

void init() {
  if (!_configured) {
    if (!configure()) {
      return;
    }
  }

  if (_initialized) {
    return;
  }

  _initialized = true;

  if (provider == null) {
    provider = SimpleNodeProvider(null, profiles);
    (provider as SimpleNodeProvider).setPersistFunction(saveAsync);
  }

  loadNodesFile();

  void doRun() {
    link = createHttpLink();
    _ready = true;

    if (_connectOnReady) {
      connect();
    }
  }

  doRun();
}