@Override public boolean isOpen() { return this.sequentialFile.isOpen(); }
@Override public boolean isOpen() { return this.sequentialFile.isOpen(); }
protected void closeFile() throws Exception { if (file != null && file.isOpen()) { file.close(); } }
@Override public void copyTo(SequentialFile dstFile) throws IOException { checkIsNotOpen(); if (dstFile.isOpen()) { throw new IllegalArgumentException("dstFile must be closed too"); } SequentialFile.appendTo(file.toPath(), dstFile.getJavaFile().toPath()); }
/** * @throws Exception */ private void deleteAppendFile() throws Exception { if (appendFile != null) { if (appendFile.isOpen()) appendFile.close(); appendFile.delete(); } }
@Override public synchronized void releaseResources() { if (logger.isTraceEnabled()) { logger.trace("release resources called on " + mainLM, new Exception("trace")); } mainLM.releaseResources(); if (appendFile != null && appendFile.isOpen()) { try { appendFile.close(); } catch (Exception e) { ActiveMQServerLogger.LOGGER.largeMessageErrorReleasingResources(e); } } }
protected void openFile() throws Exception { if (file == null) { validateFile(); } else if (!file.isOpen()) { file.open(); } }
@Override protected void finalize() { try { if (file != null && file.isOpen()) { file.close(false); } } catch (Exception e) { ActiveMQServerLogger.LOGGER.pageFinaliseError(e); } }
public void open() throws Exception { if (!file.isOpen()) { file.open(); } size.set((int) file.size()); file.position(0); }
@Override public void stop() throws Exception { if (currentFile.getFile().isOpen()) currentFile.getFile().close(); }
@Override public void copyTo(SequentialFile dstFile) throws IOException { if (ActiveMQJournalLogger.LOGGER.isDebugEnabled()) { ActiveMQJournalLogger.LOGGER.debug("Copying " + this + " as " + dstFile); } if (isOpen()) { throw new IllegalStateException("File opened!"); } if (dstFile.isOpen()) { throw new IllegalArgumentException("dstFile must be closed too"); } SequentialFile.appendTo(getFile().toPath(), dstFile.getJavaFile().toPath()); } }
@Override public synchronized void releaseResources() { if (file != null && file.isOpen()) { try { file.sync(); file.close(); } catch (Exception e) { ActiveMQServerLogger.LOGGER.largeMessageErrorReleasingResources(e); } } }
@Override public void stop() throws Exception { if (currentFile.getFile().isOpen()) currentFile.getFile().close(); }
@Override public void open() throws ActiveMQException { try { if (cFile != null && cFile.isOpen()) { cFile.close(); } cFile = file.cloneFile(); cFile.open(); } catch (Exception e) { throw new ActiveMQException(ActiveMQExceptionType.INTERNAL_ERROR, e.getMessage(), e); } }
@Override public synchronized void addBytes(byte[] bytes) throws Exception { if (deleted) return; if (syncDone) { if (logger.isTraceEnabled()) { logger.trace("Adding " + bytes.length + " towards sync message::" + mainLM); } mainLM.addBytes(bytes); return; } if (logger.isTraceEnabled()) { logger.trace("addBytes(bytes.length=" + bytes.length + ") on message=" + mainLM); } if (appendFile == null) { appendFile = storageManager.createFileForLargeMessage(mainLM.getMessageID(), LargeMessageExtension.SYNC); } if (!appendFile.isOpen()) { appendFile.open(); } storageManager.addBytesToLargeMessage(appendFile, mainLM.getMessageID(), bytes); }
@Override public synchronized void addBytes(final byte[] bytes) throws Exception { validateFile(); if (!file.isOpen()) { file.open(); } storageManager.addBytesToLargeMessage(file, getMessageID(), bytes); bodySize += bytes.length; }
@Override public synchronized void addBytes(final ActiveMQBuffer bytes) throws Exception { validateFile(); if (!file.isOpen()) { file.open(); } final int readableBytes = bytes.readableBytes(); storageManager.addBytesToLargeMessage(file, getMessageID(), bytes); bodySize += readableBytes; }
@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 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; } }
/** * Sends the whole content of the file to be duplicated. * * @throws ActiveMQException * @throws Exception */ public void syncJournalFile(JournalFile jf, AbstractJournalStorageManager.JournalContent content) throws Exception { if (!enabled) { return; } SequentialFile file = jf.getFile().cloneFile(); try { ActiveMQServerLogger.LOGGER.replicaSyncFile(file, file.size()); sendLargeFile(content, null, jf.getFileID(), file, Long.MAX_VALUE); } finally { if (file.isOpen()) file.close(); } }