Search in sources :

Example 1 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class UpgradeFrom4To5 method upgradeQueues.

private Set<String> upgradeQueues(final Environment environment, final UpgradeInteractionHandler handler, List<AMQShortString> potentialDurableSubs, Transaction transaction) {
    LOGGER.info("Queues");
    final Set<String> existingQueues = new HashSet<String>();
    if (environment.getDatabaseNames().contains(OLD_QUEUE_DB_NAME)) {
        final QueueRecordBinding binding = new QueueRecordBinding(potentialDurableSubs);
        CursorOperation databaseOperation = new CursorOperation() {

            @Override
            public void processEntry(final Database sourceDatabase, final Database targetDatabase, final Transaction transaction, final DatabaseEntry key, final DatabaseEntry value) {
                QueueRecord record = binding.entryToObject(value);
                DatabaseEntry newValue = new DatabaseEntry();
                binding.objectToEntry(record, newValue);
                targetDatabase.put(transaction, key, newValue);
                existingQueues.add(record.getNameShortString().toString());
                sourceDatabase.delete(transaction, key);
            }
        };
        new DatabaseTemplate(environment, OLD_QUEUE_DB_NAME, NEW_QUEUE_DB_NAME, transaction).run(databaseOperation);
        environment.removeDatabase(transaction, OLD_QUEUE_DB_NAME);
        LOGGER.info(databaseOperation.getRowCount() + " Queue entries");
    }
    return existingQueues;
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) HashSet(java.util.HashSet)

Example 2 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class UpgradeFrom4To5 method createQueue.

protected void createQueue(final Environment environment, Transaction transaction, final String queueName) {
    final QueueRecordBinding binding = new QueueRecordBinding(null);
    final BindingTuple bindingTuple = new BindingTuple();
    DatabaseRunnable queueCreateOperation = new DatabaseRunnable() {

        @Override
        public void run(Database newQueueDatabase, Database newBindingsDatabase, Transaction transaction) {
            AMQShortString queueNameAMQ = AMQShortString.createAMQShortString(queueName);
            QueueRecord record = new QueueRecord(queueNameAMQ, null, false, null);
            DatabaseEntry key = new DatabaseEntry();
            TupleOutput output = new TupleOutput();
            AMQShortStringEncoding.writeShortString(record.getNameShortString(), output);
            TupleBase.outputToEntry(output, key);
            DatabaseEntry newValue = new DatabaseEntry();
            binding.objectToEntry(record, newValue);
            newQueueDatabase.put(transaction, key, newValue);
            FieldTable emptyArguments = FieldTableFactory.createFieldTable(Collections.emptyMap());
            addBindingToDatabase(bindingTuple, newBindingsDatabase, transaction, queueNameAMQ, AMQShortString.valueOf(ExchangeDefaults.DIRECT_EXCHANGE_NAME), queueNameAMQ, emptyArguments);
            // TODO QPID-3490 we should not persist a default exchange binding
            addBindingToDatabase(bindingTuple, newBindingsDatabase, transaction, queueNameAMQ, AMQShortString.valueOf(ExchangeDefaults.DEFAULT_EXCHANGE_NAME), queueNameAMQ, emptyArguments);
        }
    };
    new DatabaseTemplate(environment, NEW_QUEUE_DB_NAME, NEW_BINDINGS_DB_NAME, transaction).run(queueCreateOperation);
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Transaction(com.sleepycat.je.Transaction) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) TupleOutput(com.sleepycat.bind.tuple.TupleOutput)

Example 3 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class UpgradeFrom4To5 method performUpgrade.

