Example usage for java.util Queue size

List of usage examples for java.util Queue size

Introduction

In this page you can find the example usage for java.util Queue size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this collection.

Usage

From source file:org.apache.hadoop.hdfs.notifier.server.TestServerHistory.java

@Test
public void testQueueNotificationAdvanced() throws Exception {
    // Starting without a ramp-up phase
    DummyServerCore core = new DummyServerCore();
    ServerHistory history = new ServerHistory(core, false);
    long historyLength = 10000;
    history.setHistoryLength(historyLength);
    Queue<NamespaceNotification> historyNotifications;
    long txCount = 1001;

    new Thread(history).start();

    for (long txId = 0; txId < txCount; txId++) {
        history.storeNotification(/*from   w  w  w.j a v  a 2 s  .c o  m*/
                new NamespaceNotification("/a/" + txId, EventType.FILE_ADDED.getByteValue(), txId));
    }

    // Part 1 - Get all notifications
    historyNotifications = new LinkedList<NamespaceNotification>();
    history.addNotificationsToQueue(new NamespaceEvent("/a", EventType.FILE_ADDED.getByteValue()), 0,
            historyNotifications);
    Assert.assertEquals(1000, historyNotifications.size());
    for (long txId = 1; txId < txCount; txId++) {
        NamespaceNotification n = historyNotifications.poll();
        Assert.assertEquals(txId, n.txId);
        Assert.assertEquals("/a/" + txId, n.path);
        Assert.assertEquals(EventType.FILE_ADDED.getByteValue(), n.type);
    }

    // Part 2 - Get half of the notifications
    historyNotifications = new LinkedList<NamespaceNotification>();
    history.addNotificationsToQueue(new NamespaceEvent("/a", EventType.FILE_ADDED.getByteValue()), 500,
            historyNotifications);
    Assert.assertEquals(500, historyNotifications.size());
    for (long txId = 501; txId < txCount; txId++) {
        NamespaceNotification n = historyNotifications.poll();
        Assert.assertEquals(txId, n.txId);
        Assert.assertEquals("/a/" + txId, n.path);
        Assert.assertEquals(EventType.FILE_ADDED.getByteValue(), n.type);
    }

    core.shutdown();
}

From source file:org.mule.util.queue.AbstractTransactionQueueManagerTestCase.java

@Test
public void testTransactedPutCommitWithPersistence() throws Exception {
    if (isPersistent()) {
        TransactionalQueueManager mgr = createQueueManager();

        try {/*from w  w w  . ja v  a  2s.c  om*/
            QueueSession s = mgr.getQueueSession();
            Queue q = s.getQueue("queue1");
            mgr.start();
            s.begin();
            q.put("String1");
            assertEquals("Queue size", 1, q.size());
            s.commit();
            assertEquals("Queue size", 1, q.size());

            s = mgr.getQueueSession();
            q = s.getQueue("queue1");
            assertEquals("Queue size", 1, q.size());

            mgr.stop(AbstractResourceManager.SHUTDOWN_MODE_NORMAL);

            mgr = createQueueManager();
            s = mgr.getQueueSession();
            q = s.getQueue("queue1");
            mgr.start();
            assertEquals("Queue size", 1, q.size());

            purgeQueue(q);
        } finally {
            mgr.stop(AbstractResourceManager.SHUTDOWN_MODE_NORMAL);
        }
    } else {
        logger.info("Ignoring test because queue manager is not persistent");
    }
}

From source file:org.apache.synapse.endpoints.EndpointView.java

private int getTotal(Queue<Integer> queue, int count) {
    int sum = 0;/*  w w  w . jav a  2s .c o  m*/
    Integer[] array = queue.toArray(new Integer[queue.size()]);

    if (count > array.length) {
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
    } else {
        for (int i = 0; i < count; i++) {
            sum += array[array.length - 1 - i];
        }
    }
    return sum;
}

From source file:com.datumbox.common.persistentstorage.factories.MongoDBStructureFactory.java

