Search in sources :

Example 11 with MapMessage

use of javax.jms.MapMessage in project wildfly by wildfly.

the class TestEnvEntryMDBean method onMessage.

public void onMessage(Message msg) {
    log.trace("OnMessage working...");
    try {
        Destination destination = msg.getJMSReplyTo();
        Connection conn = connectionFactory.createConnection();
        try {
            Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer replyProducer = session.createProducer(destination);
            MapMessage replyMsg = session.createMapMessage();
            replyMsg.setJMSCorrelationID(msg.getJMSMessageID());
            replyMsg.setInt("maxExceptions", maxExceptions);
            replyMsg.setInt("numExceptions", numExceptions);
            replyMsg.setInt("minExceptions", minExceptions);
            // System.err.println("reply to: " + destination);
            // System.err.println("maxExceptions: " + maxExceptions);
            // System.err.println("numExceptions: " + numExceptions);
            // System.err.println("minExceptions: " + minExceptions);
            replyProducer.send(replyMsg);
        } finally {
            conn.close();
        }
    } catch (JMSException e) {
        throw new RuntimeException(e);
    }
}
Also used : Destination(javax.jms.Destination) MapMessage(javax.jms.MapMessage) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 12 with MapMessage

use of javax.jms.MapMessage in project qpid by apache.

the class Agent method subscriptionResponse.

/**
     * If the subscription request is successful, the Agent application must provide a unique subscriptionId.
     * <p>
     * If replying to a sucessful subscription refresh, the original subscriptionId must be supplied.
     * <p>
     * If the subscription or refresh fails, the subscriptionId should be set to null and error may be set to
     * an application-specific QmfData instance that describes the error.
     * <p>
     * Should a refresh request fail, the consoleHandle may be set to null if unknown.
     *
     * @param handle the handle from the WorkItem.
     * @param consoleHandle the console reply handle.
     * @param subscriptionId a unique handle for the subscription supplied by the Agent.
     * @param lifetime should be set to the duration of the subscription in seconds.
     * @param publishInterval should be set to the time interval in seconds between successive publications
     *          on this subscription.
     * @param error an application-specific QmfData instance that describes the error.
     */
public final void subscriptionResponse(final Handle handle, final Handle consoleHandle, final String subscriptionId, final long lifetime, final long publishInterval, final QmfData error) {
    try {
        MapMessage response = _syncSession.createMapMessage();
        response.setJMSCorrelationID(handle.getCorrelationId());
        response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
        response.setStringProperty("method", "response");
        response.setStringProperty("qmf.opcode", "_subscribe_response");
        response.setStringProperty("qmf.agent", _name);
        response.setStringProperty("qpid.subject", handle.getRoutingKey());
        if (error == null) {
            response.setObject("_subscription_id", subscriptionId);
            response.setObject("_duration", lifetime);
            response.setObject("_interval", publishInterval);
        } else {
            Map<String, Object> errorMap = error.mapEncode();
            for (Map.Entry<String, Object> entry : errorMap.entrySet()) {
                response.setObject(entry.getKey(), entry.getValue());
            }
        }
        sendResponse(handle, response);
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in subscriptionResponse()", jmse.getMessage());
    }
}
Also used : MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 13 with MapMessage

use of javax.jms.MapMessage in project qpid by apache.

the class Agent method raiseException.

/**
     * Send an exception back to the Console.
     * @param handle the reply handle that contains the replyTo Address.
     * @param message the exception message.
     */
public final void raiseException(final Handle handle, final String message) {
    try {
        MapMessage response = _syncSession.createMapMessage();
        response.setJMSCorrelationID(handle.getCorrelationId());
        response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
        response.setStringProperty("method", "response");
        response.setStringProperty("qmf.opcode", "_exception");
        response.setStringProperty("qmf.agent", _name);
        response.setStringProperty("qpid.subject", handle.getRoutingKey());
        QmfData exception = new QmfData();
        exception.setValue("error_text", message);
        response.setObject("_values", exception.mapEncode());
        sendResponse(handle, response);
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in handleLocateRequest()", jmse.getMessage());
    }
}
Also used : QmfData(org.apache.qpid.qmf2.common.QmfData) MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException)

Example 14 with MapMessage

use of javax.jms.MapMessage in project qpid by apache.

the class Console method getClasses.

/**
     * Return a list of SchemaClassIds for all available Schema for the specified Agent.
     * @param agent the Agent being queried
     * @return a list of SchemaClassIds for all available Schema for the specified Agent.
     */
