@SuppressWarnings("boxing")
  public void backgroundInit() {
    // (Ralf:) zomfg, this is one of the worst hacks i've done the last years. Deep within  jmdns we
    // placed a variable to
    // override a check if it is already safe to transmit something. jmDNS usually takes 5 seconds
    // to reach that state, but that's
    // too long for us. If you set this variable the check will be skipped and the request should
    // take place much faster.
    // Appears to work(tm).
    ServiceResolver.ANNOUNCE_OVERRIDE = true;

    this.logger.status("backgroundinit/start");

    final PluginConfigurationUtil pcu = new PluginConfigurationUtil(this.pluginConfiguration);
    this.startupLock = pcu.getInt(RemoteDiscovery.class, "startup.locktime", 1000);
    this.lockMode = pcu.getString(RemoteDiscovery.class, "startup.lockmode", "onepass");

    try {
      this.logger.status("backgroundinit/lock");

      this.jmdnsLock.lock();
      this.jmdns =
          JmDNS
              .create(); // Maybe init with local loopback in case no other network card is present,
      // otherwise returns null

      this.timeOfStartup = System.currentTimeMillis();

      final int port = RemoteDiscoveryImpl.getFreePort();
      final ServiceInfo service =
          ServiceInfo.create(TYPE, NAME + " @" + this.timeOfStartup, port, 0, 0, EXPORT_NAME);
      this.logger.status("backgroundinit/export", "port", port);
      this.localManagerExportServer =
          Proxies.newServer(EXPORT_NAME, port, (DiscoveryManager) this.localTCPIPManager);
      this.logger.status("backgroundinit/announce", "port", port);
      this.jmdns.registerService(service);

      // Set it again, this time for the lock below
      this.timeOfStartup = System.currentTimeMillis();
    } catch (final IOException e) {
      e.printStackTrace();
    } catch (final IllegalStateException e) {
      this.logger.status("backgroundinit/exception/illegalstate", "message", e.getMessage());
    } finally {
      this.logger.status("backgroundinit/unlock");
      this.startupLatch.countDown();
      this.jmdnsLock.unlock();
    }

    this.logger.status("backgroundinit/end");
  }
  void discoverThread() {

    try {
      this.startupLatch.await();
    } catch (final InterruptedException e) {
      e.printStackTrace();
      return;
    }

    // Increase counter
    this.discoverThreadCounter.incrementAndGet();

    // Create empty data.
    ServiceInfo[] infos = {};

    // Magic: Get all network services of our type.
    try {
      this.jmdnsLock.lock();
      // TODO: jmdsn can be null if no network card is present
      infos = this.jmdns.list(TYPE);
    } catch (final IllegalStateException e) {
      this.logger.status("discoverthread/exception", "message", e.getMessage());
    } finally {
      this.jmdnsLock.unlock();
    }

    // Reset all service infos
    try {
      this.serviceInfosLock.lock();
      this.serviceInfos.clear();
      this.serviceInfos.addAll(Arrays.asList(infos));

    } finally {
      this.serviceInfosLock.unlock();
    }

    // Process all callbacks.
    @SuppressWarnings("unused")
    final Collection<CallbackRequest> toRemove = new ArrayList<CallbackRequest>();

    //
    // TODO: This callback handling needs improvement. Check for unsynchronized access to the
    // allRequest structure
    //
  }
  /**
   * Notifies single listener.
   *
   * @param lsnr Listener.
   */
  private void notifyListener(IgniteInClosure<? super IgniteInternalFuture<R>> lsnr) {
    assert lsnr != null;

    try {
      lsnr.apply(this);
    } catch (IllegalStateException e) {
      U.error(
          null,
          "Failed to notify listener (is grid stopped?) [fut="
              + this
              + ", lsnr="
              + lsnr
              + ", err="
              + e.getMessage()
              + ']',
          e);
    } catch (RuntimeException | Error e) {
      U.error(null, "Failed to notify listener: " + lsnr, e);

      throw e;
    }
  }