Search in sources :

Example 1 with UUID

use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.

the class DuplicateIDEncoding method toString.

@Override
public String toString() {
    // this would be useful when testing. Most tests on the testsuite will use a SimpleString on the duplicate ID
    // and this may be useful to validate the journal on those tests
    // You may uncomment these two lines on that case and replcate the toString for the PrintData
    // SimpleString simpleStr = new SimpleString(duplID);
    // return "DuplicateIDEncoding [address=" + address + ", duplID=" + simpleStr + "]";
    String bridgeRepresentation = null;
    // This will make them easier to read
    if (address.toString().startsWith("BRIDGE") && duplID.length == 24) {
        try {
            ByteBuffer buff = ByteBuffer.wrap(duplID);
            // 16 for UUID
            byte[] bytesUUID = new byte[16];
            buff.get(bytesUUID);
            UUID uuid = new UUID(UUID.TYPE_TIME_BASED, bytesUUID);
            long id = buff.getLong();
            bridgeRepresentation = "nodeUUID=" + uuid.toString() + " messageID=" + id;
        } catch (Throwable ignored) {
            bridgeRepresentation = null;
        }
    }
    if (bridgeRepresentation != null) {
        return "DuplicateIDEncoding [address=" + address + ", duplID=" + ByteUtil.bytesToHex(duplID, 2) + " / " + bridgeRepresentation + "]";
    } else {
        return "DuplicateIDEncoding [address=" + address + ", duplID=" + ByteUtil.bytesToHex(duplID, 2) + "]";
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) UUID(org.apache.activemq.artemis.utils.UUID) ByteBuffer(java.nio.ByteBuffer)

Example 2 with UUID

use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.

the class CoreMessage method decodeHeadersAndProperties.

private void decodeHeadersAndProperties(final ByteBuf buffer, boolean lazyProperties) {
    messageIDPosition = buffer.readerIndex();
    messageID = buffer.readLong();
    address = SimpleString.readNullableSimpleString(buffer, coreMessageObjectPools == null ? null : coreMessageObjectPools.getAddressDecoderPool());
    if (buffer.readByte() == DataConstants.NOT_NULL) {
        byte[] bytes = new byte[16];
        buffer.readBytes(bytes);
        userID = new UUID(UUID.TYPE_TIME_BASED, bytes);
    } else {
        userID = null;
    }
    type = buffer.readByte();
    durable = buffer.readBoolean();
    expiration = buffer.readLong();
    timestamp = buffer.readLong();
    priority = buffer.readByte();
    if (lazyProperties) {
        properties = null;
        propertiesLocation = buffer.readerIndex();
    } else {
        properties = new TypedProperties();
        properties.decode(buffer, coreMessageObjectPools == null ? null : coreMessageObjectPools.getPropertiesDecoderPools());
    }
}
Also used : UUID(org.apache.activemq.artemis.utils.UUID) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties)

Example 3 with UUID

use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.

the class PostMessage method createActiveMQMessage.

protected ClientMessage createActiveMQMessage(HttpHeaders headers, byte[] body, boolean durable, Long ttl, Long expiration, Integer priority, ClientSession session) throws Exception {
    ClientMessage message = session.createMessage(Message.BYTES_TYPE, durable);
    // HORNETQ-962
    UUID uid = UUIDGenerator.getInstance().generateUUID();
    message.setUserID(uid);
    if (expiration != null) {
        message.setExpiration(expiration.longValue());
    } else if (ttl != null) {
        message.setExpiration(System.currentTimeMillis() + ttl.longValue());
    } else if (producerTimeToLive > 0) {
        message.setExpiration(System.currentTimeMillis() + producerTimeToLive);
    }
    if (priority != null) {
        byte p = priority.byteValue();
        if (p >= 0 && p <= 9) {
            message.setPriority(p);
        }
    }
    HttpMessageHelper.writeHttpMessage(headers, body, message);
    return message;
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) UUID(org.apache.activemq.artemis.utils.UUID)

Example 4 with UUID

use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.

the class ActiveMQMessage method getJMSMessageID.

// javax.jmx.Message implementation ------------------------------
@Override
public String getJMSMessageID() {
    if (msgID == null) {
        UUID uid = (UUID) message.getUserID();
        msgID = uid == null ? null : "ID:" + uid.toString();
    }
    return msgID;
}
Also used : UUID(org.apache.activemq.artemis.utils.UUID)

Example 5 with UUID

use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.

the class ActiveMQMessageProducer method doSendx.

