Java Code Examples for org.agrona.IoUtil#unmap()
The following examples show how to use
org.agrona.IoUtil#unmap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CncFileReader.java From aeron with Apache License 2.0 | 6 votes |
private CncFileReader(final MappedByteBuffer cncByteBuffer) { this.cncByteBuffer = cncByteBuffer; final DirectBuffer cncMetaDataBuffer = createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaDataBuffer.getInt(cncVersionOffset(0)); try { checkVersion(cncVersion); } catch (final AeronException e) { IoUtil.unmap(cncByteBuffer); throw e; } this.cncVersion = cncVersion; this.cncSemanticVersion = SemanticVersion.toString(cncVersion); this.toDriverBuffer = CncFileDescriptor.createToDriverBuffer(cncByteBuffer, cncMetaDataBuffer); this.countersReader = new CountersReader( createCountersMetaDataBuffer(cncByteBuffer, cncMetaDataBuffer), createCountersValuesBuffer(cncByteBuffer, cncMetaDataBuffer)); }
Example 2
Source File: FileReceiver.java From aeron with Apache License 2.0 | 6 votes |
private void fileChunk( final long correlationId, final long chunkOffset, final long chunkLength, final DirectBuffer buffer, final int offset) { final UnsafeBuffer fileBuffer = fileSessionByIdMap.get(correlationId); buffer.getBytes(offset + CHUNK_PAYLOAD_OFFSET, fileBuffer, (int)chunkOffset, (int)chunkLength); if ((chunkOffset + chunkLength) >= fileBuffer.capacity()) { fileSessionByIdMap.remove(correlationId); IoUtil.unmap(fileBuffer.byteBuffer()); } }
Example 3
Source File: LogBuffers.java From aeron with Apache License 2.0 | 6 votes |
public void close() { Throwable error = null; try { CloseHelper.close(fileChannel); } catch (final Throwable t) { error = t; } for (int i = 0, length = mappedByteBuffers.length; i < length; i++) { final MappedByteBuffer mappedByteBuffer = mappedByteBuffers[i]; mappedByteBuffers[i] = null; IoUtil.unmap(mappedByteBuffer); } if (error != null) { LangUtil.rethrowUnchecked(error); } }
Example 4
Source File: DistinctErrorLogTestWatcher.java From aeron with Apache License 2.0 | 6 votes |
public void captureErrors(final String aeronDirectoryName) { final File cncFile = CommonContext.newCncFile(aeronDirectoryName); assertTrue(cncFile.exists()); MappedByteBuffer cncByteBuffer = null; try (RandomAccessFile file = new RandomAccessFile(cncFile, "r"); FileChannel channel = file.getChannel()) { cncByteBuffer = channel.map(READ_ONLY, 0, channel.size()); final AtomicBuffer errorLogBuffer = CommonContext.errorLogBuffer(cncByteBuffer); ErrorLogReader.read(errorLogBuffer, this::onObservation); } catch (final IOException ex) { ex.printStackTrace(); } finally { IoUtil.unmap(cncByteBuffer); } }
Example 5
Source File: LossReportTestUtil.java From aeron with Apache License 2.0 | 5 votes |
public static void verifyLossOccurredForStream(final String aeronDirectoryName, final int streamId) throws IOException { final File lossReportFile = LossReportUtil.file(aeronDirectoryName); assertTrue(lossReportFile.exists()); MappedByteBuffer mappedByteBuffer = null; try (RandomAccessFile file = new RandomAccessFile(lossReportFile, "r"); FileChannel channel = file.getChannel()) { mappedByteBuffer = channel.map(READ_ONLY, 0, channel.size()); final AtomicBuffer buffer = new UnsafeBuffer(mappedByteBuffer); final LossReportReader.EntryConsumer lossEntryConsumer = mock(LossReportReader.EntryConsumer.class); LossReportReader.read(buffer, lossEntryConsumer); verify(lossEntryConsumer).accept( longThat((l) -> l > 0), longThat((l) -> l > 0), anyLong(), anyLong(), anyInt(), eq(streamId), any(), any()); } finally { IoUtil.unmap(mappedByteBuffer); } }
Example 6
Source File: CncFileReader.java From aeron with Apache License 2.0 | 5 votes |
public void close() { if (!isClosed) { isClosed = true; IoUtil.unmap(cncByteBuffer); } }
Example 7
Source File: CommonContext.java From aeron with Apache License 2.0 | 5 votes |
/** * Read the error log to a given {@link PrintStream} * * @param out to write the error log contents to. * @return the number of observations from the error log. */ public int saveErrorLog(final PrintStream out) { final MappedByteBuffer cncByteBuffer = mapExistingCncFile(null); try { return saveErrorLog(out, cncByteBuffer); } finally { IoUtil.unmap(cncByteBuffer); } }
Example 8
Source File: CommonContext.java From aeron with Apache License 2.0 | 5 votes |
/** * Request a driver to run its termination hook. * * @param directory for the driver. * @param tokenBuffer containing the optional token for the request. * @param tokenOffset within the tokenBuffer at which the token begins. * @param tokenLength of the token in the tokenBuffer. * @return true if request was sent or false if request could not be sent. */ public static boolean requestDriverTermination( final File directory, final DirectBuffer tokenBuffer, final int tokenOffset, final int tokenLength) { final File cncFile = new File(directory, CncFileDescriptor.CNC_FILE); if (cncFile.exists() && cncFile.length() > 0) { final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "CnC file"); try { final UnsafeBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaDataBuffer.getIntVolatile(cncVersionOffset(0)); CncFileDescriptor.checkVersion(cncVersion); final ManyToOneRingBuffer toDriverBuffer = new ManyToOneRingBuffer( CncFileDescriptor.createToDriverBuffer(cncByteBuffer, cncMetaDataBuffer)); final long clientId = toDriverBuffer.nextCorrelationId(); final DriverProxy driverProxy = new DriverProxy(toDriverBuffer, clientId); return driverProxy.terminateDriver(tokenBuffer, tokenOffset, tokenLength); } finally { IoUtil.unmap(cncByteBuffer); } } return false; }
Example 9
Source File: CommonContext.java From aeron with Apache License 2.0 | 5 votes |
/** * Is a media driver active in the current Aeron directory? * * @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 boolean isDriverActive(final long driverTimeoutMs, final Consumer<String> logger) { final MappedByteBuffer cncByteBuffer = mapExistingCncFile(logger); try { return isDriverActive(driverTimeoutMs, logger, cncByteBuffer); } finally { IoUtil.unmap(cncByteBuffer); } }
Example 10
Source File: RecordingSessionTest.java From aeron with Apache License 2.0 | 5 votes |
@AfterEach public void after() { IoUtil.unmap(mockLogBufferMapped.byteBuffer()); CloseHelper.close(mockLogBufferChannel); IoUtil.delete(archiveDir, false); IoUtil.delete(termFile, false); }
Example 11
Source File: MappedRawLog.java From aeron with Apache License 2.0 | 5 votes |
public boolean free() { final MappedByteBuffer[] mappedBuffers = this.mappedBuffers; if (null != mappedBuffers) { for (int i = 0; i < mappedBuffers.length; i++) { final MappedByteBuffer buffer = mappedBuffers[i]; mappedBuffers[i] = null; IoUtil.unmap(buffer); } this.mappedBuffers = null; } if (null != logFile) { if (!logFile.delete()) { return false; } logFile = null; } return true; }
Example 12
Source File: ReplayQuery.java From artio with Apache License 2.0 | 5 votes |
public void close() { if (wrappedBuffer instanceof MappedByteBuffer) { IoUtil.unmap((MappedByteBuffer)wrappedBuffer); } }
Example 13
Source File: RecordingCoordinator.java From artio with Apache License 2.0 | 5 votes |
private void loadRecordingIdsFile() { if (recordingIdsFile.exists()) { final MappedByteBuffer mappedBuffer = IoUtil.mapExistingFile(recordingIdsFile, FILE_NAME); final UnsafeBuffer buffer = new UnsafeBuffer(mappedBuffer); try { final MessageHeaderDecoder header = new MessageHeaderDecoder(); final PreviousRecordingDecoder previousRecording = new PreviousRecordingDecoder(); header.wrap(buffer, 0); previousRecording.wrap(buffer, ENCODED_LENGTH, header.blockLength(), header.version()); for (final InboundRecordingsDecoder inboundRecording : previousRecording.inboundRecordings()) { inboundRecordingIds.free.add(inboundRecording.recordingId()); } for (final OutboundRecordingsDecoder outboundRecording : previousRecording.outboundRecordings()) { outboundRecordingIds.free.add(outboundRecording.recordingId()); } } finally { IoUtil.unmap(mappedBuffer); } } }
Example 14
Source File: MappedFile.java From artio with Apache License 2.0 | 4 votes |
public void close() { IoUtil.unmap(buffer.byteBuffer()); CloseHelper.close(fileChannel); }
Example 15
Source File: MappedResizeableBuffer.java From agrona with Apache License 2.0 | 4 votes |
private void unmap() { IoUtil.unmap(fileChannel, addressOffset, capacity); }
Example 16
Source File: MonitoringFile.java From artio with Apache License 2.0 | 4 votes |
public void close() { IoUtil.unmap(mappedByteBuffer); CloseChecker.onClose(absolutePath, this); }
Example 17
Source File: HistogramLogReader.java From artio with Apache License 2.0 | 4 votes |
public void close() { IoUtil.unmap(buffer); CloseHelper.close(channel); }
Example 18
Source File: ReplayIndex.java From artio with Apache License 2.0 | 4 votes |
public void close() { IoUtil.unmap(wrappedBuffer); }
Example 19
Source File: ReplayIndex.java From artio with Apache License 2.0 | 4 votes |
public void close() { positionWriter.close(); fixSessionIdToIndex.clear(); IoUtil.unmap(positionBuffer.byteBuffer()); }
Example 20
Source File: RecordingCoordinator.java From artio with Apache License 2.0 | 4 votes |
private void saveRecordingIdsFile() { libraryIdToExtendPosition.values().forEach(pos -> outboundRecordingIds.free.add(pos.recordingId)); try { final int inboundSize = inboundRecordingIds.size(); final int outboundSize = outboundRecordingIds.size(); final File saveFile = File.createTempFile(FILE_NAME, "tmp", new File(configuration.logFileDir())); final int requiredLength = MessageHeaderEncoder.ENCODED_LENGTH + PreviousRecordingEncoder.BLOCK_LENGTH + InboundRecordingsEncoder.HEADER_SIZE + OutboundRecordingsEncoder.HEADER_SIZE + InboundRecordingsEncoder.recordingIdEncodingLength() * inboundSize + OutboundRecordingsEncoder.recordingIdEncodingLength() * outboundSize; final MappedByteBuffer mappedBuffer = IoUtil.mapExistingFile(saveFile, FILE_NAME, 0, requiredLength); final UnsafeBuffer buffer = new UnsafeBuffer(mappedBuffer); try { final MessageHeaderEncoder header = new MessageHeaderEncoder(); final PreviousRecordingEncoder previousRecording = new PreviousRecordingEncoder(); previousRecording.wrapAndApplyHeader(buffer, 0, header); final InboundRecordingsEncoder inbound = previousRecording.inboundRecordingsCount(inboundSize); inboundRecordingIds.forEach(id -> inbound.next().recordingId(id)); final OutboundRecordingsEncoder outbound = previousRecording.outboundRecordingsCount(outboundSize); outboundRecordingIds.forEach(id -> outbound.next().recordingId(id)); mappedBuffer.force(); } finally { IoUtil.unmap(mappedBuffer); } Files.move(saveFile.toPath(), recordingIdsFile.toPath(), ATOMIC_MOVE, REPLACE_EXISTING); } catch (final Throwable e) { e.printStackTrace(); errorHandler.onError(e); } }