use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractSystemConfig method initiateStoreAndRecovery.
private Container<?> initiateStoreAndRecovery() throws IOException {
ConfiguredObjectRecord[] initialRecords = convertToConfigurationRecords(getInitialConfigurationLocation());
final DurableConfigurationStore store = getConfigurationStore();
store.init(AbstractSystemConfig.this);
store.upgradeStoreStructure();
final List<ConfiguredObjectRecord> records = new ArrayList<>();
boolean isNew = store.openConfigurationStore(new ConfiguredObjectRecordHandler() {
@Override
public void handle(final ConfiguredObjectRecord record) {
records.add(record);
}
}, initialRecords);
String containerTypeName = getDefaultContainerType();
for (ConfiguredObjectRecord record : records) {
if (record.getParents() != null && record.getParents().size() == 1 && getId().equals(record.getParents().get(SystemConfig.class.getSimpleName()))) {
containerTypeName = record.getType();
break;
}
}
QpidServiceLoader loader = new QpidServiceLoader();
final ContainerType<?> containerType = loader.getInstancesByType(ContainerType.class).get(containerTypeName);
if (containerType != null) {
if (containerType.getModel() != getModel()) {
updateModel(containerType.getModel());
}
containerType.getRecoverer(this).upgradeAndRecover(records);
} else {
throw new IllegalConfigurationException("Unknown container type '" + containerTypeName + "'");
}
final Class categoryClass = containerType.getCategoryClass();
return (Container<?>) getContainer(categoryClass);
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractSystemConfig method convertToConfigurationRecords.
private ConfiguredObjectRecord[] convertToConfigurationRecords(final String initialConfigurationLocation) throws IOException {
ConfiguredObjectRecordConverter converter = new ConfiguredObjectRecordConverter(getModel());
Reader reader;
try {
URL url = new URL(initialConfigurationLocation);
reader = new InputStreamReader(url.openStream());
} catch (MalformedURLException e) {
reader = new FileReader(initialConfigurationLocation);
}
try {
Collection<ConfiguredObjectRecord> records = converter.readFromJson(null, this, reader);
return records.toArray(new ConfiguredObjectRecord[records.size()]);
} finally {
reader.close();
}
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class BDBConfigurationStore method remove.
@Override
public UUID[] remove(final ConfiguredObjectRecord... objects) throws StoreException {
assertState(OPEN);
com.sleepycat.je.Transaction txn = null;
try {
txn = _environmentFacade.beginTransaction(null);
Collection<UUID> removed = new ArrayList<>(objects.length);
for (ConfiguredObjectRecord record : objects) {
if (removeConfiguredObject(txn, record) == OperationStatus.SUCCESS) {
removed.add(record.getId());
}
}
txn.commit();
txn = null;
return removed.toArray(new UUID[removed.size()]);
} catch (RuntimeException e) {
throw _environmentFacade.handleDatabaseException("Error deleting configured objects from database", e);
} finally {
if (txn != null) {
abortTransactionSafely(txn, _environmentFacade);
}
}
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class BDBConfigurationStore method update.
@Override
public void update(boolean createIfNecessary, ConfiguredObjectRecord... records) throws StoreException {
assertState(OPEN);
com.sleepycat.je.Transaction txn = null;
try {
txn = _environmentFacade.beginTransaction(null);
for (ConfiguredObjectRecord record : records) {
update(createIfNecessary, record, txn);
}
txn.commit();
txn = null;
} catch (RuntimeException e) {
throw _environmentFacade.handleDatabaseException("Error updating configuration details within the store: " + e, e);
} finally {
if (txn != null) {
abortTransactionSafely(txn, _environmentFacade);
}
}
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class ConfiguredObjectBindingTest method testObjectToEntryAndEntryToObject.
public void testObjectToEntryAndEntryToObject() {
TupleOutput tupleOutput = new TupleOutput();
_configuredObjectBinding.objectToEntry(_object, tupleOutput);
byte[] entryAsBytes = tupleOutput.getBufferBytes();
TupleInput tupleInput = new TupleInput(entryAsBytes);
ConfiguredObjectRecord storedObject = _configuredObjectBinding.entryToObject(tupleInput);
assertEquals("Unexpected attributes", DUMMY_ATTRIBUTES_MAP, storedObject.getAttributes());
assertEquals("Unexpected type", DUMMY_TYPE_STRING, storedObject.getType());
}
Aggregations