use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class ReplicationTest method blockOnReplication.
/**
* @param manager1
*/
private void blockOnReplication(final StorageManager storage, final ReplicationManager manager1) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
storage.afterCompleteOperations(new IOCallback() {
@Override
public void onError(final int errorCode, final String errorMessage) {
}
@Override
public void done() {
latch.countDown();
}
});
Assert.assertTrue(latch.await(30, TimeUnit.SECONDS));
}
use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class ReplicationTest method testExceptionSettingActionBefore.
@Test
public void testExceptionSettingActionBefore() throws Exception {
OperationContext ctx = OperationContextImpl.getContext(factory);
ctx.storeLineUp();
String msg = "I'm an exception";
ctx.onError(ActiveMQExceptionType.UNBLOCKED.getCode(), msg);
final AtomicInteger lastError = new AtomicInteger(0);
final List<String> msgsResult = new ArrayList<>();
final CountDownLatch latch = new CountDownLatch(1);
ctx.executeOnCompletion(new IOCallback() {
@Override
public void onError(final int errorCode, final String errorMessage) {
lastError.set(errorCode);
msgsResult.add(errorMessage);
latch.countDown();
}
@Override
public void done() {
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Assert.assertEquals(5, lastError.get());
Assert.assertEquals(1, msgsResult.size());
Assert.assertEquals(msg, msgsResult.get(0));
final CountDownLatch latch2 = new CountDownLatch(1);
// Adding the Task after the exception should still throw an exception
ctx.executeOnCompletion(new IOCallback() {
@Override
public void onError(final int errorCode, final String errorMessage) {
lastError.set(errorCode);
msgsResult.add(errorMessage);
latch2.countDown();
}
@Override
public void done() {
}
});
Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
Assert.assertEquals(2, msgsResult.size());
Assert.assertEquals(msg, msgsResult.get(0));
Assert.assertEquals(msg, msgsResult.get(1));
final CountDownLatch latch3 = new CountDownLatch(1);
ctx.executeOnCompletion(new IOCallback() {
@Override
public void onError(final int errorCode, final String errorMessage) {
}
@Override
public void done() {
latch3.countDown();
}
});
Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
}
use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class ReplicationTest method testOrderOnNonPersistency.
@Test
public void testOrderOnNonPersistency() throws Exception {
setupServer(true);
final ArrayList<Integer> executions = new ArrayList<>();
StorageManager storage = getStorage();
manager = liveServer.getReplicationManager();
Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager);
int numberOfAdds = 200;
final CountDownLatch latch = new CountDownLatch(numberOfAdds);
OperationContext ctx = storage.getContext();
for (int i = 0; i < numberOfAdds; i++) {
final int nAdd = i;
if (i % 2 == 0) {
replicatedJournal.appendPrepareRecord(i, new FakeData(), false);
}
ctx.executeOnCompletion(new IOCallback() {
@Override
public void onError(final int errorCode, final String errorMessage) {
}
@Override
public void done() {
executions.add(nAdd);
latch.countDown();
}
});
}
Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
for (int i = 0; i < numberOfAdds; i++) {
Assert.assertEquals(i, executions.get(i).intValue());
}
Assert.assertEquals(0, manager.getActiveTokens().size());
}
use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class JournalImpl method appendRecord.
/**
* @param completeTransaction If the appendRecord is for a prepare or commit, where we should
* update the number of pendingTransactions on the current file
* @throws Exception
*/
private JournalFile appendRecord(final JournalInternalRecord encoder, final boolean completeTransaction, final boolean sync, final JournalTransaction tx, final IOCallback parameterCallback) throws Exception {
final IOCallback callback;
final int size = encoder.getEncodeSize();
switchFileIfNecessary(size);
if (tx != null) {
// since we individualize the callback per file
if (fileFactory.isSupportsCallbacks()) {
// Set the delegated callback as a parameter
TransactionCallback txcallback = tx.getCallback(currentFile);
if (parameterCallback != null) {
txcallback.setDelegateCompletion(parameterCallback);
}
callback = txcallback;
} else {
callback = parameterCallback;
}
// We need to add the number of records on currentFile if prepare or commit
if (completeTransaction) {
// Filling the number of pendingTransactions at the current file
tx.fillNumberOfRecords(currentFile, encoder);
}
} else {
callback = parameterCallback;
}
// Adding fileID
encoder.setFileID(currentFile.getRecordID());
if (callback != null) {
currentFile.getFile().write(encoder, sync, callback);
} else {
currentFile.getFile().write(encoder, sync);
}
return currentFile;
}
use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class TimedSequentialFile method invokeDoneOn.
private static void invokeDoneOn(List<? extends IOCallback> callbacks) {
final int size = callbacks.size();
for (int i = 0; i < size; i++) {
try {
final IOCallback callback = callbacks.get(i);
callback.done();
} catch (Throwable e) {
ActiveMQJournalLogger.LOGGER.errorCompletingCallback(e);
}
}
}
Aggregations