static protected MapMessage createMapMessage() throws JMSException { MapMessage mapMessage = new ActiveMQMapMessage(); mapMessage.setString("name", "Arnold"); mapMessage.setInt("age", 97); mapMessage.setDouble("xyz", 89686.564); mapMessage.setBoolean("good", true); return mapMessage; }
message.setLong(name, (Long) v); } else if (v instanceof Double) { message.setDouble(name, (Double) v); } else if (v instanceof Integer) { message.setInt(name, (Integer) v);
@Override public void setDouble(final String name, final double value) throws JMSException { message.setDouble(name, value); }
public void setDouble(String name, double value) throws JMSException { ((MapMessage) message).setDouble(name, value); }
public void setDouble(String name, double value) throws JMSException { ((MapMessage) message).setDouble(name, value); }
/** * Set * @param name The name * @param value The value * @exception JMSException Thrown if an error occurs */ public void setDouble(final String name, final double value) throws JMSException { if (_log.isTraceEnabled()) { _log.trace("setDouble(" + name + ", " + value + ")"); } ((MapMessage)_message).setDouble(name, value); }
/** * Set * * @param name The name * @param value The value * @throws JMSException Thrown if an error occurs */ @Override public void setDouble(final String name, final double value) throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("setDouble(" + name + ", " + value + ")"); } ((MapMessage) message).setDouble(name, value); }
/** * Set * * @param name The name * @param value The value * @throws JMSException Thrown if an error occurs */ @Override public void setDouble(final String name, final double value) throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("setDouble(" + name + ", " + value + ")"); } ((MapMessage) message).setDouble(name, value); }
/** * Test that the <code>MapMessage.getMapNames()</code> method returns an * empty <code>Enumeration</code> when no map has been defined before. * <br /> * Also test that the same method returns the correct names of the map. */ public void testgetMapNames() { try { MapMessage message = senderSession.createMapMessage(); Enumeration e = message.getMapNames(); assertTrue("No map yet defined.\n", !e.hasMoreElements()); message.setDouble("pi", 3.14159); e = message.getMapNames(); assertEquals("pi", (String) (e.nextElement())); } catch (JMSException e) { fail(e); } }
private void mapToMapMessage(final Map<?, ?> map, MapMessage mapMessage) throws JMSException { for(Entry<?, ?> entry : map.entrySet()) { String key = entry.getKey().toString(); Object value = entry.getValue(); if(value instanceof String) { mapMessage.setString(key, (String)value); } else if(value instanceof Integer) { mapMessage.setInt(key, (Integer)value); } else if(value instanceof Long) { mapMessage.setLong(key, (Long)value); } else if(value instanceof Double) { mapMessage.setDouble(key, (Double)value); } else if(value instanceof Float) { mapMessage.setFloat(key, (Float)value); } else if(value instanceof Boolean) { mapMessage.setBoolean(key, (Boolean)value); } else if(value instanceof Short) { mapMessage.setShort(key, (Short)value); } else if(value instanceof Byte) { mapMessage.setByte(key, (Byte)value); } else if(value instanceof Character) { mapMessage.setChar(key, (Character)value); } else if(value instanceof byte[]) { mapMessage.setBytes(key, (byte[])value); } else { mapMessage.setString(key, value.toString()); } } }
/** * Test in MapMessage the conversion between <code>getObject("foo")</code> and * <code>getDouble("foo")</code> (the later returning a java.lang.Double and the former a double) */ public void testMapMessageConversion() { try { MapMessage message = senderSession.createMapMessage(); message.setDouble("pi", 3.14159); sender.send(message); Message m = receiver.receive(TestConfig.TIMEOUT); assertTrue("The message should be an instance of MapMessage.\n", m instanceof MapMessage); MapMessage msg = (MapMessage) m; assertTrue(msg.getObject("pi") instanceof Double); assertEquals(3.14159, ((Double) msg.getObject("pi")).doubleValue(), 0); assertEquals(3.14159, msg.getDouble("pi"), 0); } catch (JMSException e) { fail(e); } }
private void sendMapMessageUsingCoreJms(String queueName) throws Exception { Connection jmsConn = null; try { jmsConn = coreCf.createConnection(); Session session = jmsConn.createSession(false, Session.AUTO_ACKNOWLEDGE); MapMessage mapMessage = session.createMapMessage(); mapMessage.setBoolean("aboolean", true); mapMessage.setByte("abyte", (byte) 4); mapMessage.setBytes("abytes", new byte[]{4, 5}); mapMessage.setChar("achar", 'a'); mapMessage.setDouble("adouble", 4.4); mapMessage.setFloat("afloat", 4.5f); mapMessage.setInt("aint", 40); mapMessage.setLong("along", 80L); mapMessage.setShort("ashort", (short) 65); mapMessage.setString("astring", "hello"); Queue queue = session.createQueue(queueName); MessageProducer producer = session.createProducer(queue); producer.send(mapMessage); } finally { if (jmsConn != null) { jmsConn.close(); } } }
/** * Test that the <code>MapMessage.getMapNames()</code> method returns an * empty <code>Enumeration</code> when no map has been defined before. * <br /> * Also test that the same method returns the correct names of the map. */ @Test public void testgetMapNames() { try { MapMessage message = senderSession.createMapMessage(); Enumeration<?> e = message.getMapNames(); Assert.assertTrue("No map yet defined.\n", !e.hasMoreElements()); message.setDouble("pi", 3.14159); e = message.getMapNames(); Assert.assertEquals("pi", e.nextElement()); } catch (JMSException e) { fail(e); } }
@Test public void testResendWithMapMessagesOnly() throws Exception { conn = cf.createConnection(); conn.start(); Session sess = conn.createSession(true, Session.SESSION_TRANSACTED); ArrayList<Message> msgs = new ArrayList<>(); for (int i = 0; i < 1; i++) { MapMessage mm = sess.createMapMessage(); mm.setBoolean("boolean", true); mm.setByte("byte", (byte) 3); mm.setBytes("bytes", new byte[]{(byte) 3, (byte) 4, (byte) 5}); mm.setChar("char", (char) 6); mm.setDouble("double", 7.0); mm.setFloat("float", 8.0f); mm.setInt("int", 9); mm.setLong("long", 10L); mm.setObject("object", new String("this is an object")); mm.setShort("short", (short) 11); mm.setString("string", "this is a string"); msgs.add(mm); MapMessage emptyMap = sess.createMapMessage(); msgs.add(emptyMap); } internalTestResend(msgs, sess); }
/** * Send a <code>MapMessage</code> with 2 Java primitives in its body (a <code> * String</code> and a <code>double</code>). * <br /> * Receive it and test that the values of the primitives of the body are correct */ public void testMapMessage_2() { try { MapMessage message = senderSession.createMapMessage(); message.setString("name", "pi"); message.setDouble("value", 3.14159); sender.send(message); Message m = receiver.receive(TestConfig.TIMEOUT); assertTrue("The message should be an instance of MapMessage.\n", m instanceof MapMessage); MapMessage msg = (MapMessage) m; assertEquals("pi", msg.getString("name")); assertEquals(3.14159, msg.getDouble("value"), 0); } catch (JMSException e) { fail(e); } }
private void sendCompressedMapMessageUsingOpenWire() throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination); MapMessage mapMessage = session.createMapMessage(); mapMessage.setBoolean("boolean-type", true); mapMessage.setByte("byte-type", (byte) 10); mapMessage.setBytes("bytes-type", TEXT.getBytes()); mapMessage.setChar("char-type", 'A'); mapMessage.setDouble("double-type", 55.3D); mapMessage.setFloat("float-type", 79.1F); mapMessage.setInt("int-type", 37); mapMessage.setLong("long-type", 56652L); mapMessage.setObject("object-type", new String("VVVV")); mapMessage.setShort("short-type", (short) 333); mapMessage.setString("string-type", TEXT); producer.send(mapMessage); }
private void sendMapMessageUsingOpenWire() throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); System.out.println("destination: " + destination); final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination); MapMessage mapMessage = session.createMapMessage(); mapMessage.setBoolean("aboolean", true); mapMessage.setByte("abyte", (byte) 4); mapMessage.setBytes("abytes", new byte[]{4, 5}); mapMessage.setChar("achar", 'a'); mapMessage.setDouble("adouble", 4.4); mapMessage.setFloat("afloat", 4.5f); mapMessage.setInt("aint", 40); mapMessage.setLong("along", 80L); mapMessage.setShort("ashort", (short) 65); mapMessage.setString("astring", "hello"); producer.send(mapMessage); }
@Override protected void prepareMessage(final Message m) throws JMSException { super.prepareMessage(m); MapMessage mm = (MapMessage) m; mm.setBoolean("boolean", true); mm.setByte("byte", (byte) 3); mm.setBytes("bytes", new byte[]{(byte) 3, (byte) 4, (byte) 5}); mm.setChar("char", (char) 6); mm.setDouble("double", 7.0); mm.setFloat("float", 8.0f); mm.setInt("int", 9); mm.setLong("long", 10L); mm.setObject("object", new String("this is an object")); mm.setShort("short", (short) 11); mm.setString("string", "this is a string"); }
/** * Test in MapMessage the conversion between <code>getObject("foo")</code> and * <code>getDouble("foo")</code> (the later returning a java.lang.Double and the former a double) */ @Test public void testMapMessageConversion() { try { MapMessage message = senderSession.createMapMessage(); message.setDouble("pi", 3.14159); sender.send(message); Message m = receiver.receive(TestConfig.TIMEOUT); Assert.assertTrue("The message should be an instance of MapMessage.\n", m instanceof MapMessage); MapMessage msg = (MapMessage) m; Assert.assertTrue(msg.getObject("pi") instanceof Double); Assert.assertEquals(3.14159, ((Double) msg.getObject("pi")).doubleValue(), 0); Assert.assertEquals(3.14159, msg.getDouble("pi"), 0); } catch (JMSException e) { fail(e); } }
/** * Send a <code>MapMessage</code> with 2 Java primitives in its body (a <code> * String</code> and a <code>double</code>). * <br /> * Receive it and test that the values of the primitives of the body are correct */ @Test public void testMapMessage_2() { try { MapMessage message = senderSession.createMapMessage(); message.setString("name", "pi"); message.setDouble("value", 3.14159); sender.send(message); Message m = receiver.receive(TestConfig.TIMEOUT); Assert.assertTrue("The message should be an instance of MapMessage.\n", m instanceof MapMessage); MapMessage msg = (MapMessage) m; Assert.assertEquals("pi", msg.getString("name")); Assert.assertEquals(3.14159, msg.getDouble("value"), 0); } catch (JMSException e) { fail(e); } }