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;
}
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);
}
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);
}
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");
}
}
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());
}
Aggregations