@Override public synchronized void close() throws IOException { if (this.fileChannel.isOpen()) { long start = System.nanoTime(); this.fileChannel.close(); this.fileLifecycleListener.onEvent(EventType.CLOSE, this.path, System.nanoTime() - start); } }
@Override public synchronized void close() throws IOException { if(this.fileChannel.isOpen()) { long start = System.nanoTime(); this.fileChannel.close(); this.fileLifecycleListener.onEvent(EventType.CLOSE, this.path, System.nanoTime() - start); } }
public void force() { long start = System.nanoTime(); this.buffer.force(); fileLifecycleListener.onEvent( FileLifecycleListener.EventType.SYNC, this.path, System.nanoTime() - start ); }
public void force() { long start = System.nanoTime(); this.buffer.force(); fileLifecycleListener.onEvent( FileLifecycleListener.EventType.SYNC, this.path, System.nanoTime() - start ); }
private synchronized MappedByteBuffer map(long address, long size) throws IOException { long start = System.nanoTime(); MappedByteBuffer buffer = this.fileChannel.map(this.mode.mapValue(), address, size); buffer.order(ByteOrder.nativeOrder()); fileLifecycleListener.onEvent(EventType.MMAP, path, System.nanoTime() - start); return buffer; } }
private synchronized MappedByteBuffer map(long address, long size) throws IOException { long start = System.nanoTime(); MappedByteBuffer buffer = this.fileChannel.map(this.mode.mapValue(),address,size); buffer.order(ByteOrder.nativeOrder()); fileLifecycleListener.onEvent(EventType.MMAP, path, System.nanoTime() - start); return buffer; }
private static FileChannel fileChannel(final File path, VanillaMappedMode mapMode, long size, FileLifecycleListener fileLifecycleListener) throws IOException { long start = System.nanoTime(); FileChannel fileChannel = null; try { final RandomAccessFile raf = new RandomAccessFile(path, mapMode.stringValue()); if (size > 0 && raf.length() != size) { if (mapMode.mapValue() != FileChannel.MapMode.READ_WRITE) { throw new IOException("Cannot resize file to " + size + " as mode is not READ_WRITE"); } raf.setLength(size); } fileChannel = raf.getChannel(); } catch (Exception e) { throw wrap(e); } fileLifecycleListener.onEvent(EventType.NEW, path, System.nanoTime() - start); return fileChannel; }
private static FileChannel fileChannel(final File path, VanillaMappedMode mapMode, long size, FileLifecycleListener fileLifecycleListener) throws IOException { long start = System.nanoTime(); FileChannel fileChannel = null; try { final RandomAccessFile raf = new RandomAccessFile(path, mapMode.stringValue()); if (size > 0 && raf.length() != size) { if (mapMode.mapValue() != FileChannel.MapMode.READ_WRITE) { throw new IOException("Cannot resize file to " + size + " as mode is not READ_WRITE"); } raf.setLength(size); } fileChannel = raf.getChannel(); } catch (Exception e) { throw wrap(e); } fileLifecycleListener.onEvent(EventType.NEW, path, System.nanoTime() - start); return fileChannel; }
@Override protected synchronized void cleanup() { if(!this.unmapped) { Cleaner cl = ((DirectBuffer)this.buffer).cleaner(); if (cl != null) { long start = System.nanoTime(); cl.clean(); fileLifecycleListener.onEvent( FileLifecycleListener.EventType.UNMAP, this.path, System.nanoTime() - start ); } try { if (this.channel != null && this.channel.isOpen()) { this.channel.close(); } } catch(IOException e) { throw new AssertionError(e); } this.unmapped = true; } super.cleanup(); }
@Override protected synchronized void cleanup() { if (!this.unmapped) { Cleaner cl = ((DirectBuffer) this.buffer).cleaner(); if (cl != null) { long start = System.nanoTime(); cl.clean(); fileLifecycleListener.onEvent( FileLifecycleListener.EventType.UNMAP, this.path, System.nanoTime() - start ); } try { if (this.channel != null && this.channel.isOpen()) { this.channel.close(); } } catch (IOException e) { throw new AssertionError(e); } this.unmapped = true; } super.cleanup(); }
public synchronized VanillaMappedBytes indexFor(int cycle, int indexCount, boolean forAppend) throws IOException { key.cycle = cycle; key.indexCount = indexCount; VanillaMappedBytes vmb = this.cache.get(key); if (vmb == null) { File file = this.indexFileMap.get(key); if (file == null) { this.indexFileMap.put( key.clone(), file = indexFileFor(cycle, indexCount, dateCache) ); } long start = System.nanoTime(); File parent = file.getParentFile(); if (forAppend && !VanillaChronicleUtils.exists(parent)) { parent.mkdirs(); } if (!forAppend && !VanillaChronicleUtils.exists(file)) { return null; } vmb = this.cache.put(key.clone(), file, 1L << blockBits, indexCount); fileLifecycleListener.onEvent(EventType.NEW, file, System.nanoTime() - start); } vmb.reserve(); return vmb; }
public synchronized VanillaMappedBytes dataFor(int cycle, int threadId, int dataCount, boolean forWrite) throws IOException { key.cycle = cycle; key.threadId = threadId; key.dataCount = dataCount; VanillaMappedBytes vmb = this.cache.get(key); if (vmb == null || vmb.refCount() < 1) { long start = System.nanoTime(); File file = VanillaChronicleUtils.mkFiles( dateCache.valueFor(cycle).path, FILE_NAME_PREFIX + threadId + "-" + dataCount, forWrite); vmb = this.cache.put(key.clone(), file, 1L << blockBits, dataCount); fileLifecycleListener.onEvent(EventType.NEW, file, System.nanoTime() - start); } vmb.reserve(); return vmb; }