@Override public File getJavaFile() { return getFile().getAbsoluteFile(); } }
@Override protected ByteBuffer newBuffer(int size, final int limit) { // For NIO, we don't need to allocate a buffer the entire size of the timed buffer, unlike AIO size = limit; return super.newBuffer(size, limit); }
@Override public void copyTo(SequentialFile newFileName) throws Exception { try { ActiveMQJournalLogger.LOGGER.debug("Copying " + this + " as " + newFileName); if (!newFileName.isOpen()) { newFileName.open(); } if (!isOpen()) { this.open(); } ByteBuffer buffer = ByteBuffer.allocate(10 * 1024); FileIOUtil.copyData(this, newFileName, buffer); newFileName.close(); this.close(); } catch (ClosedChannelException e) { throw e; } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } }
@Override public void flushBuffer(final ByteBuffer buffer, final boolean requestedSync, final List<IOCallback> callbacks) { buffer.flip(); if (buffer.limit() == 0) { factory.releaseBuffer(buffer); } else { writeDirect(buffer, requestedSync, new DelegateCallback(callbacks)); } }
@Override public synchronized void close() throws IOException, InterruptedException, ActiveMQException { super.close(); try { if (channel != null) { channel.close(); } } catch (ClosedChannelException e) { throw e; } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } channel = null; notifyAll(); }
@Override public void write(final ActiveMQBuffer bytes, final boolean sync) throws IOException, InterruptedException, ActiveMQException { if (sync) { SimpleWaitIOCallback completion = new SimpleWaitIOCallback(); write(bytes, true, completion); completion.waitCompletion(); } else { write(bytes, false, DummyCallback.getInstance()); } }
@Override public void position(final long pos) throws IOException { try { super.position(pos); channel.position(pos); } catch (ClosedChannelException e) { throw e; } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } }
@Override public void copyTo(SequentialFile newFileName) throws Exception { try { ActiveMQJournalLogger.LOGGER.debug("Copying " + this + " as " + newFileName); if (!newFileName.isOpen()) { newFileName.open(); } if (!isOpen()) { this.open(); } ByteBuffer buffer = ByteBuffer.allocate(10 * 1024); FileIOUtil.copyData(this, newFileName, buffer); newFileName.close(); this.close(); } catch (ClosedChannelException e) { throw e; } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } }
@Override public void flushBuffer(final ByteBuffer buffer, final boolean requestedSync, final List<IOCallback> callbacks) { buffer.flip(); if (buffer.limit() == 0) { factory.releaseBuffer(buffer); } else { writeDirect(buffer, requestedSync, new DelegateCallback(callbacks)); } }
@Override public final void renameTo(final String newFileName) throws IOException, InterruptedException, ActiveMQException { try { close(); } catch (ClosedChannelException e) { throw e; } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } File newFile = new File(directory + "/" + newFileName); if (!file.equals(newFile)) { if (!file.renameTo(newFile)) { throw ActiveMQJournalBundle.BUNDLE.ioRenameFileError(file.getName(), newFileName); } file = newFile; } }
@Override public void write(final EncodingSupport bytes, final boolean sync) throws InterruptedException, ActiveMQException { if (sync) { SimpleWaitIOCallback completion = new SimpleWaitIOCallback(); write(bytes, true, completion); completion.waitCompletion(); } else { write(bytes, false, DummyCallback.getInstance()); } }
@Override public void position(final long pos) throws IOException { try { super.position(pos); channel.position(pos); } catch (ClosedChannelException e) { throw e; } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } }
@Override public final void delete() throws IOException, InterruptedException, ActiveMQException { if (isOpen()) { close(); } try { Files.deleteIfExists(file.toPath()); } catch (Throwable t) { logger.trace("Fine error while deleting file", t); ActiveMQJournalLogger.LOGGER.errorDeletingFile(this); } }
@Override public void write(final EncodingSupport bytes, final boolean sync, final IOCallback callback) { if (timedBuffer != null) { timedBuffer.addBytes(bytes, sync, callback); } else { final int encodedSize = bytes.getEncodeSize(); ByteBuffer buffer = factory.newBuffer(encodedSize); ActiveMQBuffer outBuffer = ActiveMQBuffers.wrappedBuffer(buffer); bytes.encode(outBuffer); buffer.clear(); buffer.limit(encodedSize); writeDirect(buffer, sync, callback); } }
@Override public synchronized void close() throws IOException, InterruptedException, ActiveMQException { super.close(); try { if (channel != null) { channel.close(); } if (rfile != null) { rfile.close(); } } catch (ClosedChannelException e) { throw e; } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } channel = null; rfile = null; notifyAll(); }
@Override public void write(final ActiveMQBuffer bytes, final boolean sync) throws IOException, InterruptedException, ActiveMQException { if (sync) { SimpleWaitIOCallback completion = new SimpleWaitIOCallback(); write(bytes, true, completion); completion.waitCompletion(); } else { write(bytes, false, DummyCallback.getInstance()); } }
@Override public ByteBuffer newBuffer(final int size, final int limit) { return AbstractSequentialFile.this.newBuffer(size, limit); }
@Override public File getJavaFile() { return getFile().getAbsoluteFile(); } }
@Override public void write(final EncodingSupport bytes, final boolean sync, final IOCallback callback) { if (timedBuffer != null) { timedBuffer.addBytes(bytes, sync, callback); } else { final int encodedSize = bytes.getEncodeSize(); ByteBuffer buffer = factory.newBuffer(encodedSize); ActiveMQBuffer outBuffer = ActiveMQBuffers.wrappedBuffer(buffer); bytes.encode(outBuffer); buffer.clear(); buffer.limit(encodedSize); writeDirect(buffer, sync, callback); } }