use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class InMemoryStreamBuffer method doGet.
private ByteBuffer doGet(long position, int length, boolean consumeStreamIfNecessary) {
return withReadLock(releaser -> {
ByteBuffer presentRead = getFromCurrentData(position, length);
if (presentRead != null) {
return presentRead;
}
if (consumeStreamIfNecessary) {
releaser.release();
return withWriteLock(() -> {
ByteBuffer refetch;
refetch = getFromCurrentData(position, length);
if (refetch != null) {
return refetch;
}
final long requiredUpperBound = position + length;
while (!isStreamFullyConsumed() && bufferTip < requiredUpperBound) {
try {
final int read = consumeForwardData();
if (read > 0) {
refetch = getFromCurrentData(position, min(length, read));
if (refetch != null) {
return refetch;
}
} else {
streamFullyConsumed();
buffer.get().limit(buffer.get().position());
}
} catch (IOException e) {
throw new MuleRuntimeException(createStaticMessage("Could not read stream"), e);
}
}
return doGet(position, length, false);
});
} else {
return getFromCurrentData(position, length);
}
});
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class AbstractQueueManager method setQueueConfiguration.
/**
* {@inheritDoc}
*/
@Override
public synchronized void setQueueConfiguration(String queueName, QueueConfiguration newConfig) {
// We allow calling this method only if the new config is equals to the previous one because of MULE-7420
if (queues.containsKey(queueName) && !newConfig.equals(queueConfigurations.get(queueName))) {
throw new MuleRuntimeException(CoreMessages.createStaticMessage(String.format("A queue with name %s is in use so we cannot change it's configuration", queueName)));
}
if (logger.isDebugEnabled()) {
if (queueConfigurations.containsKey(queueName)) {
QueueConfiguration oldConfiguration = queueConfigurations.get(queueName);
logger.debug(String.format("Replacing queue %s configuration: %s with new newConfig: %s", queueName, oldConfiguration, newConfig));
}
}
queueConfigurations.put(queueName, newConfig);
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class RandomAccessFileQueueStore method writeData.
private long writeData(byte[] data) {
try {
if (getSize() > 0) {
queueFileProvider.getRandomAccessFile().seek(fileTotalSpace);
}
long filePointer = queueFileProvider.getRandomAccessFile().getFilePointer();
int totalBytesRequired = CONTROL_DATA_SIZE + data.length;
ByteBuffer byteBuffer = ByteBuffer.allocate(totalBytesRequired);
byteBuffer.put(NOT_REMOVED);
byteBuffer.putInt(data.length);
byteBuffer.put(data);
queueFileProvider.getRandomAccessFile().write(byteBuffer.array());
fileTotalSpace += totalBytesRequired;
return filePointer;
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class RandomAccessFileQueueStore method clear.
/**
* removes all the elements from the queue.
*/
public synchronized void clear() {
try {
queueFileProvider.getRandomAccessFile().close();
orderedKeys.clear();
fileTotalSpace = 0;
queueFileProvider.recreate();
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class RandomAccessFileQueueStore method initialise.
private void initialise() {
try {
queueFileProvider.getRandomAccessFile().seek(0);
while (true) {
if (currentThread().isInterrupted()) {
throw new InterruptedException();
}
long position = queueFileProvider.getRandomAccessFile().getFilePointer();
byte removed = queueFileProvider.getRandomAccessFile().readByte();
if (removed == NOT_REMOVED) {
orderedKeys.add(position);
moveFilePointerToNextData();
} else {
moveFilePointerToNextData();
}
}
} catch (EOFException e) {
try {
fileTotalSpace = queueFileProvider.getRandomAccessFile().length();
} catch (IOException ioe) {
throw new MuleRuntimeException(e);
}
if (logger.isDebugEnabled()) {
logger.debug("Error initializing queue store", e);
}
} catch (Exception e) {
throw new MuleRuntimeException(e);
}
}
Aggregations