Search in sources :

Example 16 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class QueueControlDataFile method writeControlData.

/**
 * Updates the control data
 *
 * @param writeFile file that is used for writing
 * @param readFile file that is used for reading
 */
public void writeControlData(File writeFile, File readFile) {
    try {
        queueFileProvider.getRandomAccessFile().seek(0);
        final String writeFilePath = writeFile.getAbsolutePath();
        final String readFilePath = readFile.getAbsolutePath();
        final ByteBuffer controlDataBuffer = ByteBuffer.allocate(writeFilePath.length() + INTEGER_SIZE_IN_BYTES + readFilePath.length() + INTEGER_SIZE_IN_BYTES);
        controlDataBuffer.putInt(writeFilePath.length());
        controlDataBuffer.put(writeFilePath.getBytes());
        controlDataBuffer.putInt(readFilePath.length());
        controlDataBuffer.put(readFilePath.getBytes());
        queueFileProvider.getRandomAccessFile().write(controlDataBuffer.array());
        this.currentReadFilePath = readFile;
        this.currentWriteFilePath = writeFile;
    } catch (IOException e) {
        throw new MuleRuntimeException(e);
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 17 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class RandomAccessFileQueueStore method readFirstValue.

private byte[] readFirstValue() {
    try {
        if (orderedKeys.isEmpty()) {
            return null;
        }
        Long filePointer = orderedKeys.getFirst();
        queueFileProvider.getRandomAccessFile().seek(filePointer);
        // Always true since it's a key
        queueFileProvider.getRandomAccessFile().readByte();
        return readDataInCurrentPosition();
    } catch (IOException e) {
        throw new MuleRuntimeException(e);
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException)

Example 18 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class LocalTxQueueTransactionRecoverer method recover.

/**
 * Recover all the pending transactions.
 *
 * Will undo all operations done over queues that were not commit or rolled back.
 *
 * Clears the transaction log after processing all the log entries since does entries are not longer required.
 */
public void recover() {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing transaction recovery");
    }
    Multimap<Integer, LocalQueueTxJournalEntry> allEntries = this.localTxQueueTransactionJournal.getAllLogEntries();
    if (logger.isDebugEnabled()) {
        logger.debug("Found " + allEntries.size() + " txs to recover");
    }
    int txRecovered = 0;
    for (Integer txId : allEntries.keySet()) {
        Collection<LocalQueueTxJournalEntry> entries = allEntries.get(txId);
        Object commitOrRollback = find(entries, new Predicate() {

            @Override
            public boolean evaluate(Object object) {
                LocalQueueTxJournalEntry logEntry = (LocalQueueTxJournalEntry) object;
                return logEntry.isCommit() || logEntry.isRollback();
            }
        });
        if (commitOrRollback != null) {
            continue;
        }
        txRecovered++;
        for (LocalQueueTxJournalEntry logEntry : entries) {
            if (logEntry.isRemove()) {
                String queueName = logEntry.getQueueName();
                RecoverableQueueStore queue = queueProvider.getRecoveryQueue(queueName);
                Serializable polledValue = logEntry.getValue();
                if (!queue.contains(polledValue)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("re-adding polled element that was not commited to queue " + queue.getName());
                    }
                    try {
                        queue.putNow(polledValue);
                    } catch (InterruptedException e) {
                        throw new MuleRuntimeException(e);
                    }
                }
            } else if (logEntry.isAdd() || logEntry.isAddFirst()) {
                Serializable offeredValue = logEntry.getValue();
                String queueName = logEntry.getQueueName();
                RecoverableQueueStore queue = queueProvider.getRecoveryQueue(queueName);
                if (queue.contains(offeredValue)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("removing offer element that was not commited to queue " + queue.getName());
                    }
                    queue.remove(offeredValue);
                }
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Recovered " + txRecovered + " txs to recover");
    }
    this.localTxQueueTransactionJournal.clear();
}
Also used : Serializable(java.io.Serializable) Predicate(org.apache.commons.collections.Predicate) RecoverableQueueStore(org.mule.runtime.core.internal.util.queue.RecoverableQueueStore) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 19 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class TransientQueueTransactionContext method doRollback.

@Override
public void doRollback() throws ResourceManagerException {
    if (removed != null) {
        for (Map.Entry<QueueStore, List<Serializable>> entry : removed.entrySet()) {
            QueueStore queue = entry.getKey();
            List<Serializable> queueRemoved = entry.getValue();
            if (queueRemoved != null && queueRemoved.size() > 0) {
                for (Serializable id : queueRemoved) {
                    try {
                        queue.putNow(id);
                    } catch (InterruptedException e) {
                        throw new MuleRuntimeException(e);
                    }
                }
            }
        }
    }
    added = null;
    removed = null;
}
Also used : Serializable(java.io.Serializable) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class AbstractQueueManager method removeQueueFromCache.

private void removeQueueFromCache(QueueStore queueStore) {
    try {
        if (queueStore == null) {
            throw new IllegalArgumentException("Queue to be disposed cannot be null");
        }
        final String queueName = queueStore.getName();
        queuesLock.lock();
        try {
            if (!this.queues.containsKey(queueName)) {
                throw new IllegalArgumentException(String.format("There's no queue for name %s", queueName));
            }
            this.queues.remove(queueName);
        } finally {
            queuesLock.unlock();
        }
    } catch (Exception e) {
        throw new MuleRuntimeException(e);
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Aggregations

MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)123 IOException (java.io.IOException)22 List (java.util.List)22 MuleException (org.mule.runtime.api.exception.MuleException)22 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)22 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)22 Map (java.util.Map)20 Optional (java.util.Optional)20 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)18 ArrayList (java.util.ArrayList)17 String.format (java.lang.String.format)16 File (java.io.File)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)13 Set (java.util.Set)13 Collectors.toList (java.util.stream.Collectors.toList)12 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)12 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)10 Collections.emptyMap (java.util.Collections.emptyMap)9 Optional.empty (java.util.Optional.empty)9