Exemplo n.º 1
0
 public static final void openAll() {
   try {
     synchronized (ClientCatalog.class) {
       for (ClientCatalogItem catalogItem : getClientCatalog(null)) {
         Logging.info("OSS loads index " + catalogItem.getIndexName());
         getClient(catalogItem.getIndexName());
       }
     }
   } catch (SearchLibException e) {
     Logging.error(e);
   }
 }
  // TODO: Consider implementing this method using Android's ConnectivityManager
  public synchronized boolean isNetworkUnavailable(long checkInterval) {
    if (this.offlineMode) return true;

    // If there's been success since failure, network assumed to be reachable.
    if (this.lastAvailableLogTime.get() > this.lastUnavailableLogTime.get()) {
      this.lastNetworkUnavailableResult.set(false);
      return this.lastNetworkUnavailableResult.get();
    }

    long now = System.currentTimeMillis();

    // If there's been success recently, network assumed to be reachable.
    if (!this.lastNetworkUnavailableResult.get()
        && now - this.lastAvailableLogTime.get() < checkInterval) {
      return this.lastNetworkUnavailableResult.get();
    }

    // If query comes too soon after an earlier one that addressed the network, return the earlier
    // result.
    if (now - this.lastNetworkCheckTime.get() < checkInterval) {
      return this.lastNetworkUnavailableResult.get();
    }

    this.lastNetworkCheckTime.set(now);

    if (!this.isWorldWindServerUnavailable()) {
      this.lastNetworkUnavailableResult.set(false); // network not unreachable
      return this.lastNetworkUnavailableResult.get();
    }

    for (String testHost : networkTestSites) {
      if (isHostReachable(testHost)) {
        {
          this.lastNetworkUnavailableResult.set(false); // network not unreachable
          return this.lastNetworkUnavailableResult.get();
        }
      }
    }

    if (now - this.lastNetworkStatusReportTime.get() > NETWORK_STATUS_REPORT_INTERVAL) {
      this.lastNetworkStatusReportTime.set(now);
      String message = Logging.getMessage("NetworkStatus.NetworkUnreachable");
      Logging.info(message);
    }

    this.lastNetworkUnavailableResult.set(
        true); // if no successful contact then network is unreachable
    return this.lastNetworkUnavailableResult.get();
  }
Exemplo n.º 3
0
 public static final void closeIndex(String indexName) throws SearchLibException {
   Client client = null;
   clientsLock.w.lock();
   try {
     File indexDirectory = getIndexDirectory(indexName);
     client = CLIENTS.get(indexDirectory);
     if (client == null) return;
     Logging.info("Closing client " + indexName);
     client.close();
     CLIENTS.remove(indexDirectory);
   } finally {
     clientsLock.w.unlock();
   }
   if (client != null) PushEvent.eventClientSwitch.publish(client);
 }
Exemplo n.º 4
0
 public static final void closeAll() {
   synchronized (ClientCatalog.class) {
     clientsLock.r.lock();
     try {
       for (Client client : CLIENTS.values()) {
         if (client == null) continue;
         Logging.info("OSS unloads index " + client.getIndexName());
         client.close();
       }
     } finally {
       clientsLock.r.unlock();
     }
     rendererResults.release();
   }
 }
  /**
   * Determine if a host is reachable by attempting to resolve the host name, and then attempting to
   * open a connection.
   *
   * @param hostName Name of the host to connect to.
   * @return {@code true} if a the host is reachable, {@code false} if the host name cannot be
   *     resolved, or if opening a connection to the host fails.
   */
  protected static boolean isHostReachable(String hostName) {
    try {
      // Assume host is unreachable if we can't get its dns entry without getting an exception
      //noinspection ResultOfMethodCallIgnored
      InetAddress.getByName(hostName);
    } catch (UnknownHostException e) {
      String message = Logging.getMessage("NetworkStatus.UnreachableTestHost", hostName);
      Logging.verbose(message);
      return false;
    } catch (Exception e) {
      String message = Logging.getMessage("NetworkStatus.ExceptionTestingHost", hostName);
      Logging.verbose(message);
      return false;
    }

    // Was able to get internet address, but host still might not be reachable because the address
    // might have been
    // cached earlier when it was available. So need to try something else.

    URLConnection connection = null;
    try {
      URL url = new URL("http://" + hostName);
      Proxy proxy = WWIO.configureProxy();
      if (proxy != null) connection = url.openConnection(proxy);
      else connection = url.openConnection();

      connection.setConnectTimeout(2000);
      connection.setReadTimeout(2000);
      String ct = connection.getContentType();
      if (ct != null) return true;
    } catch (IOException e) {
      String message = Logging.getMessage("NetworkStatus.ExceptionTestingHost", hostName);
      Logging.info(message);
    } finally {
      if (connection instanceof HttpURLConnection) ((HttpURLConnection) connection).disconnect();
    }

    return false;
  }