/** * If the given {@code message.getBinaryData()} is not {@code null} delegates to * {@link #sendWithBinaryData(ProducerConnectionContext, BasicMessage, InputStream, Map)} otherwise delegates to * {@link #send(ProducerConnectionContext, BasicMessageWithExtraData, Map)} * * @param context information that determines where the message is sent * @param message the message to send * @param headers headers for the JMS transport that will override same-named headers in the basic message * @return the message ID * @throws JMSException any error */ public <T extends BasicMessage> MessageId send(ProducerConnectionContext context, BasicMessageWithExtraData<T> message, Map<String, String> headers) throws JMSException { if (message.getBinaryData() == null) { return send(context, message.getBasicMessage(), headers); } else { return sendWithBinaryData(context, message.getBasicMessage(), message.getBinaryData(), headers); } }
String receivedBody = ((TextMessage) message).getText(); T basicMessage = AbstractMessage.fromJSON(receivedBody, basicMessageClass); retVal = new BasicMessageWithExtraData<T>(basicMessage, null); retVal.getBasicMessage().setMessageId(new MessageId(message.getJMSMessageID())); if (message.getJMSCorrelationID() != null) { MessageId correlationId = new MessageId(message.getJMSCorrelationID()); retVal.getBasicMessage().setCorrelationId(correlationId); retVal.getBasicMessage().setHeaders(rawHeaders); getLog().tracef("Received basic message: %s", retVal.getBasicMessage().getClass());
/** * Subclasses implement this method to process the received message. * * If subclasses would rather just receive the {@link BasicMessage}, it can do so by * overriding {@link #onBasicMessage(BasicMessage)} and leaving this method as-is (that is, * do NOT override this method). * * @param msgWithExtraData the basic message received with any extra data that came with it */ protected void onBasicMessage(BasicMessageWithExtraData<T> msgWithExtraData) { onBasicMessage(msgWithExtraData.getBasicMessage()); // delegate }
/** * Deserializes a JSON string in {@link #toHawkularFormat(BasicMessage) Hawkular format}. * The JSON object is returned. * * @param nameAndJson the string to be deserialized * @return the object represented by the JSON */ public <T extends BasicMessage> BasicMessageWithExtraData<T> deserialize(String nameAndJson) { String[] nameAndJsonArray = fromHawkularFormat(nameAndJson); String name = nameAndJsonArray[0]; String json = nameAndJsonArray[1]; // The name is the actual name of the POJO that is used to deserialize the JSON. // If not fully qualified with a package then assume it is in our package. if (name.indexOf(".") == -1) { name = String.format("%s.%s", API_PKG, name); } try { Class<T> pojo = (Class<T>) Class.forName(name); return new BasicMessageWithExtraData(AbstractMessage.fromJSON(json, pojo), null); } catch (Exception e) { throw new RuntimeException("Cannot deserialize: [" + nameAndJson + "]", e); } }
String receivedBody = ((TextMessage) message).getText(); T basicMessage = AbstractMessage.fromJSON(receivedBody, basicMessageClass); retVal = new BasicMessageWithExtraData<T>(basicMessage, null); retVal.getBasicMessage().setMessageId(new MessageId(message.getJMSMessageID())); if (message.getJMSCorrelationID() != null) { MessageId correlationId = new MessageId(message.getJMSCorrelationID()); retVal.getBasicMessage().setCorrelationId(correlationId); retVal.getBasicMessage().setHeaders(rawHeaders); getLog().tracef("Received basic message: %s", retVal.getBasicMessage().getClass());
/** * Subclasses implement this method to process the received message. * * If subclasses would rather just receive the {@link BasicMessage}, it can do so by * overriding {@link #onBasicMessage(BasicMessage)} and leaving this method as-is (that is, * do NOT override this method). * * @param msgWithExtraData the basic message received with any extra data that came with it */ protected void onBasicMessage(BasicMessageWithExtraData<T> msgWithExtraData) { onBasicMessage(msgWithExtraData.getBasicMessage()); // delegate }
throw new IllegalArgumentException("Stream cannot be converted to JSON object of type [" + clazz + "]", e); return new BasicMessageWithExtraData<T>(obj, new BinaryData(remainder, in));
/** * If the given {@code message.getBinaryData()} is not {@code null} delegates to * {@link #sendWithBinaryData(ProducerConnectionContext, BasicMessage, InputStream, Map)} otherwise delegates to * {@link #send(ProducerConnectionContext, BasicMessageWithExtraData, Map)} * * @param context information that determines where the message is sent * @param message the message to send * @param headers headers for the JMS transport that will override same-named headers in the basic message * @return the message ID * @throws JMSException any error */ public <T extends BasicMessage> MessageId send(ProducerConnectionContext context, BasicMessageWithExtraData<T> message, Map<String, String> headers) throws JMSException { if (message.getBinaryData() == null) { return send(context, message.getBasicMessage(), headers); } else { return sendWithBinaryData(context, message.getBasicMessage(), message.getBinaryData(), headers); } }
/** * Subclasses implement this method to process the received message. * * If subclasses would rather just receive the {@link AbstractMessage}, it can do so by * overriding the onBasicMessage method that just takes the message type as a parameter * and leaving this method as-is (that is, do NOT override this method). * * @param msgWithExtraData the basic message received with any extra data that came with it * @return the response message - this will be forwarded to the sender of the request message */ protected U onBasicMessage(BasicMessageWithExtraData<T> msgWithExtraData) { return onBasicMessage(msgWithExtraData.getBasicMessage()); }
throw new IllegalArgumentException("Stream cannot be converted to JSON object of type [" + clazz + "]", e); return new BasicMessageWithExtraData<T>(obj, new BinaryData(remainder, in));
/** * Subclasses implement this method to process the received message. * * If subclasses would rather just receive the {@link AbstractMessage}, it can do so by * overriding the onBasicMessage method that just takes the message type as a parameter * and leaving this method as-is (that is, do NOT override this method). * * @param msgWithExtraData the basic message received with any extra data that came with it * @return the response message - this will be forwarded to the sender of the request message */ protected U onBasicMessage(BasicMessageWithExtraData<T> msgWithExtraData) { return onBasicMessage(msgWithExtraData.getBasicMessage()); }
UpdateCollectionIntervalsRequest request = envelope.getBasicMessage(); Map<PathAddress, String> metricTypes = filterUpdates(mcc, request.getMetricTypes(), false, agentAddress); Map<PathAddress, String> availTypes = filterUpdates(mcc, request.getAvailTypes(), true, agentAddress);