use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method upgradeMetaData.
private void upgradeMetaData(final Environment environment, final UpgradeInteractionHandler handler, final Set<Long> messagesToDiscard, Transaction transaction) {
LOGGER.info("Message MetaData");
if (environment.getDatabaseNames().contains(OLD_METADATA_DB_NAME)) {
final MessageMetaDataBinding binding = new MessageMetaDataBinding();
CursorOperation databaseOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
StorableMessageMetaData metaData = binding.entryToObject(value);
// get message id
Long messageId = LongBinding.entryToLong(key);
// ONLY copy data if message is delivered to existing queue
if (messagesToDiscard.contains(messageId)) {
return;
}
DatabaseEntry newValue = new DatabaseEntry();
binding.objectToEntry(metaData, newValue);
targetDatabase.put(transaction, key, newValue);
targetDatabase.put(transaction, key, newValue);
deleteCurrent();
}
};
new DatabaseTemplate(environment, OLD_METADATA_DB_NAME, NEW_METADATA_DB_NAME, transaction).run(databaseOperation);
environment.removeDatabase(transaction, OLD_METADATA_DB_NAME);
LOGGER.info(databaseOperation.getRowCount() + " Message MetaData entries");
}
}
use of com.sleepycat.je.Transaction 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 com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom5To6 method upgradeExchanges.
private List<String> upgradeExchanges(Environment environment, Transaction transaction, final String virtualHostName) {
final List<String> exchangeNames = new ArrayList<String>();
LOGGER.info("Exchanges");
if (environment.getDatabaseNames().contains(OLD_EXCHANGE_DB_NAME)) {
final ExchangeBinding exchangeBinding = new ExchangeBinding();
CursorOperation exchangeCursor = new CursorOperation() {
@Override
public void processEntry(Database exchangeDatabase, Database configuredObjectsDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
ExchangeRecord exchangeRecord = exchangeBinding.entryToObject(value);
String exchangeName = exchangeRecord.getNameShortString().toString();
if (!DEFAULT_EXCHANGES_SET.contains(exchangeName) && !"<<default>>".equals(exchangeName)) {
String exchangeType = exchangeRecord.getType().toString();
boolean autoDelete = exchangeRecord.isAutoDelete();
UUID exchangeId = UUIDGenerator.generateExchangeUUID(exchangeName, virtualHostName);
UpgradeConfiguredObjectRecord configuredObject = createExchangeConfiguredObjectRecord(exchangeName, exchangeType, autoDelete);
storeConfiguredObjectEntry(configuredObjectsDatabase, exchangeId, configuredObject, transaction);
exchangeNames.add(exchangeName);
}
}
};
new DatabaseTemplate(environment, OLD_EXCHANGE_DB_NAME, CONFIGURED_OBJECTS_DB_NAME, transaction).run(exchangeCursor);
environment.removeDatabase(transaction, OLD_EXCHANGE_DB_NAME);
LOGGER.info(exchangeCursor.getRowCount() + " Exchange Entries");
}
return exchangeNames;
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacadeTest method testBeginTransaction.
public void testBeginTransaction() throws Exception {
ReplicatedEnvironmentFacade facade = createMaster();
Transaction txn = null;
try {
TransactionConfig transactionConfig = new TransactionConfig();
transactionConfig.setDurability(facade.getRealMessageStoreDurability());
txn = facade.beginTransaction(transactionConfig);
assertNotNull("Transaction is not created", txn);
txn.commit();
txn = null;
} finally {
if (txn != null) {
txn.abort();
}
}
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacadeTest method testReplicaTransactionBeginsImmediately.
public void testReplicaTransactionBeginsImmediately() throws Exception {
ReplicatedEnvironmentFacade master = createMaster();
String nodeName2 = TEST_NODE_NAME + "_2";
String host = "localhost";
int port = _portHelper.getNextAvailable();
String node2NodeHostPort = host + ":" + port;
final ReplicatedEnvironmentFacade replica = createReplica(nodeName2, node2NodeHostPort, new NoopReplicationGroupListener());
// close the master
master.close();
// try to create a transaction in a separate thread
// and make sure that transaction is created immediately.
ExecutorService service = Executors.newSingleThreadExecutor();
try {
Future<Transaction> future = service.submit(new Callable<Transaction>() {
@Override
public Transaction call() throws Exception {
return replica.beginTransaction(null);
}
});
Transaction transaction = future.get(_timeout, TimeUnit.SECONDS);
assertNotNull("Transaction was not created during expected time", transaction);
transaction.abort();
} finally {
service.shutdown();
}
}
Aggregations