org.apache.activemq.artemis.utils.OrderedExecutorFactory

Here are the examples of the java api class org.apache.activemq.artemis.utils.OrderedExecutorFactory taken from open source projects.

1. ReplicationTest#setUp()

Project: activemq-artemis
File: ReplicationTest.java
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    tFactory = new ActiveMQThreadFactory("ActiveMQ-ReplicationTest", false, this.getClass().getClassLoader());
    executor = Executors.newCachedThreadPool(tFactory);
    scheduledExecutor = new ScheduledThreadPoolExecutor(10, tFactory);
    factory = new OrderedExecutorFactory(executor);
}

2. DuplicateDetectionUnitTest#setUp()

Project: activemq-artemis
File: DuplicateDetectionUnitTest.java
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    executor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory());
    factory = new OrderedExecutorFactory(executor);
}

3. JournalCleanupCompactStressTest#setUp()

Project: activemq-artemis
File: JournalCleanupCompactStressTest.java
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    threadPool = Executors.newFixedThreadPool(20, tFactory);
    executorFactory = new OrderedExecutorFactory(threadPool);
    testExecutor = executorFactory.getExecutor();
    maxRecords = new Semaphore(MAX_WRITES);
    errors.set(0);
    File dir = new File(getTemporaryDir());
    dir.mkdirs();
    SequentialFileFactory factory;
    int maxAIO;
    if (LibaioContext.isLoaded()) {
        factory = new AIOSequentialFileFactory(dir, 10);
        maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoAio();
    } else {
        factory = new NIOSequentialFileFactory(dir, true, 1);
        maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoNio();
    }
    journal = new JournalImpl(50 * 1024, 20, 20, 50, ActiveMQDefaultConfiguration.getDefaultJournalCompactPercentage(), factory, "activemq-data", "amq", maxAIO) {

        @Override
        protected void onCompactLockingTheJournal() throws Exception {
        }

        @Override
        protected void onCompactStart() throws Exception {
            testExecutor.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        // System.out.println("OnCompactStart enter");
                        if (running) {
                            long id = idGen.generateID();
                            journal.appendAddRecord(id, (byte) 0, new byte[] { 1, 2, 3 }, false);
                            journal.forceMoveNextFile();
                            journal.appendDeleteRecord(id, id == 20);
                        }
                    // System.out.println("OnCompactStart leave");
                    } catch (Exception e) {
                        e.printStackTrace();
                        errors.incrementAndGet();
                    }
                }
            });
        }
    };
    journal.start();
    journal.loadInternalOnly();
}

4. NIOJournalCompactTest#testStressDeletesNoSync()

Project: activemq-artemis
File: NIOJournalCompactTest.java
@Test
public void testStressDeletesNoSync() throws Exception {
    Configuration config = createBasicConfig().setJournalFileSize(100 * 1024).setJournalSyncNonTransactional(false).setJournalSyncTransactional(false).setJournalCompactMinFiles(0).setJournalCompactPercentage(0);
    final AtomicInteger errors = new AtomicInteger(0);
    final AtomicBoolean running = new AtomicBoolean(true);
    final AtomicLong seqGenerator = new AtomicLong(1);
    final ExecutorService executor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
    OrderedExecutorFactory factory = new OrderedExecutorFactory(executor);
    final ExecutorService deleteExecutor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
    final JournalStorageManager storage = new JournalStorageManager(config, factory, null);
    storage.start();
    storage.loadInternalOnly();
    ((JournalImpl) storage.getMessageJournal()).setAutoReclaim(false);
    final LinkedList<Long> survivingMsgs = new LinkedList<>();
    Runnable producerRunnable = new Runnable() {

        @Override
        public void run() {
            try {
                while (running.get()) {
                    final long[] values = new long[100];
                    long tx = seqGenerator.incrementAndGet();
                    OperationContextImpl ctx = new OperationContextImpl(executor);
                    storage.setContext(ctx);
                    for (int i = 0; i < 100; i++) {
                        long id = seqGenerator.incrementAndGet();
                        values[i] = id;
                        ServerMessageImpl message = new ServerMessageImpl(id, 100);
                        message.getBodyBuffer().writeBytes(new byte[1024]);
                        storage.storeMessageTransactional(tx, message);
                    }
                    ServerMessageImpl message = new ServerMessageImpl(seqGenerator.incrementAndGet(), 100);
                    survivingMsgs.add(message.getMessageID());
                    // This one will stay here forever
                    storage.storeMessage(message);
                    storage.commit(tx);
                    ctx.executeOnCompletion(new IOCallback() {

                        @Override
                        public void onError(int errorCode, String errorMessage) {
                        }

                        @Override
                        public void done() {
                            deleteExecutor.execute(new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        for (long messageID : values) {
                                            storage.deleteMessage(messageID);
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        errors.incrementAndGet();
                                    }
                                }
                            });
                        }
                    });
                }
            } catch (Throwable e) {
                e.printStackTrace();
                errors.incrementAndGet();
            }
        }
    };
    Runnable compressRunnable = new Runnable() {

        @Override
        public void run() {
            try {
                while (running.get()) {
                    Thread.sleep(500);
                    System.out.println("Compacting");
                    ((JournalImpl) storage.getMessageJournal()).testCompact();
                    ((JournalImpl) storage.getMessageJournal()).checkReclaimStatus();
                }
            } catch (Throwable e) {
                e.printStackTrace();
                errors.incrementAndGet();
            }
        }
    };
    Thread producerThread = new Thread(producerRunnable);
    producerThread.start();
    Thread compactorThread = new Thread(compressRunnable);
    compactorThread.start();
    Thread.sleep(1000);
    running.set(false);
    producerThread.join();
    compactorThread.join();
    storage.stop();
    executor.shutdown();
    assertTrue("executor terminated", executor.awaitTermination(10, TimeUnit.SECONDS));
    deleteExecutor.shutdown();
    assertTrue("delete executor terminated", deleteExecutor.awaitTermination(30, TimeUnit.SECONDS));
}