Search in sources :

Example 16 with IOCallback

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));
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) IOCallback(org.apache.activemq.artemis.core.io.IOCallback)

Example 17 with IOCallback

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));
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) Test(org.junit.Test)

Example 18 with IOCallback

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());
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) ArrayList(java.util.ArrayList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 19 with IOCallback

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;
}
Also used : IOCallback(org.apache.activemq.artemis.core.io.IOCallback)

Example 20 with IOCallback

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);
        }
    }
}
Also used : IOCallback(org.apache.activemq.artemis.core.io.IOCallback) SimpleWaitIOCallback(org.apache.activemq.artemis.core.journal.impl.SimpleWaitIOCallback)

Aggregations

IOCallback (org.apache.activemq.artemis.core.io.IOCallback)27 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)12 Test (org.junit.Test)9 CountDownLatch (java.util.concurrent.CountDownLatch)7 ArrayList (java.util.ArrayList)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ByteBuffer (java.nio.ByteBuffer)4 ExecutorService (java.util.concurrent.ExecutorService)3 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)3 OperationContext (org.apache.activemq.artemis.core.persistence.OperationContext)3 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)3 OperationContextImpl (org.apache.activemq.artemis.core.persistence.impl.journal.OperationContextImpl)3 IOException (java.io.IOException)2 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)2 Message (org.apache.activemq.artemis.api.core.Message)2 Journal (org.apache.activemq.artemis.core.journal.Journal)2 SimpleWaitIOCallback (org.apache.activemq.artemis.core.journal.impl.SimpleWaitIOCallback)2 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)2 ReplicatedJournal (org.apache.activemq.artemis.core.replication.ReplicatedJournal)2 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)2