Examples of BytesMessage


Examples of javax.jms.BytesMessage

        {
            throw new MessageFormatException("Attempting to do AMQPMessage.getList() on null Message");
        }
        else if (message instanceof BytesMessage)
        {
            BytesMessage msg = (BytesMessage)message;

            //only handles responses up to 2^31-1 bytes long
            byte[] data = new byte[(int) msg.getBodyLength()];
            msg.readBytes(data);
            BBDecoder decoder = new BBDecoder();
            decoder.init(ByteBuffer.wrap(data));
            return (List<T>)decoder.readList();
        }
        else if (message instanceof MapMessage)
        {   /*
             * In Qpid version 0.20 instead of exposing amqp/list as a BytesMessage as above rather it is exposed
             * as a MapMessage!!??? the Object Keys are the indices into the List. We create a java.util.List
             * out of this by iterating through the getMapNames() Enumeration and copying the Objects into the List.
             * This amount of copying doesn't feel healthy and we can't even work out the capacity for the List
             * a priori, but I'm not sure of a better way at present. I can't say I much like how amqp/list or indeed
             * amqp/map are currently encoded. I'd *much* prefer to see them exposed as JMS ObjectMessage.
             */
            MapMessage msg = (MapMessage)message;
            List resultList = new ArrayList(50); // Initial capacity of 50, can we better estimate this?

            for (Enumeration e = msg.getMapNames(); e.hasMoreElements();)
            {
                String key = (String)e.nextElement();
                resultList.add(msg.getObject(key));
            }
            return resultList;
        }
        else
        {
View Full Code Here

Examples of javax.jms.BytesMessage

     * @param session used to create the JMS Message
     * @return an amqp/list encoded JMS Message
     */
    public static Message createListMessage(final Session session) throws JMSException
    {
        BytesMessage message = session.createBytesMessage();
        setContentType(message, "amqp/list");
        return message;
    }
View Full Code Here

Examples of javax.jms.BytesMessage

      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      javax.jms.Queue queue = (javax.jms.Queue)context.lookup("/queue/Q1");
     
      MessageProducer prod = sess.createProducer(queue);
      prod.setDeliveryMode(DeliveryMode.PERSISTENT);
      BytesMessage bmt = sess.createBytesMessage();
     
      bmt.writeBytes(new byte[1024]);
     
      for (int i = 0 ; i < 500; i++)
      {
         prod.send(bmt);
      }
View Full Code Here

Examples of javax.jms.BytesMessage

        if (message instanceof TextMessage) {
            final String text = ((TextMessage)message).getText();
            return NIOConverter.toByteBuffer(text);
        }
        if (message instanceof BytesMessage) {
            final BytesMessage bmsg = (BytesMessage)message;
            final int len = (int)bmsg.getBodyLength();
            final byte[] data = new byte[len];
            bmsg.readBytes(data, len);
            return NIOConverter.toByteBuffer(data);

        }
        if (message instanceof StreamMessage) {
            final StreamMessage msg = (StreamMessage)message;
View Full Code Here

Examples of javax.jms.BytesMessage

                } else {
                    bodyMessage = (DefaultMessage)exchange.getIn();
                }
                switch (JmsMessageHelper.discoverJmsMessageType(message)) {
                case Bytes:
                    BytesMessage bytesMessage = (BytesMessage)message;
                    if (bytesMessage.getBodyLength() > Integer.MAX_VALUE) {
                        LOGGER.warn("Length of BytesMessage is too long: {}", bytesMessage.getBodyLength());
                        return null;
                    }
                    byte[] result = new byte[(int)bytesMessage.getBodyLength()];
                    bytesMessage.readBytes(result);
                    bodyMessage.setHeader(JMS_MESSAGE_TYPE, JmsMessageType.Bytes);
                    bodyMessage.setBody(result);
                    break;
                case Map:
                    Map<String, Object> body = new HashMap<String, Object>();
View Full Code Here

Examples of javax.jms.BytesMessage

        JmsMessageType messageType = JmsMessageHelper.discoverMessgeTypeFromPayload(payload);
        try {

            switch (messageType) {
            case Bytes:
                BytesMessage bytesMessage = session.createBytesMessage();
                bytesMessage.writeBytes((byte[])payload);
                answer = bytesMessage;
                break;
            case Map:
                MapMessage mapMessage = session.createMapMessage();
                Map<String, Object> objMap = (Map<String, Object>)payload;
View Full Code Here

Examples of javax.jms.BytesMessage

        }
    }

    private Message nextMessage(int msg, Session producerSession) throws JMSException
    {
        BytesMessage send = producerSession.createBytesMessage();
        send.writeBytes(BYTE_32K);
        send.setIntProperty("msg", msg);
        return send;
    }
View Full Code Here

Examples of javax.jms.BytesMessage

    private static final byte[] BYTE_300 = new byte[300];

    private Message nextMessage(int msg, Session producerSession) throws JMSException
    {
        BytesMessage send = producerSession.createBytesMessage();
        send.writeBytes(BYTE_300);
        send.setIntProperty("msg", msg);

        return send;
    }
View Full Code Here

Examples of javax.jms.BytesMessage

                jmsException.setLinkedException(e);
                throw jmsException;
            }
        }
        if (body instanceof byte[]) {
            BytesMessage result = session.createBytesMessage();
            result.writeBytes((byte[])body);
            return result;
        }
        if (body instanceof Map) {
            MapMessage result = session.createMapMessage();
            Map<?, ?> map = (Map<?, ?>)body;
            try {
                populateMapMessage(result, map, context);
                return result;
            } catch (JMSException e) {
                // if MapMessage creation failed then fall back to Object Message
                LOG.warn("Can not populate MapMessage will fall back to ObjectMessage, cause by: " + e.getMessage());
            }
        }
        if (body instanceof String) {
            return session.createTextMessage((String)body);
        }
        if (body instanceof File || body instanceof Reader || body instanceof InputStream || body instanceof ByteBuffer) {
            BytesMessage result = session.createBytesMessage();
            byte[] bytes = context.getTypeConverter().convertTo(byte[].class, body);
            result.writeBytes(bytes);
            return result;
        }
        if (body instanceof Serializable) {
            return session.createObjectMessage((Serializable)body);
        }
View Full Code Here

Examples of javax.jms.BytesMessage

         throw new CacheException("Unable to process remote cache event", e);
      }
   }

   private Object getKey(Message message) throws Exception {
      BytesMessage msg = (BytesMessage) message;
      // Transform a Hot Rod binary key into the local Java equivalent
      byte[] keyBytes = new byte[(int) msg.getBodyLength()];
      msg.readBytes(keyBytes);
      // Since Hot Rod stores keys in byte[], it needs to be unmarshalled
      return marshaller.objectFromByteBuffer(keyBytes);
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.