Search in sources :

Example 71 with MuleRuntimeException

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);
        }
    });
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 72 with MuleRuntimeException

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);
}
Also used : DefaultQueueConfiguration(org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration) QueueConfiguration(org.mule.runtime.core.api.util.queue.QueueConfiguration) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 73 with MuleRuntimeException

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);
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 74 with MuleRuntimeException

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);
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException)

Example 75 with MuleRuntimeException

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);
    }
}
Also used : EOFException(java.io.EOFException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException) EOFException(java.io.EOFException)

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