Package org.apache.james.queue.api.MailQueue

Examples of org.apache.james.queue.api.MailQueue.MailQueueItem


                    // ready, the 'accept' will block until message is ready.
                    // The amount
                    // of time to block is determined by the 'getWaitTime'
                    // method of the
                    // MultipleDelayFilter.
                    MailQueueItem queueItem = queue.deQueue();
                    Mail mail = queueItem.getMail();
                   
                    String key = mail.getName();
                    try {
                        if (isDebug) {
                            String message = Thread.currentThread().getName()
                                    + " will process mail " + key;
                            log(message);
                        }
                       
                        // Deliver message
                        if (deliver(mail, session)) {
                            // Message was successfully delivered/fully failed...
                            // delete it
                            LifecycleUtil.dispose(mail);
                            //workRepository.remove(key);
                        } else {
                            // Something happened that will delay delivery.
                            // Store it back in the retry repository.
                            //workRepository.store(mail);
                            int retries = 0;
                            try {
                                retries = Integer.parseInt(mail.getErrorMessage());
                            } catch (NumberFormatException e) {
                                // Something strange was happen with the errorMessage..
                            }
                           
                            long delay =  getNextDelay (retries);
                            queue.enQueue(mail, delay, TimeUnit.MILLISECONDS);
                            LifecycleUtil.dispose(mail);

                            // This is an update, so we have to unlock and
                            // notify or this mail is kept locked by this thread.
                            //workRepository.unlock(key);
                           
                            // Note: We do not notify because we updated an
                            // already existing mail and we are now free to handle
                            // more mails.
                            // Furthermore this mail should not be processed now
                            // because we have a retry time scheduling.
                        }
                       
                        // Clear the object handle to make sure it recycles
                        // this object.
                        mail = null;
                        queueItem.done(true);
                    } catch (Exception e) {
                        // Prevent unexpected exceptions from causing looping by
                        // removing message from outgoing.
                        // DO NOT CHANGE THIS to catch Error! For example, if
                        // there were an OutOfMemory condition caused because
                        // something else in the server was abusing memory, we would
                        // not want to start purging the retrying spool!
                        LifecycleUtil.dispose(mail);
                        //workRepository.remove(key);
                        queueItem.done(false);
                        throw new MailQueueException("Unable to perform dequeue", e);
                    }
                   
                  
                } catch (Throwable e) {
View Full Code Here


        while(active.get()) {
            numActive.incrementAndGet();

            try {
                MailQueueItem queueItem = queue.deQueue();
                Mail mail = queueItem.getMail();
                if (logger.isDebugEnabled()) {
                    StringBuffer debugBuffer =
                        new StringBuffer(64)
                                .append("==== Begin processing mail ")
                                .append(mail.getName())
                                .append("====");
                    logger.debug(debugBuffer.toString());
                }

                try {
                    mailProcessor.service(mail);
                    queueItem.done(true);
                } catch (Exception e) {
                    if (active.get() && logger.isErrorEnabled()) {
                        logger.error("Exception processing mail in JamesSpoolManager.run " + e.getMessage(), e);
                    }
                    queueItem.done(false);

                } finally {
                    LifecycleUtil.dispose(mail);
                    mail = null;
                }
View Full Code Here

                    // ready, the 'accept' will block until message is ready.
                    // The amount
                    // of time to block is determined by the 'getWaitTime'
                    // method of the
                    // MultipleDelayFilter.
                    MailQueueItem queueItem = queue.deQueue();
                    Mail mail = queueItem.getMail();

                    String key = mail.getName();

                    try {
                        if (isDebug) {
                            String message = Thread.currentThread().getName() + " will process mail " + key;
                            log(message);
                        }

                        // Deliver message
                        if (deliver(mail, session)) {
                            // Message was successfully delivered/fully
                            // failed...
                            // delete it
                            LifecycleUtil.dispose(mail);
                            // workRepository.remove(key);
                        } else {
                            // Something happened that will delay delivery.
                            // Store it back in the retry repository.
                            // workRepository.store(mail);
                            int retries = 0;
                            try {
                                retries = Integer.parseInt(mail.getErrorMessage());
                            } catch (NumberFormatException e) {
                                // Something strange was happen with the
                                // errorMessage..
                            }

                            long delay = getNextDelay(retries);

                            if (usePriority) {
                                // Use lowest priority for retries. See JAMES-1311
                                mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, MailPrioritySupport.LOW_PRIORITY);
                            }
                            queue.enQueue(mail, delay, TimeUnit.MILLISECONDS);
                            LifecycleUtil.dispose(mail);

                            // This is an update, so we have to unlock and
                            // notify or this mail is kept locked by this
                            // thread.
                            // workRepository.unlock(key);

                            // Note: We do not notify because we updated an
                            // already existing mail and we are now free to
                            // handle
                            // more mails.
                            // Furthermore this mail should not be processed now
                            // because we have a retry time scheduling.
                        }

                        // Clear the object handle to make sure it recycles
                        // this object.
                        mail = null;
                        queueItem.done(true);
                    } catch (Exception e) {
                        // Prevent unexpected exceptions from causing looping by
                        // removing message from outgoing.
                        // DO NOT CHANGE THIS to catch Error! For example, if
                        // there were an OutOfMemory condition caused because
                        // something else in the server was abusing memory, we
                        // would
                        // not want to start purging the retrying spool!
                        log("Exception caught in RemoteDelivery.run()", e);
                        LifecycleUtil.dispose(mail);
                        // workRepository.remove(key);
                        queueItem.done(false);
                        throw new MailQueueException("Unable to perform dequeue", e);
                    }

                } catch (Throwable e) {
                    if (!destroyed) {
View Full Code Here

        TimeUnit.MILLISECONDS.sleep(200);

        assertEquals(2, queue.getSize());

        MailQueueItem item = queue.deQueue();
        checkMail(mail, item.getMail());
        item.done(false);

        TimeUnit.MILLISECONDS.sleep(200);

        // ok we should get the same email again
        assertEquals(2, queue.getSize());
        MailQueueItem item2 = queue.deQueue();
        checkMail(mail, item2.getMail());
        item2.done(true);

        TimeUnit.MILLISECONDS.sleep(200);

        assertEquals(1, queue.getSize());
        MailQueueItem item3 = queue.deQueue();
        checkMail(mail2, item3.getMail());
        item3.done(true);

        TimeUnit.MILLISECONDS.sleep(200);

        // should be empty
        assertEquals(0, queue.getSize());
View Full Code Here

        TimeUnit.MILLISECONDS.sleep(200);

        assertEquals(2, queue.getSize());

        // as we enqueued the mail with delay we should get mail2 first
        MailQueueItem item = queue.deQueue();
        checkMail(mail2, item.getMail());
        item.done(true);

        TimeUnit.MILLISECONDS.sleep(200);

        assertEquals(1, queue.getSize());
        MailQueueItem item2 = queue.deQueue();
        long dequeueTime = System.currentTimeMillis() - enqueueTime;
        checkMail(mail, item2.getMail());
        item2.done(true);
        assertTrue(dequeueTime >= 2000);
        TimeUnit.MILLISECONDS.sleep(200);

        // should be empty
        assertEquals(0, queue.getSize());
View Full Code Here

            }
        });
        flushThread.start();

        // this will block until flush is called
        MailQueueItem item = queue.deQueue();
        checkMail(mail, item.getMail());
        item.done(true);

        long dequeueTime = System.currentTimeMillis() - enqueueTime;

        assertEquals(0, queue.getSize());
