Package org.apache.james.queue.api.ManageableMailQueue

Examples of org.apache.james.queue.api.ManageableMailQueue.MailQueueIterator


        TimeUnit.MILLISECONDS.sleep(200);

        assertEquals(2, queue.getSize());

        MailQueueIterator it = queue.browse();
        checkMail(mail, it.next().getMail());
        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());
        assertFalse(it.hasNext());
        it.close();
    }
View Full Code Here


    }

    @Override
    @SuppressWarnings("unchecked")
    public List<CompositeData> browse() throws Exception {
        MailQueueIterator it = queue.browse();
        List<CompositeData> data = new ArrayList<CompositeData>();
        String[] names = new String[]{"name", "sender", "state", "recipients", "size", "lastUpdated", "remoteAddress", "remoteHost", "errorMessage", "attributes", "nextDelivery"};
        String[] descs = new String[]{"Unique name", "Sender", "Current state", "Recipients", "Size in bytes", "Timestamp of last update", "IPAddress of the sender", "Hostname of the sender", "Errormessage if any", "Attributes stored", "Timestamp of when the next delivery attempt will be make"};
        OpenType[] types = new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG};

        while (it.hasNext()) {

            MailQueueItemView mView = it.next();
            Mail m = mView.getMail();
            long nextDelivery = mView.getNextDelivery();
            Map<String, Object> map = new HashMap<String, Object>();
            map.put(names[0], m.getName());
            String sender = null;
            MailAddress senderAddress = m.getSender();
            if (senderAddress != null) {
                sender = senderAddress.toString();
            }
            map.put(names[1], sender);
            map.put(names[2], m.getState());

            StringBuilder rcptsBuilder = new StringBuilder();
            Collection<MailAddress> rcpts = m.getRecipients();
            if (rcpts != null) {
                Iterator<MailAddress> rcptsIt = rcpts.iterator();
                while (rcptsIt.hasNext()) {
                    rcptsBuilder.append(rcptsIt.next().toString());
                    if (rcptsIt.hasNext()) {
                        rcptsBuilder.append(",");
                    }
                }
            }
            map.put(names[3], rcptsBuilder.toString());
            map.put(names[4], m.getMessageSize());
            map.put(names[5], m.getLastUpdated().getTime());
            map.put(names[6], m.getRemoteAddr());
            map.put(names[7], m.getRemoteHost());
            map.put(names[8], m.getErrorMessage());
            Map<String, String> attrs = new HashMap<String, String>();
            Iterator<String> attrNames = m.getAttributeNames();
            while (attrNames.hasNext()) {
                String attrName = attrNames.next();
                String attrValueString = null;
                Serializable attrValue = m.getAttribute(attrName);
                if (attrValue != null) {
                    attrValueString = attrValue.toString();
                }
                attrs.put(attrName, attrValueString);
            }
            map.put(names[9], attrs.toString());
            map.put(names[10], nextDelivery);
            CompositeDataSupport c = new CompositeDataSupport(new CompositeType(Mail.class.getName(), "Queue Mail", names, descs, types), map);
            data.add(c);
        }
        it.close();
        return data;
    }
View Full Code Here

TOP

Related Classes of org.apache.james.queue.api.ManageableMailQueue.MailQueueIterator

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.