@Override public synchronized void handleLargeMessageContinuation(final byte[] chunk, final int flowControlSize, final boolean isContinues) throws Exception { if (closing) { return; } if (currentLargeMessageController == null) { if (logger.isTraceEnabled()) { logger.trace(this + "::Sending back credits for largeController = null " + flowControlSize); } flowControl(flowControlSize, false); } else { currentLargeMessageController.addPacket(chunk, flowControlSize, isContinues); } }
currentLargeMessageController.addPacket(body, body.length, false);
@Override public synchronized void handleLargeMessageContinuation(final byte[] chunk, final int flowControlSize, final boolean isContinues) throws Exception { if (closing) { return; } if (currentLargeMessageController == null) { if (logger.isTraceEnabled()) { logger.trace(this + "::Sending back credits for largeController = null " + flowControlSize); } flowControl(flowControlSize, false); } else { currentLargeMessageController.addPacket(chunk, flowControlSize, isContinues); } }
@Override public synchronized void handleLargeMessageContinuation(final byte[] chunk, final int flowControlSize, final boolean isContinues) throws Exception { if (closing) { return; } if (currentLargeMessageController == null) { if (logger.isTraceEnabled()) { logger.trace(this + "::Sending back credits for largeController = null " + flowControlSize); } flowControl(flowControlSize, false); } else { currentLargeMessageController.addPacket(chunk, flowControlSize, isContinues); } }
@Override public synchronized void handleLargeMessageContinuation(final byte[] chunk, final int flowControlSize, final boolean isContinues) throws Exception { if (closing) { return; } if (currentLargeMessageController == null) { if (logger.isTraceEnabled()) { logger.trace(this + "::Sending back credits for largeController = null " + flowControlSize); } flowControl(flowControlSize, false); } else { currentLargeMessageController.addPacket(chunk, flowControlSize, isContinues); } }
@Override public synchronized void handleLargeMessageContinuation(final byte[] chunk, final int flowControlSize, final boolean isContinues) throws Exception { if (closing) { return; } if (currentLargeMessageController == null) { if (logger.isTraceEnabled()) { logger.trace(this + "::Sending back credits for largeController = null " + flowControlSize); } flowControl(flowControlSize, false); } else { currentLargeMessageController.addPacket(chunk, flowControlSize, isContinues); } }
@Override public synchronized void handleLargeMessageContinuation(final byte[] chunk, final int flowControlSize, final boolean isContinues) throws Exception { if (closing) { return; } if (currentLargeMessageController == null) { if (logger.isTraceEnabled()) { logger.trace(this + "::Sending back credits for largeController = null " + flowControlSize); } flowControl(flowControlSize, false); } else { currentLargeMessageController.addPacket(chunk, flowControlSize, isContinues); } }
@Override public synchronized void handleLargeMessageContinuation(final byte[] chunk, final int flowControlSize, final boolean isContinues) throws Exception { if (closing) { return; } if (currentLargeMessageController == null) { if (logger.isTraceEnabled()) { logger.trace(this + "::Sending back credits for largeController = null " + flowControlSize); } flowControl(flowControlSize, false); } else { currentLargeMessageController.addPacket(chunk, flowControlSize, isContinues); } }
private LargeMessageControllerImpl splitBuffer(final int splitFactor, final byte[] bytes, final File file) throws Exception { LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), bytes.length, 5000, file); ByteArrayInputStream input = new ByteArrayInputStream(bytes); while (true) { byte[] splitElement = new byte[splitFactor]; int size = input.read(splitElement); if (size <= 0) { break; } if (size < splitFactor) { byte[] newSplit = new byte[size]; System.arraycopy(splitElement, 0, newSplit, 0, size); outBuffer.addPacket(newSplit, 1, input.available() > 0); } else { outBuffer.addPacket(splitElement, 1, input.available() > 0); } } return outBuffer; }
@Test public void testErrorOnSetStreaming() throws Exception { long start = System.currentTimeMillis(); final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 5, 30000); outBuffer.addPacket(new byte[]{0, 1, 2, 3, 4}, 1, true); final CountDownLatch latchBytesWritten1 = new CountDownLatch(5); final CountDownLatch latchBytesWritten2 = new CountDownLatch(10); outBuffer.setOutputStream(new OutputStream() { @Override public void write(final int b) throws IOException { latchBytesWritten1.countDown(); latchBytesWritten2.countDown(); } }); ActiveMQTestBase.waitForLatch(latchBytesWritten1); try { outBuffer.readByte(); Assert.fail("supposed to throw an exception"); } catch (IllegalAccessError ignored) { } Assert.assertTrue("It waited too much", System.currentTimeMillis() - start < 30000); }
buffer.addPacket(new byte[]{0, 1, 2, 3, 4}, 1, true);
currentLargeMessageController.addPacket(body, body.length, false);
currentLargeMessageController.addPacket(body, body.length, false);
currentLargeMessageController.addPacket(body, body.length, false);
currentLargeMessageController.addPacket(body, body.length, false);
currentLargeMessageController.addPacket(body, body.length, false);
currentLargeMessageController.addPacket(body, body.length, false);
@Test public void testSplitBufferOnFile() throws Exception { LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 1024 * 1024, 1, getTestFile(), 1024); try { long count = 0; for (int i = 0; i < 10; i++) { byte[] buffer = new byte[10240]; for (int j = 0; j < 10240; j++) { buffer[j] = getSamplebyte(count++); } outBuffer.addPacket(buffer, 1, true); } outBuffer.readerIndex(0); for (int i = 0; i < 10240 * 10; i++) { assertEquals("position " + i, getSamplebyte(i), outBuffer.readByte()); } outBuffer.readerIndex(0); for (int i = 0; i < 10240 * 10; i++) { assertEquals("position " + i, getSamplebyte(i), outBuffer.readByte()); } } finally { outBuffer.close(); } }