@Override
public void preSave(BigDataStructureContainer learnedParameters, MemoryConfiguration memoryConfiguration) {

    boolean usesInMemoryStructures = memoryConfiguration.getMapType().isInMemory()
            || memoryConfiguration.getSetType().isInMemory() || memoryConfiguration.getQueueType().isInMemory()
            || memoryConfiguration.getCollectionType().isInMemory();

    //If in-memory structures are used to speed up the execution of the algorithm, then
    //those fields are marked as Transient and thus they will not be stored
    //by Morphia. To avoid losing this information, we check to find the fields
    //of ModelParameter object and we try to spote the fields that are marked
    //as Transient and BigDataStructureMarker (custom annotation). If such a field is found
    //we add its contents in the database in a collection named as the name
    //of the field.
    if (usesInMemoryStructures) {
        Queue<BigDataStructureContainer> learnableObjects = new LinkedList<>();
        Set<BigDataStructureContainer> alreadyChecked = new HashSet<>(); //This set uses the default equals() which means that it compares memory addresses. This behavior is desired

        learnableObjects.add(learnedParameters);

        while (learnableObjects.size() > 0) {
            //get the next object from the queue
            BigDataStructureContainer obj = learnableObjects.poll();

            //mark it as examined
            alreadyChecked.add(obj);/*  ww  w .  java 2  s  .c  o m*/

            //get all the fields from all the inherited classes
            for (Field field : getAllFields(new LinkedList<>(), obj.getClass())) {
                handleBigDataStructureField(field, obj, memoryConfiguration);

                Class<?> fieldClass = field.getType();
                //if this object can be learned and is not already checked add it in the Queue
                if (BigDataStructureContainer.class.isAssignableFrom(fieldClass)) {
                    field.setAccessible(true);
                    BigDataStructureContainer fieldValue;
                    try {
                        fieldValue = (BigDataStructureContainer) field.get(obj);
                    } catch (IllegalArgumentException | IllegalAccessException ex) {
                        throw new RuntimeException(ex);
                    }

                    if (!alreadyChecked.contains(fieldValue)) {
                        learnableObjects.add(fieldValue);
                    }
                }
            }
        }

    }
}

From source file:com.datumbox.common.persistentstorage.factories.MongoDBStructureFactory.java

@Override
public void postLoad(BigDataStructureContainer learnedParameters, MemoryConfiguration memoryConfiguration) {
    //InMemory DataStructureTypes can be used to speed up training. This point of load() 
    //method is reached when the classifier calls a method that requires data and the 
    //data are not already loaded. 
    ////from w  ww.j a  va  2  s.com
    //Loading the data from the DB to a map during methods like test() or predict() is 
    //slow and a waste of resources. Usually LRU caching is more appropriate.
    //Thus using hashmaps during test() or predict() is disallowed if the
    //data are not already in there.
    //
    //Below if the MapType is set to HashMap we switch it to the default map.
    //We do the same with the other DataStructures
    if (memoryConfiguration.getMapType().isInMemory()) {
        memoryConfiguration.setMapType(getDefaultMapType());
        memoryConfiguration.setLRUsize(getDefaultLRUsize());
    }
    if (memoryConfiguration.getCollectionType().isInMemory()) {
        memoryConfiguration.setCollectionType(getDefaultCollectionType());
    }
    if (memoryConfiguration.getSetType().isInMemory()) {
        memoryConfiguration.setSetType(getDefaultSetType());
    }
    if (memoryConfiguration.getQueueType().isInMemory()) {
        memoryConfiguration.setQueueType(getDefaultQueueType());
    }

    Queue<BigDataStructureContainer> learnableObjects = new LinkedList<>();
    Set<BigDataStructureContainer> alreadyChecked = new HashSet<>(); //This set uses the default equals() which means that it compares memory addresses. This behavior is desired

    learnableObjects.add(learnedParameters);

    while (learnableObjects.size() > 0) {
        //get the next object from the queue
        BigDataStructureContainer obj = learnableObjects.poll();

        //mark it as examined
        alreadyChecked.add(obj);

        //reinitialize the big data structures to load the data from the mongodb collections
        obj.bigDataStructureInitializer(this, memoryConfiguration);

        //get all the fields from all the inherited classes
        for (Field field : getAllFields(new LinkedList<>(), obj.getClass())) {

            Class<?> fieldClass = field.getType();
            //if this object can be learned and is not already checked add it in the Queue
            if (BigDataStructureContainer.class.isAssignableFrom(fieldClass)) {
                field.setAccessible(true);
                BigDataStructureContainer fieldValue;
                try {
                    fieldValue = (BigDataStructureContainer) field.get(obj);
                } catch (IllegalArgumentException | IllegalAccessException ex) {
                    throw new RuntimeException(ex);
                }

                if (fieldValue != null && !alreadyChecked.contains(fieldValue)) {
                    learnableObjects.add(fieldValue);
                }
            }
        }
    }

}

