com.thinkaurelius.titan.util.system.IOUtils.closeQuietly()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中com.thinkaurelius.titan.util.system.IOUtils.closeQuietly()方法的一些代码示例,展示了IOUtils.closeQuietly()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.closeQuietly()方法的具体详情如下:
包路径:com.thinkaurelius.titan.util.system.IOUtils
类名称:IOUtils
方法名:closeQuietly

IOUtils.closeQuietly介绍

暂无

代码示例

代码示例来源:origin: thinkaurelius/titan

@Override
public void close() {
  IOUtils.closeQuietly(table);
  isClosed = true;
  logger.debug("RowIterator closed table {}", table);
}

代码示例来源:origin: thinkaurelius/titan

@Override
public void close() {
  openStores.clear();
  if (logger.isTraceEnabled())
    openManagers.remove(this);
  IOUtils.closeQuietly(cnx);
}

代码示例来源:origin: thinkaurelius/titan

public static ScanMetrics hbaseRemove(String titanPropertiesPath, String indexName, String relationType)
    throws InterruptedException, IOException, ClassNotFoundException {
  Properties p = new Properties();
  FileInputStream fis = null;
  try {
    fis = new FileInputStream(titanPropertiesPath);
    p.load(fis);
    return hbaseRemove(p, indexName, relationType);
  } finally {
    IOUtils.closeQuietly(fis);
  }
}

代码示例来源:origin: thinkaurelius/titan

public static ScanMetrics cassandraRepair(String titanPropertiesPath, String indexName, String relationType, String partitionerName)
    throws InterruptedException, IOException, ClassNotFoundException {
  Properties p = new Properties();
  FileInputStream fis = null;
  try {
    fis = new FileInputStream(titanPropertiesPath);
    p.load(fis);
    return cassandraRepair(p, indexName, relationType, partitionerName);
  } finally {
    IOUtils.closeQuietly(fis);
  }
}

代码示例来源:origin: thinkaurelius/titan

public static ScanMetrics hbaseRepair(String titanPropertiesPath, String indexName, String relationType)
    throws InterruptedException, IOException, ClassNotFoundException {
  Properties p = new Properties();
  FileInputStream fis = null;
  try {
    fis = new FileInputStream(titanPropertiesPath);
    p.load(fis);
    return hbaseRepair(p, indexName, relationType);
  } finally {
    IOUtils.closeQuietly(fis);
  }
}

代码示例来源:origin: thinkaurelius/titan

@Override
public synchronized void close() throws BackendException {
  /* Copying the map is necessary to avoid ConcurrentModificationException.
   * The path to ConcurrentModificationException in the absence of a copy is
   * log.close() -> manager.closedLog(log) -> openLogs.remove(log.getName()).
   */
  for (KCVSLog log : ImmutableMap.copyOf(openLogs).values()) log.close();
  IOUtils.closeQuietly(serializer);
}

代码示例来源:origin: thinkaurelius/titan

public static ScanMetrics cassandraRemove(String titanPropertiesPath, String indexName, String relationType, String partitionerName)
    throws InterruptedException, IOException, ClassNotFoundException {
  Properties p = new Properties();
  FileInputStream fis = null;
  try {
    fis = new FileInputStream(titanPropertiesPath);
    p.load(fis);
    return cassandraRemove(p, indexName, relationType, partitionerName);
  } finally {
    IOUtils.closeQuietly(fis);
  }
}

代码示例来源:origin: thinkaurelius/titan

static void applySettingsFromFile(ImmutableSettings.Builder settings,
                     Configuration config,
                     ConfigOption<String> confFileOption) throws FileNotFoundException {
  if (config.has(confFileOption)) {
    String confFile = config.get(confFileOption);
    log.debug("Loading Elasticsearch settings from file {}", confFile);
    InputStream confStream = null;
    try {
      confStream = new FileInputStream(confFile);
      settings.loadFromStream(confFile, confStream);
    } finally {
      IOUtils.closeQuietly(confStream);
    }
  } else {
    log.debug("Option {} is not set; not attempting to load Elasticsearch settings from file", confFileOption);
  }
}

代码示例来源:origin: thinkaurelius/titan

@Override
public List<KeyRange> getLocalKeyPartition() throws BackendException {
  List<KeyRange> result = new LinkedList<KeyRange>();
  HTable table = null;
  try {
    ensureTableExists(tableName, getCfNameForStoreName(GraphDatabaseConfiguration.SYSTEM_PROPERTIES_STORE_NAME), 0);
    table = new HTable(hconf, tableName);
    Map<KeyRange, ServerName> normed =
        normalizeKeyBounds(table.getRegionLocations());
    for (Map.Entry<KeyRange, ServerName> e : normed.entrySet()) {
      if (NetworkUtil.isLocalConnection(e.getValue().getHostname())) {
        result.add(e.getKey());
        logger.debug("Found local key/row partition {} on host {}", e.getKey(), e.getValue());
      } else {
        logger.debug("Discarding remote {}", e.getValue());
      }
    }
  } catch (MasterNotRunningException e) {
    logger.warn("Unexpected MasterNotRunningException", e);
  } catch (ZooKeeperConnectionException e) {
    logger.warn("Unexpected ZooKeeperConnectionException", e);
  } catch (IOException e) {
    logger.warn("Unexpected IOException", e);
  } finally {
    IOUtils.closeQuietly(table);
  }
  return result;
}

代码示例来源:origin: thinkaurelius/titan

@Override
public void close() {
  try {
    store.close();
    txProvider.close();
    IOUtils.closeQuietly(serializer);
  } catch (BackendException e) {
    throw new TitanException("Could not close configuration store",e);
  }
}

代码示例来源:origin: thinkaurelius/titan

