use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractJDBCConfigurationStore method remove.
@Override
public UUID[] remove(ConfiguredObjectRecord... objects) throws StoreException {
assertState(OPEN);
Collection<UUID> removed = new ArrayList<UUID>(objects.length);
try {
try (Connection conn = newAutoCommitConnection()) {
for (ConfiguredObjectRecord record : objects) {
if (removeConfiguredObject(record.getId(), conn) != 0) {
removed.add(record.getId());
}
}
}
} catch (SQLException e) {
throw new StoreException("Error deleting of configured objects " + Arrays.asList(objects) + " from database: " + e.getMessage(), e);
}
return removed.toArray(new UUID[removed.size()]);
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractJDBCConfigurationStore method openConfigurationStore.
@Override
public boolean openConfigurationStore(ConfiguredObjectRecordHandler handler, final ConfiguredObjectRecord... initialRecords) {
changeState(CONFIGURED, OPEN);
_deleteActions.clear();
try {
Collection<? extends ConfiguredObjectRecord> records = doVisitAllConfiguredObjectRecords(handler);
boolean isNew = records.isEmpty();
if (isNew) {
records = Arrays.asList(initialRecords);
try {
try (Connection conn = newConnection()) {
for (ConfiguredObjectRecord record : records) {
updateConfiguredObject(record, true, conn);
}
conn.commit();
}
} catch (SQLException e) {
throw new StoreException("Error updating configured objects in database: " + e.getMessage(), e);
}
}
for (ConfiguredObjectRecord record : records) {
handler.handle(record);
}
return isNew;
} catch (SQLException e) {
throw new StoreException("Cannot visit configured object records", e);
}
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class VirtualHostTest method testRestartingVirtualHostRecoversChildren.
public void testRestartingVirtualHostRecoversChildren() {
String virtualHostName = getName();
VirtualHost<?> virtualHost = createVirtualHost(virtualHostName);
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
final ConfiguredObjectRecord virtualHostCor = virtualHost.asObjectRecord();
// Give virtualhost a queue and an exchange
Queue queue = virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, "myQueue"));
final ConfiguredObjectRecord queueCor = queue.asObjectRecord();
Map<String, Object> exchangeArgs = new HashMap<>();
exchangeArgs.put(Exchange.NAME, "myExchange");
exchangeArgs.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
Exchange exchange = virtualHost.createChild(Exchange.class, exchangeArgs);
final ConfiguredObjectRecord exchangeCor = exchange.asObjectRecord();
assertEquals("Unexpected number of queues before stop", 1, virtualHost.getChildren(Queue.class).size());
assertEquals("Unexpected number of exchanges before stop", 5, virtualHost.getChildren(Exchange.class).size());
final List<ConfiguredObjectRecord> allObjects = new ArrayList<>();
allObjects.add(virtualHostCor);
allObjects.add(queueCor);
for (Exchange e : virtualHost.getChildren(Exchange.class)) {
allObjects.add(e.asObjectRecord());
}
((AbstractConfiguredObject<?>) virtualHost).stop();
assertEquals("Unexpected state", State.STOPPED, virtualHost.getState());
assertEquals("Unexpected number of queues after stop", 0, virtualHost.getChildren(Queue.class).size());
assertEquals("Unexpected number of exchanges after stop", 0, virtualHost.getChildren(Exchange.class).size());
// Setup an answer that will return the configured object records
doAnswer(new Answer() {
final Iterator<ConfiguredObjectRecord> corIterator = allObjects.iterator();
@Override
public Object answer(final InvocationOnMock invocation) {
ConfiguredObjectRecordHandler handler = (ConfiguredObjectRecordHandler) invocation.getArguments()[0];
boolean handlerContinue = true;
while (corIterator.hasNext()) {
handler.handle(corIterator.next());
}
return null;
}
}).when(_configStore).reload(any(ConfiguredObjectRecordHandler.class));
((AbstractConfiguredObject<?>) virtualHost).start();
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
assertEquals("Unexpected number of queues after restart", 1, virtualHost.getChildren(Queue.class).size());
assertEquals("Unexpected number of exchanges after restart", 5, virtualHost.getChildren(Exchange.class).size());
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractConfiguredObjectTest method recoverParentAndChild.
/**
* Simulates recovery of a parent/child from a store. Neither will be open yet.
*/
private TestCar recoverParentAndChild() {
final SystemConfig mockSystemConfig = mock(SystemConfig.class);
when(mockSystemConfig.getId()).thenReturn(UUID.randomUUID());
when(mockSystemConfig.getModel()).thenReturn(TestModel.getInstance());
final String carName = "myCar";
final Map<String, Object> carAttributes = new HashMap<>();
carAttributes.put(ConfiguredObject.NAME, carName);
carAttributes.put(ConfiguredObject.TYPE, TestKitCarImpl.TEST_KITCAR_TYPE);
ConfiguredObjectRecord carCor = new ConfiguredObjectRecord() {
@Override
public UUID getId() {
return UUID.randomUUID();
}
@Override
public String getType() {
return TestCar.class.getSimpleName();
}
@Override
public Map<String, Object> getAttributes() {
return carAttributes;
}
@Override
public Map<String, UUID> getParents() {
return Collections.singletonMap(SystemConfig.class.getSimpleName(), mockSystemConfig.getId());
}
};
final TestCar car = (TestCar) _model.getObjectFactory().recover(carCor, mockSystemConfig).resolve();
String engineName = "myEngine";
final Map<String, Object> engineAttributes = new HashMap<>();
engineAttributes.put(ConfiguredObject.NAME, engineName);
engineAttributes.put(ConfiguredObject.TYPE, TestElecEngineImpl.TEST_ELEC_ENGINE_TYPE);
ConfiguredObjectRecord engineCor = new ConfiguredObjectRecord() {
@Override
public UUID getId() {
return UUID.randomUUID();
}
@Override
public String getType() {
return TestEngine.class.getSimpleName();
}
@Override
public Map<String, Object> getAttributes() {
return engineAttributes;
}
@Override
public Map<String, UUID> getParents() {
return Collections.singletonMap(TestCar.class.getSimpleName(), car.getId());
}
};
_model.getObjectFactory().recover(engineCor, car).resolve();
return car;
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractConfiguredObjectTest method testAttributePersistence.
public void testAttributePersistence() {
final String objectName = "testNonPersistAttributes";
TestSingleton object = _model.getObjectFactory().create(TestSingleton.class, Collections.<String, Object>singletonMap(ConfiguredObject.NAME, objectName), null);
assertEquals(objectName, object.getName());
assertNull(object.getAutomatedNonPersistedValue());
assertNull(object.getAutomatedPersistedValue());
assertEquals(TestSingletonImpl.DERIVED_VALUE, object.getDerivedValue());
ConfiguredObjectRecord record = object.asObjectRecord();
assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME));
assertFalse(record.getAttributes().containsKey(TestSingleton.AUTOMATED_PERSISTED_VALUE));
assertFalse(record.getAttributes().containsKey(TestSingleton.AUTOMATED_NONPERSISTED_VALUE));
assertFalse(record.getAttributes().containsKey(TestSingleton.DERIVED_VALUE));
Map<String, Object> updatedAttributes = new HashMap<>();
final String newValue = "newValue";
updatedAttributes.put(TestSingleton.AUTOMATED_PERSISTED_VALUE, newValue);
updatedAttributes.put(TestSingleton.AUTOMATED_NONPERSISTED_VALUE, newValue);
// Will be ignored
updatedAttributes.put(TestSingleton.DERIVED_VALUE, System.currentTimeMillis());
object.setAttributes(updatedAttributes);
assertEquals(newValue, object.getAutomatedPersistedValue());
assertEquals(newValue, object.getAutomatedNonPersistedValue());
record = object.asObjectRecord();
assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME));
assertEquals(newValue, record.getAttributes().get(TestSingleton.AUTOMATED_PERSISTED_VALUE));
assertFalse(record.getAttributes().containsKey(TestSingleton.AUTOMATED_NONPERSISTED_VALUE));
assertFalse(record.getAttributes().containsKey(TestSingleton.DERIVED_VALUE));
}
Aggregations