From source file:it.geosolutions.geobatch.geotiff.retile.GeotiffRetiler.java

public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {
    try {//ww  w .  j a  v a2s.  c  o m

        if (configuration == null) {
            final String message = "GeotiffRetiler::execute(): flow configuration is null.";
            if (LOGGER.isErrorEnabled())
                LOGGER.error(message);
            throw new ActionException(this, message);
        }
        if (events.size() == 0) {
            throw new ActionException(this,
                    "GeotiffRetiler::execute(): Unable to process an empty events queue.");
        }

        if (LOGGER.isInfoEnabled())
            LOGGER.info("GeotiffRetiler::execute(): Starting with processing...");

        listenerForwarder.started();

        // The return
        final Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>();

        while (events.size() > 0) {

            FileSystemEvent event = events.remove();

            File eventFile = event.getSource();
            FileSystemEventType eventType = event.getEventType();

            if (eventFile.exists() && eventFile.canRead() && eventFile.canWrite()) {
                /*
                 * If here: we can start retiler actions on the incoming file event
                 */

                if (eventFile.isDirectory()) {

                    File[] fileList = eventFile.listFiles();
                    int size = fileList.length;
                    for (int progress = 0; progress < size; progress++) {

                        File inFile = fileList[progress];

                        final String absolutePath = inFile.getAbsolutePath();
                        final String inputFileName = FilenameUtils.getName(absolutePath);

                        if (LOGGER.isInfoEnabled())
                            LOGGER.info("is going to retile: " + inputFileName);

                        try {

                            listenerForwarder.setTask("GeotiffRetiler");

                            File tiledTiffFile = File.createTempFile(inFile.getName(), "_tiled.tif",
                                    getTempDir());
                            if (tiledTiffFile.exists()) {
                                // file already exists
                                // check write permission
                                if (!tiledTiffFile.canWrite()) {
                                    final String message = "Unable to over-write the temporary file called: "
                                            + tiledTiffFile.getAbsolutePath() + "\nCheck permissions.";
                                    if (LOGGER.isErrorEnabled()) {
                                        LOGGER.error(message);
                                    }
                                    throw new IllegalArgumentException(message);
                                }
                            } else if (!tiledTiffFile.createNewFile()) {
                                final String message = "Unable to create temporary file called: "
                                        + tiledTiffFile.getAbsolutePath();
                                if (LOGGER.isErrorEnabled()) {
                                    LOGGER.error(message);
                                }
                                throw new IllegalArgumentException(message);
                            }
                            final double compressionRatio = getConfiguration().getCompressionRatio();
                            final String compressionType = getConfiguration().getCompressionScheme();

                            reTile(inFile, tiledTiffFile, compressionRatio, compressionType,
                                    getConfiguration().getTileW(), getConfiguration().getTileH(),
                                    getConfiguration().isForceToBigTiff());

                            String extension = FilenameUtils.getExtension(inputFileName);
                            if (!extension.contains("tif")) {
                                extension = "tif";
                            }
                            final String outputFileName = FilenameUtils.getFullPath(absolutePath)
                                    + FilenameUtils.getBaseName(inputFileName) + "." + extension;
                            final File outputFile = new File(outputFileName);
                            // do we need to remove the input?
                            FileUtils.copyFile(tiledTiffFile, outputFile);
                            FileUtils.deleteQuietly(tiledTiffFile);

                            // set the output
                            /*
                             * COMMENTED OUT 21 Feb 2011: simone: If the event represents a Dir
                             * we have to return a Dir. Do not matter failing files.
                             * 
                             * carlo: we may also want to check if a file is already tiled!
                             * 
                             * File outputFile=reTile(inFile); if (outputFile!=null){ //TODO:
                             * here we use the same event for each file in the ret.add(new
                             * FileSystemEvent(outputFile, eventType)); }
                             */

                        } catch (UnsupportedOperationException uoe) {
                            listenerForwarder.failed(uoe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(uoe.getLocalizedMessage(), uoe);
                            continue;
                        } catch (IOException ioe) {
                            listenerForwarder.failed(ioe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(ioe.getLocalizedMessage(), ioe);
                            continue;
                        } catch (IllegalArgumentException iae) {
                            listenerForwarder.failed(iae);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(iae.getLocalizedMessage(), iae);
                            continue;
                        } finally {
                            listenerForwarder.setProgress((progress * 100) / ((size != 0) ? size : 1));
                            listenerForwarder.progressing();
                        }
                    }

                    if (LOGGER.isInfoEnabled())
                        LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource());

                    // add the directory to the return
                    ret.add(event);
                } else {
                    // file is not a directory
                    try {
                        listenerForwarder.setTask("GeotiffRetiler");

                        File tiledTiffFile = File.createTempFile(eventFile.getName(), "_tiled.tif",
                                eventFile.getParentFile());
                        if (tiledTiffFile.exists()) {
                            // file already exists
                            // check write permission
                            if (!tiledTiffFile.canWrite()) {
                                final String message = "Unable to over-write the temporary file called: "
                                        + tiledTiffFile.getAbsolutePath() + "\nCheck permissions.";
                                if (LOGGER.isErrorEnabled()) {
                                    LOGGER.error(message);
                                }
                                throw new IllegalArgumentException(message);
                            }
                        } else if (!tiledTiffFile.createNewFile()) {
                            final String message = "Unable to create temporary file called: "
                                    + tiledTiffFile.getAbsolutePath();
                            if (LOGGER.isErrorEnabled()) {
                                LOGGER.error(message);
                            }
                            throw new IllegalArgumentException(message);
                        }
                        final double compressionRatio = getConfiguration().getCompressionRatio();
                        final String compressionType = getConfiguration().getCompressionScheme();

                        reTile(eventFile, tiledTiffFile, compressionRatio, compressionType,
                                getConfiguration().getTileW(), getConfiguration().getTileH(),
                                getConfiguration().isForceToBigTiff());

                        String extension = FilenameUtils.getExtension(eventFile.getName());
                        if (!extension.contains("tif")) {
                            extension = "tif";
                        }
                        final String outputFileName = FilenameUtils.getFullPath(eventFile.getAbsolutePath())
                                + FilenameUtils.getBaseName(eventFile.getName()) + "." + extension;
                        final File outputFile = new File(outputFileName);
                        // do we need to remove the input?
                        FileUtils.copyFile(tiledTiffFile, outputFile);
                        FileUtils.deleteQuietly(tiledTiffFile);

                        if (LOGGER.isInfoEnabled())
                            LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource());
                        listenerForwarder.setProgress(100);
                        ret.add(new FileSystemEvent(outputFile, eventType));

                    } catch (UnsupportedOperationException uoe) {
                        listenerForwarder.failed(uoe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(uoe.getLocalizedMessage(), uoe);
                        continue;
                    } catch (IOException ioe) {
                        listenerForwarder.failed(ioe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(ioe.getLocalizedMessage(), ioe);
                        continue;
                    } catch (IllegalArgumentException iae) {
                        listenerForwarder.failed(iae);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(iae.getLocalizedMessage(), iae);
                        continue;
                    } finally {

                        listenerForwarder.setProgress((100) / ((events.size() != 0) ? events.size() : 1));
                        listenerForwarder.progressing();
                    }
                }
            } else {
                final String message = "The passed file event refers to a not existent "
                        + "or not readable/writeable file! File: " + eventFile.getAbsolutePath();
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(message);
                final IllegalArgumentException iae = new IllegalArgumentException(message);
                listenerForwarder.failed(iae);
            }
        } // endwile
        listenerForwarder.completed();

        // return
        if (ret.size() > 0) {
            events.clear();
            return ret;
        } else {
            /*
             * If here: we got an error no file are set to be returned the input queue is
             * returned
             */
            return events;
        }
    } catch (Exception t) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error(t.getLocalizedMessage(), t);
        final ActionException exc = new ActionException(this, t.getLocalizedMessage(), t);
        listenerForwarder.failed(exc);
        throw exc;
    }
}

From source file:it.geosolutions.geobatch.task.TaskExecutor.java

public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {

    listenerForwarder.started();/*from  ww  w .j  a v  a  2 s .c om*/

    if (configuration == null) {
        final ActionException e = new ActionException(this, "DataFlowConfig is null.");
        listenerForwarder.failed(e);
        throw e;
    }

    if (events == null || events.size() == 0) {
        final ActionException e = new ActionException(this, "Empty or null incoming events list");
        listenerForwarder.failed(e);
        throw e;
    }

    Queue<FileSystemEvent> outEvents = new LinkedList<FileSystemEvent>();

    while (events.size() > 0) {
        // get the first event
        final FileSystemEvent event = events.remove();
        final File inputFile = event.getSource();
        if (inputFile == null) {
            final ActionException e = new ActionException(this, "Input File is null");
            listenerForwarder.failed(e);
            throw e;
        }
        if (!inputFile.exists()) {
            final ActionException e = new ActionException(this, "Input File doesn't exist");
            listenerForwarder.failed(e);
            throw e;
        }
        final String inputFilePath = inputFile.getAbsolutePath();

        final String inputFileExt = FilenameUtils.getExtension(inputFilePath);

        // Getting XSL file definition
        final String xslPath = configuration.getXsl();
        final boolean useDefaultScript;

        String defaultScriptPath = configuration.getDefaultScript();
        if (inputFileExt.equalsIgnoreCase("xml")) {
            if (LOGGER.isInfoEnabled())
                LOGGER.info("Using input file as script: " + inputFilePath);
            defaultScriptPath = inputFilePath;
            useDefaultScript = false;
        } else {
            if (LOGGER.isInfoEnabled())
                LOGGER.info("Using default script: " + configuration.getDefaultScript());
            useDefaultScript = true;
        }

        final String outputName = configuration.getOutputName();

        File xslFile = null;
        InputStream is = null;

        try {

            if (xslPath != null && xslPath.trim().length() > 0) {
                final String path = Path.findLocation(xslPath, getConfigDir().getAbsolutePath());
                if (path == null) {
                    final ActionException e = new ActionException(this, "XSL file not found: " + path);
                    listenerForwarder.failed(e);
                    throw e;
                }
                xslFile = new File(path);
            }
            if (!xslFile.exists()) {
                final ActionException e = new ActionException(this, "XSL file not found: " + xslPath);
                listenerForwarder.failed(e);
                throw e;
            }

            File xmlFile = null;
            String outputFile = null;
            if (useDefaultScript) {
                if (defaultScriptPath != null && defaultScriptPath.trim().length() > 0) {
                    final String path = Path.findLocation(xslPath, getConfigDir().getAbsolutePath());
                    if (path == null) {
                        final ActionException e = new ActionException(this, "XSL file not found: " + path);
                        listenerForwarder.failed(e);
                        throw e;
                    }
                    xmlFile = new File(path);

                    final File outXmlFile = File.createTempFile("script", ".xml", getTempDir());
                    //                  outXmlFile.deleteOnExit();
                    outputFile = setScriptArguments(xmlFile.getAbsolutePath(), inputFilePath, outputName,
                            outXmlFile);
                    xmlFile = outXmlFile;
                }

            } else {
                xmlFile = inputFile;
            }
            if (!xmlFile.exists()) {
                final ActionException e = new ActionException(this, "XML file not found: " + xmlFile);
                listenerForwarder.failed(e);
                throw e;
            }

            // Setup an XML source from the input XML file
            final Source xmlSource = new StreamSource(xmlFile);

            is = new FileInputStream(xslFile);

            // XML parsing to setup a command line
            final String argument = buildArgument(xmlSource, is);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Arguments: " + argument);
            }

            final Project project = new Project();
            project.init();

            final ExecTask execTask = new ExecTask();
            execTask.setProject(project);

            // Setting environment variables coming from the configuration
            // as an instance: PATH, LD_LIBRARY_PATH and similar
            Map<String, String> variables = configuration.getVariables();
            if (variables != null && !variables.isEmpty()) {
                for (String key : variables.keySet()) {
                    Variable var = new Variable();
                    var.setKey(key);
                    final String value = variables.get(key);
                    if (value != null) {
                        var.setValue(variables.get(key));
                        execTask.addEnv(var);
                    }
                }
            }

            // Setting executable
            execTask.setExecutable(configuration.getExecutable());

            // Setting Error logging
            final String errorFileName = configuration.getErrorFile();
            if (errorFileName != null) {
                File errorFile = new File(errorFileName);
                if (!errorFile.exists()) {
                    errorFile = Path.findLocation(errorFileName, getTempDir());
                    if (errorFile != null && !errorFile.exists()) {
                        try {
                            errorFile.createNewFile();
                        } catch (Throwable t) {
                            final ActionException e = new ActionException(this, t.getLocalizedMessage(), t);
                            listenerForwarder.failed(e);
                            throw e;
                        }
                    }
                }
                if (errorFile.exists()) {
                    if (LOGGER.isDebugEnabled())
                        LOGGER.debug("Using error file: " + errorFile);
                    execTask.setLogError(true);
                    execTask.setAppend(true);
                    execTask.setError(errorFile);
                    execTask.setFailonerror(true);
                }
            }

            // Setting the timeout
            Long timeOut = configuration.getTimeOut();
            if (timeOut != null) {
                execTask.setTimeout(timeOut);
            }

            // Setting command line argument
            execTask.createArg().setLine(argument);

            File output = null;
            if (configuration.getOutput() != null) {
                output = new File(configuration.getOutput());
                if (output.exists() && output.isDirectory()) {
                    final File outXmlFile = File.createTempFile("script", ".xml", getTempDir()); // TODO CHECKME: is this var used?
                    //                  outXmlFile.deleteOnExit();
                    String destFile = getScriptArguments(xmlFile.getAbsolutePath(), "srcfile");
                    if (output.isAbsolute()) {
                        //                            String basename = 
                        output = new File(output, FilenameUtils.getBaseName(destFile) + configuration
                                .getOutputName().substring(configuration.getOutputName().indexOf(".")));
                    } else {
                        output = Path.findLocation(configuration.getOutput(), inputFile.getParentFile());
                        output = new File(output, FilenameUtils.getBaseName(inputFile.getName()) + configuration
                                .getOutputName().substring(configuration.getOutputName().indexOf(".")));
                    }
                }
                execTask.setOutput(output);
            }

            // Executing
            execTask.execute();

            File outFile = (outputFile != null ? new File(outputFile) : null);

            if (configuration.getOutput() != null) {
                if (new File(configuration.getOutput()).isAbsolute()) {
                    if (output.exists() && output.isFile()) {
                        // outFile = output;
                        final File outXmlFile = File.createTempFile("script", ".xml", getTempDir());
                        //                     outXmlFile.deleteOnExit();
                        outputFile = setScriptArguments(xmlFile.getAbsolutePath(), output.getAbsolutePath(),
                                outputName, outXmlFile);
                        outFile = new File(configuration.getOutput(),
                                FilenameUtils.getBaseName(outputFile) + ".xml");
                        FileUtils.copyFile(outXmlFile, outFile);
                    }
                } else {
                    if (outFile == null)
                        outFile = inputFile;
                }
            } else if (outFile == null) {
                outFile = inputFile;
            }

            outEvents.add(new FileSystemEvent(outFile, FileSystemEventType.FILE_ADDED));
        } catch (Exception e) {
            listenerForwarder.failed(e);
            throw new ActionException(this, e.getMessage(), e);
        } finally {
            if (is != null)
                org.apache.commons.io.IOUtils.closeQuietly(is);
        }
    }

    listenerForwarder.completed();
    return outEvents;
}

