org.agrona.IoUtil.mapExistingFile()方法的使用及代码示例

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

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

IoUtil.mapExistingFile介绍

[英]Check that file exists, open file, and return MappedByteBuffer for entire file

The file itself will be closed, but the mapping will persist.
[中]检查文件是否存在,打开文件,并返回整个文件的MappedByteBuffer
文件本身将被关闭,但映射将保持不变。

代码示例

代码示例来源:origin: real-logic/agrona

public static MappedByteBuffer mapExistingFile(
  final File markFile, final Consumer<String> logger, final long offset, final long length)
{
  if (markFile.exists())
  {
    if (null != logger)
    {
      logger.accept("INFO: Mark file exists: " + markFile);
    }
    return IoUtil.mapExistingFile(markFile, markFile.toString(), offset, length);
  }
  return null;
}

代码示例来源:origin: real-logic/aeron

/**
 * Map the CnC file if it exists.
 *
 * @param logger for feedback
 * @return a new mapping for the file if it exists otherwise null;
 */
public MappedByteBuffer mapExistingCncFile(final Consumer<String> logger)
{
  final File cncFile = new File(aeronDirectory, CncFileDescriptor.CNC_FILE);
  if (cncFile.exists() && cncFile.length() > 0)
  {
    if (null != logger)
    {
      logger.accept("INFO: Aeron CnC file exists: " + cncFile);
    }
    return IoUtil.mapExistingFile(cncFile, CncFileDescriptor.CNC_FILE);
  }
  return null;
}

代码示例来源:origin: real-logic/aeron

public static void main(final String[] args)
{
  final PrintStream out = System.out;
  if (args.length < 1)
  {
    out.println("Usage: SegmentInspector <segmentFileName> [dump limit in bytes per message]");
    return;
  }
  final String fileName = args[0];
  final int messageDumpLimit = args.length >= 2 ? Integer.parseInt(args[1]) : Integer.MAX_VALUE;
  final File file = new File(fileName);
  final ByteBuffer byteBuffer = IoUtil.mapExistingFile(file, "Archive Segment File");
  final UnsafeBuffer segmentBuffer = new UnsafeBuffer(byteBuffer);
  out.println("======================================================================");
  out.format("%s Inspection dump for %s%n", new Date(), fileName);
  out.println("======================================================================");
  out.println();
  dumpSegment(out, messageDumpLimit, segmentBuffer);
}

代码示例来源:origin: real-logic/aeron

public static void main(final String[] args)
{
  final String aeronDirectoryName = getProperty(AERON_DIR_PROP_NAME, AERON_DIR_PROP_DEFAULT);
  final File lossReportFile = LossReportUtil.file(aeronDirectoryName);
  if (!lossReportFile.exists())
  {
    System.err.print("Loss report does not exist: " + lossReportFile);
    System.exit(1);
  }
  final MappedByteBuffer mappedByteBuffer = IoUtil.mapExistingFile(lossReportFile, "Loss Report");
  final AtomicBuffer buffer = new UnsafeBuffer(mappedByteBuffer);
  System.out.println(
    "#OBSERVATION_COUNT, TOTAL_BYTES_LOST, FIRST_OBSERVATION," +
    " LAST_OBSERVATION, SESSION_ID, STREAM_ID, CHANNEL, SOURCE");
  final int entriesRead = LossReportReader.read(buffer, LossStat::accept);
  System.out.println(entriesRead + " entries read");
}

代码示例来源:origin: real-logic/aeron

/**
 * Is a media driver active in the given directory?
 *
 * @param directory       to check
 * @param driverTimeoutMs for the driver liveness check.
 * @param logger          for feedback as liveness checked.
 * @return true if a driver is active or false if not.
 */
public static boolean isDriverActive(
  final File directory, final long driverTimeoutMs, final Consumer<String> logger)
{
  final File cncFile = new File(directory, CncFileDescriptor.CNC_FILE);
  if (cncFile.exists() && cncFile.length() > 0)
  {
    logger.accept("INFO: Aeron CnC file exists: " + cncFile);
    final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "CnC file");
    try
    {
      return isDriverActive(driverTimeoutMs, logger, cncByteBuffer);
    }
    finally
    {
      IoUtil.unmap(cncByteBuffer);
    }
  }
  return false;
}

