@Override public boolean waitCompletion(final long timeout) throws InterruptedException, ActiveMQException { SimpleWaitIOCallback waitCallback = new SimpleWaitIOCallback(); executeOnCompletion(waitCallback); complete(); if (timeout == 0) { waitCallback.waitCompletion(); return true; } else { return waitCallback.waitCompletion(timeout); } }
@Override public int read(final ByteBuffer bytes) throws Exception { SimpleWaitIOCallback waitCompletion = new SimpleWaitIOCallback(); int bytesRead = read(bytes, waitCompletion); waitCompletion.waitCompletion(); return bytesRead; }
@Override public int read(final ByteBuffer bytes) throws Exception { SimpleWaitIOCallback waitCompletion = new SimpleWaitIOCallback(); int bytesRead = read(bytes, waitCompletion); waitCompletion.waitCompletion(); return bytesRead; }
@Override public void sync() throws IOException { final SimpleWaitIOCallback callback = new SimpleWaitIOCallback(); executor.execute(callback::done); try { callback.waitCompletion(); } catch (Exception e) { callback.onError(ActiveMQExceptionType.IO_ERROR.getCode(), "Error during JDBC file sync."); fileFactory.onIOError(e, "Error during JDBC file sync.", this); } }
@Override public void writeDirect(final ByteBuffer bytes, final boolean sync) throws Exception { if (logger.isTraceEnabled()) { logger.trace("Write Direct, Sync: " + sync + " File: " + getFileName()); } if (sync) { SimpleWaitIOCallback completion = new SimpleWaitIOCallback(); writeDirect(bytes, true, completion); completion.waitCompletion(); } else { writeDirect(bytes, false, DummyCallback.getInstance()); } }
@Override public void writeDirect(final ByteBuffer bytes, final boolean sync) throws Exception { if (logger.isTraceEnabled()) { logger.trace("Write Direct, Sync: " + sync + " File: " + getFileName()); } if (sync) { SimpleWaitIOCallback completion = new SimpleWaitIOCallback(); writeDirect(bytes, true, completion); completion.waitCompletion(); } else { writeDirect(bytes, false, DummyCallback.getInstance()); } }
@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 blockingWriteDirect(ByteBuffer bytes,boolean sync, boolean releaseBuffer) throws Exception { if (logger.isTraceEnabled()) { logger.trace("Write Direct, Sync: true File: " + getFileName()); } final SimpleWaitIOCallback completion = new SimpleWaitIOCallback(); try { checkOpened(); } catch (Exception e) { ActiveMQJournalLogger.LOGGER.warn(e.getMessage(), e); completion.onError(-1, e.getMessage()); return; } final int bytesToWrite = factory.calculateBlockSize(bytes.limit()); final long positionToWrite = position.getAndAdd(bytesToWrite); final AIOSequentialFileFactory.AIOSequentialCallback runnableCallback = getCallback(completion, bytes, releaseBuffer); runnableCallback.initWrite(positionToWrite, bytesToWrite); runnableCallback.run(); completion.waitCompletion(); }
@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 blockingWriteDirect(ByteBuffer bytes,boolean sync, boolean releaseBuffer) throws Exception { if (logger.isTraceEnabled()) { logger.trace("Write Direct, Sync: true File: " + getFileName()); } final SimpleWaitIOCallback completion = new SimpleWaitIOCallback(); try { checkOpened(); } catch (Exception e) { ActiveMQJournalLogger.LOGGER.warn(e.getMessage(), e); completion.onError(-1, e.getMessage()); return; } final int bytesToWrite = factory.calculateBlockSize(bytes.limit()); final long positionToWrite = position.getAndAdd(bytesToWrite); final AIOSequentialFileFactory.AIOSequentialCallback runnableCallback = getCallback(completion, bytes, releaseBuffer); runnableCallback.initWrite(positionToWrite, bytesToWrite); runnableCallback.run(); completion.waitCompletion(); }
@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 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 synchronized void blockingWriteDirect(ByteBuffer bytes, boolean sync, boolean releaseBuffer) throws Exception { SimpleWaitIOCallback callback = new SimpleWaitIOCallback(); try { writeDirect(bytes, sync, callback); } finally { callback.waitCompletion(); } }
@Override public void writeDirect(ByteBuffer bytes, boolean sync, IOCallback callback) { if (callback == null) { SimpleWaitIOCallback waitIOCallback = new SimpleWaitIOCallback(); try { scheduleWrite(bytes, waitIOCallback); waitIOCallback.waitCompletion(); } catch (Exception e) { waitIOCallback.onError(ActiveMQExceptionType.IO_ERROR.getCode(), "Error writing to JDBC file."); fileFactory.onIOError(e, "Failed to write to file.", this); } } else { scheduleWrite(bytes, callback); } }
@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 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); } } }
private void appendRecord(JDBCJournalRecord record) throws Exception { // extra measure I know, as all the callers are also checking for this.. // better to be safe ;) checkStatus(); if (logger.isTraceEnabled()) { logger.trace("appendRecord " + record); } record.storeLineUp(); if (!started) { if (record.getIoCompletion() != null) { record.getIoCompletion().onError(ActiveMQExceptionType.IO_ERROR.getCode(), "JDBC Journal not started"); } } SimpleWaitIOCallback callback = null; if (record.isSync() && record.getIoCompletion() == null) { callback = new SimpleWaitIOCallback(); record.setIoCompletion(callback); } synchronized (this) { if (record.isTransactional() || record.getRecordType() == JDBCJournalRecord.PREPARE_RECORD) { addTxRecord(record); } synchronized (records) { records.add(record); } } syncTimer.delay(); if (callback != null) callback.waitCompletion(); }