@Override
public void performUpgrade(final Environment environment, final UpgradeInteractionHandler handler, ConfiguredObject<?> parent) {
    Transaction transaction = null;
    reportStarting(environment, 4);
    transaction = environment.beginTransaction(null, null);
    // find all queues which are bound to a topic exchange and which have a colon in their name
    final List<AMQShortString> potentialDurableSubs = findPotentialDurableSubscriptions(environment, transaction);
    Set<String> existingQueues = upgradeQueues(environment, handler, potentialDurableSubs, transaction);
    upgradeQueueBindings(environment, handler, potentialDurableSubs, transaction);
    Set<Long> messagesToDiscard = upgradeDelivery(environment, existingQueues, handler, transaction);
    upgradeContent(environment, handler, messagesToDiscard, transaction);
    upgradeMetaData(environment, handler, messagesToDiscard, transaction);
    renameRemainingDatabases(environment, handler, transaction);
    transaction.commit();
    reportFinished(environment, 5);
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Transaction(com.sleepycat.je.Transaction) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString)

Example 4 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class UpgradeFrom4To5 method upgradeQueueBindings.

private void upgradeQueueBindings(Environment environment, UpgradeInteractionHandler handler, final List<AMQShortString> potentialDurableSubs, Transaction transaction) {
    if (environment.getDatabaseNames().contains(OLD_BINDINGS_DB_NAME)) {
        LOGGER.info("Queue Bindings");
        final BindingTuple bindingTuple = new BindingTuple();
        CursorOperation databaseOperation = new CursorOperation() {

            @Override
            public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                // All the information required in binding entries is actually in the *key* not value.
                BindingRecord oldBindingRecord = bindingTuple.entryToObject(key);
                AMQShortString queueName = oldBindingRecord.getQueueName();
                AMQShortString exchangeName = oldBindingRecord.getExchangeName();
                AMQShortString routingKey = oldBindingRecord.getRoutingKey();
                FieldTable arguments = oldBindingRecord.getArguments();
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(String.format("Processing binding for queue %s, exchange %s, routingKey %s arguments %s", queueName, exchangeName, routingKey, arguments));
                }
                // only topic exchange should have a JMS selector key in binding
                if (potentialDurableSubs.contains(queueName) && exchangeName.equals(AMQShortString.valueOf(ExchangeDefaults.TOPIC_EXCHANGE_NAME))) {
                    Map<String, Object> argumentsMap = new HashMap<>();
                    if (arguments != null) {
                        argumentsMap.putAll(FieldTable.convertToMap(arguments));
                    }
                    String selectorFilterKey = AMQPFilterTypes.JMS_SELECTOR.getValue();
                    if (!argumentsMap.containsKey(selectorFilterKey)) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.info("adding the empty string (i.e. 'no selector') value for " + queueName + " and exchange " + exchangeName);
                        }
                        argumentsMap.put(selectorFilterKey, "");
                    }
                    arguments = FieldTable.convertToFieldTable(argumentsMap);
                }
                addBindingToDatabase(bindingTuple, targetDatabase, transaction, queueName, exchangeName, routingKey, arguments);
            }
        };
        new DatabaseTemplate(environment, OLD_BINDINGS_DB_NAME, NEW_BINDINGS_DB_NAME, transaction).run(databaseOperation);
        environment.removeDatabase(transaction, OLD_BINDINGS_DB_NAME);
        LOGGER.info(databaseOperation.getRowCount() + " Queue Binding entries");
    }
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) HashMap(java.util.HashMap) DatabaseEntry(com.sleepycat.je.DatabaseEntry) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 5 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class MessageConverter_0_8_to_0_10 method convertMetaData.