代码示例来源:origin: real-logic/aeron

public static void main(final String[] args)
{
  final File cncFile = CommonContext.newDefaultCncFile();
  System.out.println("Command `n Control file " + cncFile);
  final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
  final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
  final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
  if (CNC_VERSION != cncVersion)
  {
    throw new IllegalStateException(
      "Aeron CnC version does not match: version=" + cncVersion + " required=" + CNC_VERSION);
  }
  final AtomicBuffer buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
  final int distinctErrorCount = ErrorLogReader.read(buffer, ErrorStat::accept);
  System.out.format("%n%d distinct errors observed.%n", distinctErrorCount);
}

代码示例来源:origin: real-logic/aeron

public static void main(final String[] args) throws Exception
{
  if (args.length != 1)
  {
    System.out.println("Filename to be sent must be supplied as a command line argument");
    System.exit(1);
  }
  try (Aeron aeron = Aeron.connect();
    Publication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID))
  {
    while (!publication.isConnected())
    {
      Thread.sleep(1);
    }
    final File file = new File(args[0]);
    final UnsafeBuffer buffer = new UnsafeBuffer(IoUtil.mapExistingFile(file, "sending"));
    final long correlationId = aeron.nextCorrelationId();
    sendFileCreate(publication, correlationId, buffer.capacity(), file.getName());
    streamChunks(publication, correlationId, buffer);
  }
}

代码示例来源:origin: real-logic/aeron

public static CountersReader mapCounters()
{
  final File cncFile = CommonContext.newDefaultCncFile();
  System.out.println("Command `n Control file " + cncFile);
  final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
  final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
  final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));
  if (CncFileDescriptor.CNC_VERSION != cncVersion)
  {
    throw new IllegalStateException("CnC version not supported: file version=" + cncVersion);
  }
  return new CountersReader(
    createCountersMetaDataBuffer(cncByteBuffer, cncMetaData),
    createCountersValuesBuffer(cncByteBuffer, cncMetaData));
}

代码示例来源:origin: real-logic/aeron

public static CountersReader mapCounters()
{
  final File cncFile = CommonContext.newDefaultCncFile();
  System.out.println("Command `n Control file " + cncFile);
  final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
  final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
  final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));
  if (CNC_VERSION != cncVersion)
  {
    throw new IllegalStateException(
      "Aeron CnC version does not match: version=" + cncVersion + " required=" + CNC_VERSION);
  }
  return new CountersReader(
    createCountersMetaDataBuffer(cncByteBuffer, cncMetaData),
    createCountersValuesBuffer(cncByteBuffer, cncMetaData),
    StandardCharsets.US_ASCII);
}

代码示例来源:origin: real-logic/aeron

private static void printErrors(final PrintStream out, final ClusterMarkFile markFile)
{
  out.println("Cluster component error log:");
  ClusterMarkFile.saveErrorLog(out, markFile.errorBuffer());
  final String aeronDirectory = markFile.decoder().aeronDirectory();
  out.println("Aeron driver error log (directory: " + aeronDirectory + "):");
  final File cncFile = new File(aeronDirectory, CncFileDescriptor.CNC_FILE);
  final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
  final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
  final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
  if (CncFileDescriptor.CNC_VERSION != cncVersion)
  {
    throw new AeronException(
      "Aeron CnC version does not match: version=" + cncVersion +
        " required=" + CncFileDescriptor.CNC_VERSION);
  }
  final AtomicBuffer buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
  ClusterMarkFile.saveErrorLog(out, buffer);
}

代码示例来源:origin: real-logic/aeron

final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));

代码示例来源:origin: real-logic/aeron

/**
 * Map a {@link CountersReader} over the provided {@link File} for the CnC file.
 *
 * @param cncFile for the counters.
 * @return a {@link CountersReader} over the provided CnC file.
 */