From source file:org.mule.util.queue.AbstractTransactionQueueManagerTestCase.java

@Test
public void testTransactionsOnMultipleQueues() throws Exception {

    TransactionalQueueManager mgr = createQueueManager();

    try {/*from   ww  w  .j  a  va  2  s. co  m*/
        mgr.start();

        QueueSession s1 = mgr.getQueueSession();
        QueueSession s2 = mgr.getQueueSession();

        Queue q1s1 = s1.getQueue("queue1");
        Queue q1s2 = s2.getQueue("queue1");
        Queue q2s1 = s1.getQueue("queue2");
        Queue q2s2 = s2.getQueue("queue2");

        q1s1.put("String1");
        assertEquals("Queue size", 1, q1s1.size());
        assertEquals("Queue size", 1, q1s2.size());

        s1.begin();

        Object o = q1s1.take();
        assertNotNull(o);
        assertEquals("String1", o);
        assertEquals("Queue size", 0, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        q2s1.put("String2");
        assertEquals("Queue size", 1, q2s1.size());
        assertEquals("Queue size", 0, q2s2.size());

        s1.commit();

        assertEquals("Queue size", 0, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        assertEquals("Queue size", 1, q2s1.size());
        assertEquals("Queue size", 1, q2s2.size());

        s1.begin();

        o = q2s1.take();
        assertNotNull(o);
        assertEquals("String2", o);
        assertEquals("Queue size", 0, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        assertEquals("Queue size", 0, q2s1.size());
        assertEquals("Queue size", 0, q2s2.size());

        q1s1.put("String1");

        assertEquals("Queue size", 1, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        assertEquals("Queue size", 0, q2s1.size());
        assertEquals("Queue size", 0, q2s2.size());

        s1.rollback();

        assertEquals("Queue size", 0, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        assertEquals("Queue size", 1, q2s1.size());
        assertEquals("Queue size", 1, q2s2.size());

        purgeQueue(q1s1);
        purgeQueue(q1s2);
        purgeQueue(q2s1);
        purgeQueue(q2s2);
    } finally {
        mgr.stop(AbstractResourceManager.SHUTDOWN_MODE_NORMAL);
    }
}

From source file:org.mule.util.queue.AbstractTransactionQueueManagerTestCase.java

@Test
public void testRecoverWarmRestart() throws Exception {
    TransactionalQueueManager mgr = createQueueManager();
    mgr.start();//from w w  w  . jav  a 2s.c  o  m
    QueueSession s = mgr.getQueueSession();
    Queue q = s.getQueue("warmRecoverQueue");

    int toPopulate = 500;

    // Populate queue
    Random rnd = new Random();
    for (int j = 0; j < toPopulate; j++) {
        byte[] o = new byte[2048];
        rnd.nextBytes(o);
        q.put(o);
    }
    assertEquals(q.size(), toPopulate);

    // Stop and start TransactionalQueueManager
    mgr.stop();
    mgr.start();

    assertEquals(toPopulate, q.size());
}