private MessageMetaData_0_10 convertMetaData(AMQMessage message_0_8) {
    DeliveryProperties deliveryProps = new DeliveryProperties();
    MessageProperties messageProps = new MessageProperties();
    int size = (int) message_0_8.getSize();
    BasicContentHeaderProperties properties = message_0_8.getContentHeaderBody().getProperties();
    final AMQShortString exchange = message_0_8.getMessagePublishInfo().getExchange();
    if (exchange != null) {
        deliveryProps.setExchange(exchange.toString());
    }
    deliveryProps.setExpiration(message_0_8.getExpiration());
    if (message_0_8.getExpiration() != 0) {
        deliveryProps.setTtl(message_0_8.getExpiration() - message_0_8.getArrivalTime());
    }
    deliveryProps.setImmediate(message_0_8.isImmediate());
    deliveryProps.setDiscardUnroutable(!message_0_8.isMandatory());
    deliveryProps.setPriority(MessageDeliveryPriority.get(properties.getPriority()));
    deliveryProps.setRoutingKey(message_0_8.getInitialRoutingAddress());
    deliveryProps.setTimestamp(properties.getTimestamp());
    if (properties.getDeliveryMode() == BasicContentHeaderProperties.PERSISTENT) {
        deliveryProps.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
    } else {
        deliveryProps.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
    }
    messageProps.setContentEncoding(properties.getEncodingAsString());
    messageProps.setContentLength(size);
    if (properties.getAppId() != null) {
        messageProps.setAppId(properties.getAppId().getBytes());
    }
    messageProps.setContentType(properties.getContentTypeAsString());
    if (properties.getCorrelationId() != null) {
        messageProps.setCorrelationId(properties.getCorrelationId().getBytes());
    }
    if (properties.getReplyTo() != null && properties.getReplyTo().length() != 0) {
        String origReplyToString = properties.getReplyTo().toString();
        ReplyTo replyTo = new ReplyTo();
        // if the string looks like a binding URL, then attempt to parse it...
        try {
            AMQBindingURL burl = new AMQBindingURL(origReplyToString);
            String routingKey = burl.getRoutingKey();
            if (routingKey != null) {
                replyTo.setRoutingKey(routingKey);
            }
            String exchangeName = burl.getExchangeName();
            if (exchangeName != null && !"".equals(exchangeName)) {
                replyTo.setExchange(exchangeName);
            }
        } catch (URISyntaxException e) {
            replyTo.setRoutingKey(origReplyToString);
        }
        messageProps.setReplyTo(replyTo);
    }
    if (properties.getMessageId() != null) {
        UUID uuid;
        String messageIdAsString = properties.getMessageIdAsString();
        if (messageIdAsString.startsWith("ID:")) {
            messageIdAsString = messageIdAsString.substring(3);
        }
        try {
            uuid = UUID.fromString(messageIdAsString);
        } catch (IllegalArgumentException e) {
            uuid = UUID.nameUUIDFromBytes(messageIdAsString.getBytes(UTF_8));
        }
        messageProps.setMessageId(uuid);
    }
    if (properties.getUserId() != null) {
        messageProps.setUserId(properties.getUserId().getBytes());
    }
    final Map<String, Object> appHeaders = new LinkedHashMap<>(properties.getHeadersAsMap());
    if (properties.getType() != null) {
        appHeaders.put("x-jms-type", properties.getTypeAsString());
    }
    messageProps.setApplicationHeaders(appHeaders);
    Header header = new Header(deliveryProps, messageProps, null);
    return new MessageMetaData_0_10(header, size, message_0_8.getArrivalTime());
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQBindingURL(org.apache.qpid.server.url.AMQBindingURL) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) URISyntaxException(java.net.URISyntaxException) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) LinkedHashMap(java.util.LinkedHashMap) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) UUID(java.util.UUID) MessageMetaData_0_10(org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)

Aggregations

AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)44 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)11 Transaction (com.sleepycat.je.Transaction)7 Database (com.sleepycat.je.Database)6 DatabaseEntry (com.sleepycat.je.DatabaseEntry)6 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)6 Test (org.junit.Test)6 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)4 TupleInput (com.sleepycat.bind.tuple.TupleInput)3 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)3 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)2 AMQBody (org.apache.qpid.server.protocol.v0_8.transport.AMQBody)2 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)2 QueueRecord (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.QueueRecord)2 AMQBindingURL (org.apache.qpid.server.url.AMQBindingURL)2