public static HBaseStatus write(String path, String hbaseVersion) {
  File f = new File(path);
  FileOutputStream fos = null;
  try {
    fos = new FileOutputStream(path);
    fos.write(String.format("%s", hbaseVersion).getBytes());
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    IOUtils.closeQuietly(fos);
  }
  return new HBaseStatus(f, hbaseVersion);
}

代码示例来源:origin: thinkaurelius/titan

public static ElasticsearchStatus write(String path, int pid) {
  File f = new File(path);
  FileOutputStream fos = null;
  try {
    fos = new FileOutputStream(path);
    fos.write(String.format("%d", pid).getBytes());
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    IOUtils.closeQuietly(fos);
  }
  return new ElasticsearchStatus(f, pid);
}

代码示例来源:origin: thinkaurelius/titan

public static ElasticsearchStatus read(String path) {
  File pid = new File(path);
  if (!pid.exists()) {
    log.info("ES pidfile {} does not exist", path);
    return null;
  }
  BufferedReader pidReader = null;
  try {
    pidReader = new BufferedReader(new FileReader(pid));
    ElasticsearchStatus s = parsePidFile(pid, pidReader);
    log.info("Read ES pid {} from {}", pid, path);
    return s;
  } catch (IOException e) {
    log.warn("Assuming ES is not running", e);
  } finally {
    IOUtils.closeQuietly(pidReader);
  }
  return null;
}

代码示例来源:origin: thinkaurelius/titan

public static HBaseStatus read(String path) {
  File pid = new File(path);
  if (!pid.exists()) {
    log.info("HBase pidfile {} does not exist", path);
    return null;
  }
  BufferedReader pidReader = null;
  try {
    pidReader = new BufferedReader(new FileReader(pid));
    HBaseStatus s = parsePidFile(pid, pidReader);
    log.info("Read HBase status from {}", path);
    return s;
  } catch (HBasePidfileParseException e) {
    log.warn("Assuming HBase is not running", e);
  } catch (IOException e) {
    log.warn("Assuming HBase is not running", e);
  } finally {
    IOUtils.closeQuietly(pidReader);
  }
  return null;
}

代码示例来源:origin: thinkaurelius/titan

private void watchLog(String suffix, long duration, TimeUnit unit) throws InterruptedException {
  long startMS = System.currentTimeMillis();
  long durationMS = TimeUnit.MILLISECONDS.convert(duration, unit);
  long elapsedMS;
  File logFile = new File(homedir + File.separator + "target" + File.separator
      + "es-logs" + File.separator + "elasticsearch.log");
  log.info("Watching ES logfile {} for {} token", logFile, suffix);
  while ((elapsedMS = System.currentTimeMillis() - startMS) < durationMS) {
    // Grep for a logline ending in the suffix and assume that means ES is ready
    BufferedReader br = null;
    try {
      br = new BufferedReader(new FileReader(logFile));
      String line;
      while (null != (line = br.readLine())) {
        if (line.endsWith(suffix)) {
          log.debug("Read line \"{}\" from ES logfile {}", line, logFile);
          return;
        }
      }
    } catch (FileNotFoundException e) {
      log.debug("Elasticsearch logfile {} not found", logFile, e);
    } catch (IOException e) {
      log.debug("Elasticsearch logfile {} could not be read", logFile, e);
    } finally {
      IOUtils.closeQuietly(br);
    }
    Thread.sleep(500L);
  }
  log.info("Elasticsearch logfile timeout ({} {})", elapsedMS, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: thinkaurelius/titan

IOUtils.closeQuietly(scanner);
IOUtils.closeQuietly(table);

代码示例来源:origin: thinkaurelius/titan

IOUtils.closeQuietly(scanner);
IOUtils.closeQuietly(table);

代码示例来源:origin: thinkaurelius/titan

table.batch(batch, new Object[batch.size()]);
} finally {
  IOUtils.closeQuietly(table);

代码示例来源:origin: thinkaurelius/titan

private KeyIterator executeKeySliceQuery(@Nullable byte[] startKey,
                    @Nullable byte[] endKey,
                    FilterList filters,
                    @Nullable SliceQuery columnSlice) throws BackendException {
  Scan scan = new Scan().addFamily(columnFamilyBytes);
  try {
    scan.setTimeRange(0, Long.MAX_VALUE);
  } catch (IOException e) {
    throw new PermanentBackendException(e);
  }
  if (startKey != null)
    scan.setStartRow(startKey);
  if (endKey != null)
    scan.setStopRow(endKey);
  if (columnSlice != null) {
    filters.addFilter(getFilter(columnSlice));
  }
  TableMask table = null;
  try {
    table = cnx.getTable(tableName);
    return new RowIterator(table, table.getScanner(scan.setFilter(filters)), columnFamilyBytes);
  } catch (IOException e) {
    IOUtils.closeQuietly(table);
    throw new PermanentBackendException(e);
  }
}

代码示例来源:origin: thinkaurelius/titan

private HTableDescriptor ensureTableExists(String tableName, String initialCFName, int ttlInSeconds) throws BackendException {
  AdminMask adm = null;
  HTableDescriptor desc;
  try { // Create our table, if necessary
    adm = getAdminInterface();
    /*
     * Some HBase versions/impls respond badly to attempts to create a
     * table without at least one CF. See #661. Creating a CF along with
     * the table avoids HBase carping.
     */
    if (adm.tableExists(tableName)) {
      desc = adm.getTableDescriptor(tableName);
    } else {
      desc = createTable(tableName, initialCFName, ttlInSeconds, adm);
    }
  } catch (IOException e) {
    throw new TemporaryBackendException(e);
  } finally {
    IOUtils.closeQuietly(adm);
  }
  return desc;
}

相关文章