public List<SchemaClassId> getClasses(final Agent agent) {
    // First look to see if there are cached results and if there are return those.
    List<SchemaClassId> results = agent.getClasses();
    if (results.size() > 0) {
        return results;
    }
    String agentName = agent.getName();
    results = new ArrayList<SchemaClassId>();
    try {
        MapMessage request = _syncSession.createMapMessage();
        request.setJMSReplyTo(_replyAddress);
        request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
        request.setStringProperty("method", "request");
        request.setStringProperty("qmf.opcode", "_query_request");
        request.setStringProperty("qpid.subject", agentName);
        // Create a QMF Query for an "SCHEMA_ID" target
        request.setObject("_what", "SCHEMA_ID");
        // it would be somewhat unfortunate if their response got interleaved with ours!!
        synchronized (this) {
            _requester.send(request);
            Message response = _responder.receive(_replyTimeout * 1000);
            if (response == null) {
                _log.info("No response received in getClasses()");
                return Collections.emptyList();
            }
            if (AMQPMessage.isAMQPList(response)) {
                List<Map> mapResults = AMQPMessage.getList(response);
                for (Map content : mapResults) {
                    //new SchemaClassId(content).listValues();
                    results.add(new SchemaClassId(content));
                }
            } else if (AMQPMessage.isAMQPMap(response)) {
            // Error responses are returned as MapMessages, though they are being ignored here.
            //System.out.println("Console.getClasses() no results for " + agentName);
            //QmfData exception = new QmfData(AMQPMessage.getMap(response));
            //System.out.println(agentName + " " + exception.getStringValue("error_text"));
            } else {
                _log.info("getClasses() Received response message in incorrect format");
            }
        }
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in getClasses()", jmse.getMessage());
    }
    agent.setClasses(results);
    return results;
}
Also used : AMQPMessage(org.apache.qpid.qmf2.common.AMQPMessage) MapMessage(javax.jms.MapMessage) Message(javax.jms.Message) MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException) SchemaClassId(org.apache.qpid.qmf2.common.SchemaClassId) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 15 with MapMessage

use of javax.jms.MapMessage in project qpid by apache.

the class Console method getSchema.

/**
     * Return a list of all available class SchemaClass from a specified Agent.
     * <p>
     * This call will return cached information if it is available.  If not, it will send a query message
     * to the remote agent and block waiting for a response. The timeout argument specifies the maximum time
     * to wait for a response from the agent.
     *
     * @param schemaClassId the SchemaClassId we wish to return schema information for.
     * @param agent the Agent we want to retrieve the schema from
     */
public List<SchemaClass> getSchema(final SchemaClassId schemaClassId, final Agent agent) {
    // First look to see if there are cached results and if there are return those.
    List<SchemaClass> results = agent.getSchema(schemaClassId);
    if (results.size() > 0) {
        return results;
    }
    String agentName = agent.getName();
    //System.out.println("getSchema for agent " + agentName);
    results = new ArrayList<SchemaClass>();
    try {
        MapMessage request = _syncSession.createMapMessage();
        request.setJMSReplyTo(_replyAddress);
        request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
        request.setStringProperty("method", "request");
        request.setStringProperty("qmf.opcode", "_query_request");
        request.setStringProperty("qpid.subject", agentName);
        // Create a QMF Query for an "SCHEMA" target
        request.setObject("_what", "SCHEMA");
        request.setObject("_schema_id", schemaClassId.mapEncode());
        // it would be somewhat unfortunate if their response got interleaved with ours!!
        synchronized (this) {
            _requester.send(request);
            Message response = _responder.receive(_replyTimeout * 1000);
            if (response == null) {
                _log.info("No response received in getSchema()");
                return Collections.emptyList();
            }
            if (AMQPMessage.isAMQPList(response)) {
                List<Map> mapResults = AMQPMessage.getList(response);
                for (Map content : mapResults) {
                    SchemaClass schema = new SchemaObjectClass(content);
                    if (schema.getClassId().getType().equals("_event")) {
                        schema = new SchemaEventClass(content);
                    }
                    //schema.listValues();
                    results.add(schema);
                }
            } else if (AMQPMessage.isAMQPMap(response)) {
            // Error responses are returned as MapMessages, though they are being ignored here.
            //System.out.println("Console.getSchema() no results for " + agentName);
            //QmfData exception = new QmfData(AMQPMessage.getMap(response));
            //System.out.println(agentName + " " + exception.getStringValue("error_text"));
            } else {
                _log.info("getSchema() Received response message in incorrect format");
            }
        }
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in getSchema()", jmse.getMessage());
    }
    agent.setSchema(schemaClassId, results);
    return results;
}
Also used : AMQPMessage(org.apache.qpid.qmf2.common.AMQPMessage) MapMessage(javax.jms.MapMessage) Message(javax.jms.Message) SchemaEventClass(org.apache.qpid.qmf2.common.SchemaEventClass) SchemaClass(org.apache.qpid.qmf2.common.SchemaClass) MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException) SchemaObjectClass(org.apache.qpid.qmf2.common.SchemaObjectClass) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

MapMessage (javax.jms.MapMessage)30 JMSException (javax.jms.JMSException)23 HashMap (java.util.HashMap)12 Map (java.util.Map)9 TextMessage (javax.jms.TextMessage)9 BytesMessage (javax.jms.BytesMessage)8 Message (javax.jms.Message)8 Session (javax.jms.Session)8 Destination (javax.jms.Destination)7 ObjectMessage (javax.jms.ObjectMessage)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 Test (org.junit.Test)6 AMQPMessage (org.apache.qpid.qmf2.common.AMQPMessage)5 Connection (javax.jms.Connection)4 MessageProducer (javax.jms.MessageProducer)4 QmfException (org.apache.qpid.qmf2.common.QmfException)4 MessageFormatException (javax.jms.MessageFormatException)3 StreamMessage (javax.jms.StreamMessage)3 QmfData (org.apache.qpid.qmf2.common.QmfData)3 SimpleMessageConverter (org.springframework.jms.support.converter.SimpleMessageConverter)3