public static CountersReader mapCounters(final File cncFile)
{
  final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
  final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
  final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));
  if (CncFileDescriptor.CNC_VERSION != cncVersion)
  {
    throw new AeronException(
      "Aeron CnC version does not match: version=" + cncVersion + " required=" + CNC_VERSION);
  }
  return new CountersReader(
    createCountersMetaDataBuffer(cncByteBuffer, cncMetaData),
    createCountersValuesBuffer(cncByteBuffer, cncMetaData),
    StandardCharsets.US_ASCII);
}

代码示例来源:origin: real-logic/artio

public static MappedByteBuffer mapExistingFile(final File file)
{
  return IoUtil.mapExistingFile(file, file.getName());
}

代码示例来源:origin: org.agrona/agrona

public static MappedByteBuffer mapExistingFile(
  final File markFile, final Consumer<String> logger, final long offset, final long length)
{
  if (markFile.exists())
  {
    if (null != logger)
    {
      logger.accept("INFO: Mark file exists: " + markFile);
    }
    return IoUtil.mapExistingFile(markFile, markFile.toString(), offset, length);
  }
  return null;
}

代码示例来源:origin: real-logic/artio

public static ByteBuffer map(final File file, final int size)
{
  if (file.exists())
  {
    return IoUtil.mapExistingFile(file, file.getName());
  }
  else
  {
    return mapNewFile(file, size);
  }
}

代码示例来源:origin: org.nd4j/nd4j-aeron

public static CountersReader mapCounters() {
  final File cncFile = CommonContext.newDefaultCncFile();
  System.out.println("Command `n Control file " + cncFile);
  final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
  final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
  final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));
  if (CncFileDescriptor.CNC_VERSION != cncVersion) {
    throw new IllegalStateException("CnC version not supported: file version=" + cncVersion);
  }
  return new CountersReader(createCountersMetaDataBuffer(cncByteBuffer, cncMetaData),
          createCountersValuesBuffer(cncByteBuffer, cncMetaData));
}

代码示例来源:origin: com.typesafe.akka/akka-remote_2.12

public AeronErrorLog(File cncFile, LoggingAdapter log) {
 cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
 final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
 final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
 buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
 if (CncFileDescriptor.CNC_VERSION != cncVersion) {
  log.warning(
    "Aeron CnC version mismatch: compiled version = {}, file version = {}",
    CncFileDescriptor.CNC_VERSION,
    cncVersion);
 }
}

代码示例来源:origin: com.typesafe.akka/akka-remote_2.11

public AeronErrorLog(File cncFile, LoggingAdapter log) {
 cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
 final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
 final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
 buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
 if (CncFileDescriptor.CNC_VERSION != cncVersion) {
  log.warning(
    "Aeron CnC version mismatch: compiled version = {}, file version = {}",
    CncFileDescriptor.CNC_VERSION,
    cncVersion);
 }
}

代码示例来源:origin: com.typesafe.akka/akka-remote

public AeronErrorLog(File cncFile, LoggingAdapter log) {
 cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
 final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
 final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
 buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
 if (CncFileDescriptor.CNC_VERSION != cncVersion) {
  log.warning(
    "Aeron CnC version mismatch: compiled version = {}, file version = {}",
    CncFileDescriptor.CNC_VERSION,
    cncVersion);
 }
}

代码示例来源:origin: io.aeron/aeron-all

private static void printErrors(final PrintStream out, final ClusterMarkFile markFile)
{
  out.println("Cluster component error log:");
  ClusterMarkFile.saveErrorLog(out, markFile.errorBuffer());
  final String aeronDirectory = markFile.decoder().aeronDirectory();
  out.println("Aeron driver error log (directory: " + aeronDirectory + "):");
  final File cncFile = new File(aeronDirectory, CncFileDescriptor.CNC_FILE);
  final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
  final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
  final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
  if (CncFileDescriptor.CNC_VERSION != cncVersion)
  {
    throw new AeronException(
      "Aeron CnC version does not match: version=" + cncVersion +
        " required=" + CncFileDescriptor.CNC_VERSION);
  }
  final AtomicBuffer buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
  ClusterMarkFile.saveErrorLog(out, buffer);
}

相关文章