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);
}
}
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);
}
}
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();
}
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;
}
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);
}
}
Aggregations