Пример #1
0
  @SuppressWarnings("boxing")
  @Thread(isDaemonic = true)
  public void backgroundInit() {
    // (Ralf:) zomfg, this is one of the worst hacks i've done the last
    // couple of months. Deep within jmdns we placed a variable to
    // override a check if it is already save 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;

    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");

    // TODO put this in a thread
    this.checkCache.loadCache();

    try {
      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 = getFreePort();
      final ServiceInfo service =
          ServiceInfo.create(TYPE, NAME + " @" + this.timeOfStartup, port, 0, 0, EXPORT_NAME);

      this.localManagerExportServer =
          Proxies.newServer(EXPORT_NAME, port, (DiscoveryManager) this.localManager);
      this.jmdns.registerService(service);

      // Set it again, this time for the lock below
      this.timeOfStartup = System.currentTimeMillis();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (IllegalStateException e) {
      this.logger.warning("Error starting discovery.");
    } finally {
      this.startupLatch.countDown();
      this.jmdnsLock.unlock();
    }

    // and load our cache...
    // todo make this configurable...
    //		this.checkCache.loadCache(fileName)
  }
Пример #2
0
  @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");
  }