@Override public void write(ActiveMQBuffer bytes, boolean sync, IOCallback callback) throws Exception { if (this.timedBuffer != null) { this.timedBuffer.addBytes(bytes, sync, callback); } else { this.sequentialFile.write(bytes, sync, callback); } }
@Override public void write(ActiveMQBuffer bytes, boolean sync, IOCallback callback) throws Exception { if (this.timedBuffer != null) { this.timedBuffer.addBytes(bytes, sync, callback); } else { this.sequentialFile.write(bytes, sync, callback); } }
@Override public void write(EncodingSupport bytes, boolean sync, IOCallback callback) throws Exception { if (this.timedBuffer != null) { this.timedBuffer.addBytes(bytes, sync, callback); } else { this.sequentialFile.write(bytes, sync, callback); } }
@Override public void write(EncodingSupport bytes, boolean sync, IOCallback callback) throws Exception { if (this.timedBuffer != null) { this.timedBuffer.addBytes(bytes, sync, callback); } else { this.sequentialFile.write(bytes, sync, callback); } }
@Override public void write(ActiveMQBuffer bytes, boolean sync) throws Exception { if (sync) { if (this.timedBuffer != null) { //the only way to avoid allocations is by using a lock-free pooled callback -> CyclicBarrier allocates on each new Generation!!! final SimpleWaitIOCallback callback = new SimpleWaitIOCallback(); this.timedBuffer.addBytes(bytes, true, callback); callback.waitCompletion(); } else { this.sequentialFile.write(bytes, true); } } else { if (this.timedBuffer != null) { this.timedBuffer.addBytes(bytes, false, DummyCallback.getInstance()); } else { this.sequentialFile.write(bytes, false); } } }
@Override public void write(EncodingSupport bytes, boolean sync) throws Exception { if (sync) { if (this.timedBuffer != null) { //the only way to avoid allocations is by using a lock-free pooled callback -> CyclicBarrier allocates on each new Generation!!! final SimpleWaitIOCallback callback = new SimpleWaitIOCallback(); this.timedBuffer.addBytes(bytes, true, callback); callback.waitCompletion(); } else { this.sequentialFile.write(bytes, true); } } else { if (this.timedBuffer != null) { this.timedBuffer.addBytes(bytes, false, DummyCallback.getInstance()); } else { this.sequentialFile.write(bytes, false); } } }
@Override public void write(EncodingSupport bytes, boolean sync) throws Exception { if (sync) { if (this.timedBuffer != null) { //the only way to avoid allocations is by using a lock-free pooled callback -> CyclicBarrier allocates on each new Generation!!! final SimpleWaitIOCallback callback = new SimpleWaitIOCallback(); this.timedBuffer.addBytes(bytes, true, callback); callback.waitCompletion(); } else { this.sequentialFile.write(bytes, true); } } else { if (this.timedBuffer != null) { this.timedBuffer.addBytes(bytes, false, DummyCallback.getInstance()); } else { this.sequentialFile.write(bytes, false); } } }
@Override public void write(ActiveMQBuffer bytes, boolean sync) throws Exception { if (sync) { if (this.timedBuffer != null) { //the only way to avoid allocations is by using a lock-free pooled callback -> CyclicBarrier allocates on each new Generation!!! final SimpleWaitIOCallback callback = new SimpleWaitIOCallback(); this.timedBuffer.addBytes(bytes, true, callback); callback.waitCompletion(); } else { this.sequentialFile.write(bytes, true); } } else { if (this.timedBuffer != null) { this.timedBuffer.addBytes(bytes, false, DummyCallback.getInstance()); } else { this.sequentialFile.write(bytes, false); } } }
@Override public void run() { try { SequentialFile file = factory.createSequentialFile("file.txt"); file.open(); file.write(fakeEncoding, true); Thread.currentThread().interrupt(); file.close(); } catch (Exception e) { e.printStackTrace(); } } };
@Override public void run() { try { SequentialFile file = factory.createSequentialFile("file.txt"); file.open(); Thread.currentThread().interrupt(); file.write(fakeEncoding, true); file.close(); } catch (Exception e) { e.printStackTrace(); } } };
@Override public void run() { try { SequentialFile file = factory.createSequentialFile("file.txt"); file.open(); file.write(fakeEncoding, true); Thread.currentThread().interrupt(); file.close(); } catch (Exception e) { e.printStackTrace(); } } };
@Override public void run() { try { SequentialFile file = factory.createSequentialFile("file.txt"); file.open(); Thread.currentThread().interrupt(); file.write(fakeEncoding, true); file.close(); } catch (Exception e) { e.printStackTrace(); } } };
@Override public void run() { try { SequentialFile file = factory.createSequentialFile("file.txt"); file.open(); file.write(fakeEncoding, true); file.position(0); ByteBuffer readBytes = ByteBuffer.allocate(fakeEncoding.getEncodeSize()); Thread.currentThread().interrupt(); file.read(readBytes); file.close(); } catch (Exception e) { e.printStackTrace(); } } };
@Override public void run() { try { SequentialFile file = factory.createSequentialFile("file.txt"); file.open(); file.write(fakeEncoding, true); file.position(0); ByteBuffer readBytes = ByteBuffer.allocate(fakeEncoding.getEncodeSize()); Thread.currentThread().interrupt(); file.read(readBytes); file.close(); } catch (Exception e) { e.printStackTrace(); } } };
@Override public synchronized SequentialFileFactory newFileFactory(final SimpleString address) throws Exception { String tableName = "" + storageManager.generateID(); SequentialFileFactory factory = newFileFactory(tableName, true); factory.start(); SequentialFile file = factory.createSequentialFile(PagingStoreFactoryDatabase.ADDRESS_FILE); file.open(); ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(SimpleString.sizeofNullableString(address)); buffer.writeSimpleString(address); file.write(buffer, true); file.close(); return factory; }
@Test public void testOpenClose() throws Exception { SequentialFile sf = factory.createSequentialFile("openclose.amq"); sf.open(); sf.fill(512); String s1 = "cheesecake"; byte[] bytes1 = s1.getBytes(StandardCharsets.UTF_8); long initialPos = sf.position(); sf.write(wrapBuffer(bytes1), true); long bytesWritten = sf.position() - initialPos; Assert.assertEquals(calculateRecordSize(bytes1.length, factory.getAlignment()), bytesWritten); sf.close(); try { sf.write(wrapBuffer(bytes1), true); Assert.fail("Should throw exception"); } catch (Exception e) { } sf.open(); sf.write(wrapBuffer(bytes1), true); sf.close(); }