use of org.apache.activemq.artemis.core.journal.impl.SimpleWaitIOCallback in project activemq-artemis by apache.
the class OperationContextImpl method waitCompletion.
@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);
}
}
use of org.apache.activemq.artemis.core.journal.impl.SimpleWaitIOCallback in project activemq-artemis by apache.
the class JDBCSequentialFile method writeDirect.
@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);
}
}
use of org.apache.activemq.artemis.core.journal.impl.SimpleWaitIOCallback in project activemq-artemis by apache.
the class TimedSequentialFile method write.
@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);
}
}
}
use of org.apache.activemq.artemis.core.journal.impl.SimpleWaitIOCallback in project activemq-artemis by apache.
the class AIOSequentialFile method writeDirect.
@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());
}
}
use of org.apache.activemq.artemis.core.journal.impl.SimpleWaitIOCallback in project activemq-artemis by apache.
the class JDBCJournalImpl method appendRecord.
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();
}
Aggregations