@PreRemove void onPreRemove(Object entity) { String entityName = entity.getClass().getName(); if (TrackedEntityUtils.isTrackedEntity(entityName)) { try { Session session = createSession(); MapMessage message = session.createMapMessage(); message.setLong("time", System.currentTimeMillis()); message.setString("entity", entityName); message.setString("eventType", EventType.Delete.name()); message.setObject("id", getEntityId(entity)); Long loggedUserId = getLoggedUserId(); if (loggedUserId != null) message.setLong("loggedUserId", loggedUserId); sendMessage(session, message); } catch (JMSException e) { throw new EventException(e); } catch (NamingException e) { throw new EventException(e); } } }
/** * Set * * @param name The name * @param value The value * @throws JMSException Thrown if an error occurs */ @Override public void setLong(final String name, final long value) throws JMSException { if (ActiveMQRAMapMessage.trace) { ActiveMQRALogger.LOGGER.trace("setLong(" + name + ", " + value + ")"); } ((MapMessage) message).setLong(name, value); }
/** * @param type * @throws JMSException */ private Object createBodySendAndReceive(JmsMessageType type) throws JMSException { Object res = null; Message msg = null; switch (type) { case BYTE: BytesMessage mByte = queueProducerSession.createBytesMessage(); final int size = 20; byte[] resByte = new byte[size]; for (int i = 0; i < size; i++) { resByte[i] = (byte) i; mByte.writeByte((byte) i); } msg = mByte; res = resByte; break; case TEXT: res = "JMS2"; msg = queueProducerSession.createTextMessage("JMS2"); break; case STREAM: msg = queueProducerSession.createStreamMessage(); break; case OBJECT: res = new Double(37.6); msg = queueProducerSession.createObjectMessage(new Double(37.6)); break; case MAP: MapMessage msg1 = queueProducerSession.createMapMessage(); msg1.setInt("int", 13); msg1.setLong("long", 37L); msg1.setString("string", "crocodile"); msg = msg1; Map<String, Object> map = new HashMap<String, Object>(); map.put("int", Integer.valueOf(13)); map.put("long", Long.valueOf(37L)); map.put("string", "crocodile"); res = map; break; default: Assert.fail("no default..."); } Assert.assertNotNull(msg); msg.setStringProperty("type", type.toString()); queueProducer.send(msg); return res; }
@Override public JMSProducer send(Destination destination, Map<String, Object> body) { MapMessage message = context.createMapMessage(); if (body != null) { try { for (Entry<String, Object> entry : body.entrySet()) { final String name = entry.getKey(); final Object v = entry.getValue(); if (v instanceof String) { message.setString(name, (String) v); } else if (v instanceof Long) { 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); } else if (v instanceof Character) { message.setChar(name, (Character) v); } else if (v instanceof Short) { message.setShort(name, (Short) v); } else if (v instanceof Boolean) { message.setBoolean(name, (Boolean) v); } else if (v instanceof Float) { message.setFloat(name, (Float) v); } else if (v instanceof Byte) { message.setByte(name, (Byte) v); } else if (v instanceof byte[]) { byte[] array = (byte[]) v; message.setBytes(name, array, 0, array.length); } else { message.setObject(name, v); } } } catch (JMSException e) { throw new MessageFormatRuntimeException(e.getMessage()); } } send(destination, message); return this; }