Example usage for javax.jms MapMessage getLong

List of usage examples for javax.jms MapMessage getLong

Introduction

In this page you can find the example usage for javax.jms MapMessage getLong.

Prototype


long getLong(String name) throws JMSException;

Source Link

Document

Returns the long value with the specified name.

Usage

From source file:com.vnet.demo.config.NoteMessageListener.java

@Override
public void receive(Message message) {
    MapMessage mapMessage = (MapMessage) message;
    try {/*  ww  w .  j a  va2 s . co  m*/
        Long id = mapMessage.getLong("ID");
        String opr = mapMessage.getString("OPR");

        noteService.syncNoteToIndex(id, opr);
    } catch (JMSException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.james.queue.activemq.ActiveMQMailQueue.java

/**
 * Try to use ActiveMQ StatisticsPlugin to get size and if that fails
 * fallback to {@link JMSMailQueue#getSize()}
 *//*from   w ww. ja  v a 2s.c om*/
@Override
public long getSize() throws MailQueueException {

    Connection connection = null;
    Session session = null;
    MessageConsumer consumer = null;
    MessageProducer producer = null;
    TemporaryQueue replyTo = null;
    long size = -1;

    try {
        connection = connectionFactory.createConnection();
        connection.start();

        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        replyTo = session.createTemporaryQueue();
        consumer = session.createConsumer(replyTo);

        Queue myQueue = session.createQueue(queuename);
        producer = session.createProducer(null);

        String queueName = "ActiveMQ.Statistics.Destination." + myQueue.getQueueName();
        Queue query = session.createQueue(queueName);

        Message msg = session.createMessage();
        msg.setJMSReplyTo(replyTo);
        producer.send(query, msg);
        MapMessage reply = (MapMessage) consumer.receive(2000);
        if (reply != null && reply.itemExists("size")) {
            try {
                size = reply.getLong("size");
                return size;
            } catch (NumberFormatException e) {
                // if we hit this we can't calculate the size so just catch
                // it
            }
        }

    } catch (Exception e) {
        throw new MailQueueException("Unable to remove mails", e);

    } finally {

        if (consumer != null) {

            try {
                consumer.close();
            } catch (JMSException e1) {
                e1.printStackTrace();
                // ignore on rollback
            }
        }

        if (producer != null) {

            try {
                producer.close();
            } catch (JMSException e1) {
                // ignore on rollback
            }
        }

        if (replyTo != null) {
            try {

                // we need to delete the temporary queue to be sure we will
                // free up memory if thats not done and a pool is used
                // its possible that we will register a new mbean in jmx for
                // every TemporaryQueue which will never get unregistered
                replyTo.delete();
            } catch (JMSException e) {
            }
        }
        try {
            if (session != null)
                session.close();
        } catch (JMSException e1) {
            // ignore here
        }

        try {
            if (connection != null)
                connection.close();
        } catch (JMSException e1) {
            // ignore here
        }
    }

    // if we came to this point we should just fallback to super method
    return super.getSize();
}

From source file:hermes.ext.imq.ImqAdmin.java

@Override
public void onMessage(Message msg) {

    try {//from   w w  w .j av a  2  s.  com

        MapMessage mapMsg = (MapMessage) msg;
        String type = mapMsg.getStringProperty("type");

        LOG.debug("Got admin message from broker of type: " + type);

        if (type.equals(DEST_LIST_TOPIC_NAME)) {
            List<DestinationConfig> result = new ArrayList<DestinationConfig>();

            for (@SuppressWarnings("unchecked")
            Enumeration e = mapMsg.getMapNames(); e.hasMoreElements();) {
                String name = (String) e.nextElement();

                @SuppressWarnings("unchecked")
                Map<String, String> object = (Map<String, String>) mapMsg.getObject(name);

                DestinationConfig dest = HermesBrowser.getConfigDAO().createDestinationConfig();
                dest.setName(object.get("name"));
                dest.setShortName(object.get("name"));
                dest.setDomain("queue".equals(object.get("type")) ? Domain.QUEUE.getId()
                        : ("topic".equals(object.get("type")) ? Domain.TOPIC.getId() : Domain.UNKNOWN.getId()));

                result.add(dest);
            }

            Collections.sort(result, new Comparator<DestinationConfig>() {
                @Override
                public int compare(DestinationConfig o1, DestinationConfig o2) {
                    return o1.getShortName().compareTo(o2.getShortName());
                }
            });

            destinations = result;

            synchronized (destListGuard) {
                destListGuard.notifyAll();
            }

        } else if (type.startsWith(QUEUE_METRICS_TOPIC_PREFIX)) {
            LOG.debug("Got queue metrics: " + type);

            String queueName = type.substring(QUEUE_METRICS_TOPIC_PREFIX.length());
            messageCounts.put(queueName, mapMsg.getLong("numMsgs"));
            HashMap<String, Long> map = new HashMap<String, Long>();

            @SuppressWarnings("unchecked")
            Enumeration<String> e = mapMsg.getMapNames();
            while (e.hasMoreElements()) {
                String name = e.nextElement();
                map.put(name, mapMsg.getLong(name));
            }
            stats.put(queueName, map);
            LOG.debug("Stored stats for: " + queueName);

            synchronized (destMetricGuard) {
                destMetricGuard.notifyAll();
            }

        } else if (type.startsWith(TOPIC_METRICS_TOPIC_PREFIX)) {
            LOG.debug("Got topic metrics: " + type);

            String topicName = type.substring(TOPIC_METRICS_TOPIC_PREFIX.length());
            messageCounts.put(topicName, mapMsg.getLong("numMsgs"));

            HashMap<String, Long> map = new HashMap<String, Long>();

            @SuppressWarnings("unchecked")
            Enumeration<String> e = mapMsg.getMapNames();
            while (e.hasMoreElements()) {
                String name = e.nextElement();
                map.put(name, mapMsg.getLong(name));
            }
            stats.put(topicName, map);
            LOG.debug("Stored stats for: " + topicName);

            synchronized (destMetricGuard) {
                destMetricGuard.notifyAll();
            }
        }

    } catch (JMSException e) {
        throw new RuntimeException(e);
    }
}

From source file:ubic.gemma.job.grid.util.JMSBrokerMonitorImpl.java

@Override
public int getNumberOfWorkerHosts() throws JMSException {
    MapMessage reply = sendTaskSubmissionQueueDiagnosticMessage();
    return (int) reply.getLong("consumerCount");
}

From source file:ubic.gemma.job.grid.util.JMSBrokerMonitorImpl.java

@Override
public int getTaskSubmissionQueueLength() throws JMSException {
    MapMessage reply = sendTaskSubmissionQueueDiagnosticMessage();
    return (int) reply.getLong("enqueueCount");
}