View Full Code Here

        assertEquals(2, queue.getSize());

        // we should get mail2 first as it has a higher priority set
        assertEquals(2, queue.getSize());
        MailQueueItem item2 = queue.deQueue();
        checkMail(mail2, item2.getMail());
        item2.done(true);

        TimeUnit.MILLISECONDS.sleep(200);

        assertEquals(1, queue.getSize());
        MailQueueItem item3 = queue.deQueue();
        checkMail(mail, item3.getMail());
        item3.done(true);

        TimeUnit.MILLISECONDS.sleep(200);

        // should be empty
        assertEquals(0, queue.getSize());
View Full Code Here

        checkMail(mail2, it.next().getMail());
        assertFalse(it.hasNext());
        it.close();

        assertEquals(2, queue.getSize());
        MailQueueItem item2 = queue.deQueue();
        checkMail(mail, item2.getMail());
        item2.done(true);
        TimeUnit.MILLISECONDS.sleep(200);

        assertEquals(1, queue.getSize());
        it = queue.browse();
        checkMail(mail2, it.next().getMail());
View Full Code Here

            logger.info("Queue=" + queue.toString());
        }

        while (active.get()) {

            final MailQueueItem queueItem;
            try {
                queueItem = queue.deQueue();
                workerService.execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            numActive.incrementAndGet();

                            // increase count
                            processingActive.incrementAndGet();

                            Mail mail = queueItem.getMail();
                            if (logger.isDebugEnabled()) {
                                String debugBuffer = "==== Begin processing mail " + mail.getName() + "====";
                                logger.debug(debugBuffer);
                            }

                            try {
                                mailProcessor.service(mail);
                                queueItem.done(true);
                            } catch (Exception e) {
                                if (active.get() && logger.isErrorEnabled()) {
                                    logger.error("Exception processing mail while spooling " + e.getMessage(), e);
                                }
                                queueItem.done(false);

                            } finally {
                                LifecycleUtil.dispose(mail);
                                mail = null;
                            }
View Full Code Here

TOP

Related Classes of org.apache.james.queue.api.MailQueue.MailQueueItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.