private void doSendx(ActiveMQDestination destination, final Message jmsMessage, final int deliveryMode, final int priority, final long timeToLive, CompletionListener completionListener) throws JMSException {
    jmsMessage.setJMSDeliveryMode(deliveryMode);
    jmsMessage.setJMSPriority(priority);
    if (timeToLive == 0) {
        jmsMessage.setJMSExpiration(0);
    } else {
        jmsMessage.setJMSExpiration(System.currentTimeMillis() + timeToLive);
    }
    if (!disableMessageTimestamp) {
        jmsMessage.setJMSTimestamp(System.currentTimeMillis());
    } else {
        jmsMessage.setJMSTimestamp(0);
    }
    SimpleString address = null;
    if (destination == null) {
        if (defaultDestination == null) {
            throw new UnsupportedOperationException("Destination must be specified on send with an anonymous producer");
        }
        destination = defaultDestination;
    } else {
        if (defaultDestination != null) {
            if (!destination.equals(defaultDestination)) {
                throw new UnsupportedOperationException("Where a default destination is specified " + "for the sender and a destination is " + "specified in the arguments to the send, " + "these destinations must be equal");
            }
        }
        address = destination.getSimpleAddress();
        if (!connection.containsKnownDestination(address)) {
            try {
                ClientSession.AddressQuery query = clientSession.addressQuery(address);
                if (!query.isExists()) {
                    if (destination.isQueue() && query.isAutoCreateQueues()) {
                        clientSession.createAddress(address, RoutingType.ANYCAST, true);
                        if (destination.isTemporary()) {
                            // TODO is it right to use the address for the queue name here?
                            clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
                        } else {
                            createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
                        }
                    } else if (!destination.isQueue() && query.isAutoCreateAddresses()) {
                        clientSession.createAddress(address, RoutingType.MULTICAST, true);
                    } else if ((destination.isQueue() && !query.isAutoCreateQueues()) || (!destination.isQueue() && !query.isAutoCreateAddresses())) {
                        throw new InvalidDestinationException("Destination " + address + " does not exist");
                    }
                } else {
                    ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
                    if (queueQuery.isExists()) {
                        connection.addKnownDestination(address);
                    } else if (destination.isQueue() && query.isAutoCreateQueues()) {
                        if (destination.isTemporary()) {
                            clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
                        } else {
                            createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
                        }
                    }
                }
            } catch (ActiveMQQueueExistsException e) {
            // The queue was created by another client/admin between the query check and send create queue packet
            } catch (ActiveMQException e) {
                throw JMSExceptionHelper.convertFromActiveMQException(e);
            }
        }
    }
    ActiveMQMessage activeMQJmsMessage;
    boolean foreign = false;
    // First convert from foreign message if appropriate
    if (!(jmsMessage instanceof ActiveMQMessage)) {
        if (jmsMessage instanceof BytesMessage) {
            activeMQJmsMessage = new ActiveMQBytesMessage((BytesMessage) jmsMessage, clientSession);
        } else if (jmsMessage instanceof MapMessage) {
            activeMQJmsMessage = new ActiveMQMapMessage((MapMessage) jmsMessage, clientSession);
        } else if (jmsMessage instanceof ObjectMessage) {
            activeMQJmsMessage = new ActiveMQObjectMessage((ObjectMessage) jmsMessage, clientSession, options);
        } else if (jmsMessage instanceof StreamMessage) {
            activeMQJmsMessage = new ActiveMQStreamMessage((StreamMessage) jmsMessage, clientSession);
        } else if (jmsMessage instanceof TextMessage) {
            activeMQJmsMessage = new ActiveMQTextMessage((TextMessage) jmsMessage, clientSession);
        } else {
            activeMQJmsMessage = new ActiveMQMessage(jmsMessage, clientSession);
        }
        // Set the destination on the original message
        jmsMessage.setJMSDestination(destination);
        foreign = true;
    } else {
        activeMQJmsMessage = (ActiveMQMessage) jmsMessage;
    }
    if (!disableMessageID) {
        // Generate a JMS id
        UUID uid = UUIDGenerator.getInstance().generateUUID();
        activeMQJmsMessage.getCoreMessage().setUserID(uid);
        activeMQJmsMessage.resetMessageID(null);
    }
    if (foreign) {
        jmsMessage.setJMSMessageID(activeMQJmsMessage.getJMSMessageID());
    }
    activeMQJmsMessage.setJMSDestination(destination);
    try {
        activeMQJmsMessage.doBeforeSend();
    } catch (Exception e) {
        JMSException je = new JMSException(e.getMessage());
        je.initCause(e);
        throw je;
    }
    if (defaultDeliveryDelay > 0) {
        activeMQJmsMessage.setJMSDeliveryTime(System.currentTimeMillis() + defaultDeliveryDelay);
    }
    ClientMessage coreMessage = activeMQJmsMessage.getCoreMessage();
    coreMessage.putStringProperty(ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME, connID);
    coreMessage.setRoutingType(destination.isQueue() ? RoutingType.ANYCAST : RoutingType.MULTICAST);
    try {
        /**
         * Using a completionListener requires wrapping using a {@link CompletionListenerWrapper},
         * so we avoid it if we can.
         */
        if (completionListener != null) {
            clientProducer.send(address, coreMessage, new CompletionListenerWrapper(completionListener, jmsMessage, this));
        } else {
            clientProducer.send(address, coreMessage);
        }
    } catch (ActiveMQInterruptedException e) {
        JMSException jmsException = new JMSException(e.getMessage());
        jmsException.initCause(e);
        throw jmsException;
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    } catch (java.lang.IllegalStateException e) {
        JMSException je = new IllegalStateException(e.getMessage());
        je.setStackTrace(e.getStackTrace());
        je.initCause(e);
        throw je;
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) MapMessage(javax.jms.MapMessage) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) BytesMessage(javax.jms.BytesMessage) JMSException(javax.jms.JMSException) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ObjectMessage(javax.jms.ObjectMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) UUID(org.apache.activemq.artemis.utils.UUID) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) StreamMessage(javax.jms.StreamMessage) TextMessage(javax.jms.TextMessage)

Aggregations

UUID (org.apache.activemq.artemis.utils.UUID)16 ByteBuffer (java.nio.ByteBuffer)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 File (java.io.File)2 SQLException (java.sql.SQLException)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 Test (org.junit.Test)2 RandomAccessFile (java.io.RandomAccessFile)1 FileChannel (java.nio.channels.FileChannel)1 BytesMessage (javax.jms.BytesMessage)1 IllegalStateException (javax.jms.IllegalStateException)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 ObjectMessage (javax.jms.ObjectMessage)1 StreamMessage (javax.jms.StreamMessage)1 TextMessage (javax.jms.TextMessage)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1