@Override public SequentialFile getFile() throws ActiveMQException { validateFile(); return file; }
@Override public LargeBodyEncoder getBodyEncoder() throws ActiveMQException { validateFile(); return new DecodingContext(); }
@Override public synchronized void deleteFile() throws Exception { validateFile(); releaseResources(); storageManager.deleteLargeMessageFile(this); }
protected void openFile() throws Exception { if (file == null) { validateFile(); } else if (!file.isOpen()) { file.open(); } }
@Override public ActiveMQBuffer getReadOnlyBodyBuffer() { try { validateFile(); file.open(); int fileSize = (int) file.size(); ByteBuffer buffer = ByteBuffer.allocate(fileSize); file.read(buffer); return new ChannelBufferWrapper(Unpooled.wrappedBuffer(buffer)); } catch (Exception e) { throw new RuntimeException(e); } finally { try { file.close(); } catch (Exception ignored) { } } }
@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 LargeServerMessage createLargeMessage(final long id, final Message message) throws Exception { readLock(); try { if (isReplicated()) { replicator.largeMessageBegin(id); } LargeServerMessageImpl largeMessage = (LargeServerMessageImpl) createLargeMessage(); largeMessage.copyHeadersAndProperties(message); largeMessage.setMessageID(id); // We do this here to avoid a case where the replication gets a list without this file // to avoid a race largeMessage.validateFile(); if (largeMessage.isDurable()) { // We store a marker on the journal that the large file is pending long pendingRecordID = storePendingLargeMessage(id, LargeServerMessage.NO_PENDING_ID); largeMessage.setPendingRecordID(pendingRecordID); } return largeMessage; } finally { readUnLock(); } }