use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.
the class AbstractServlet method getConfiguredObjectFinder.
protected final ConfiguredObjectFinder getConfiguredObjectFinder(final ConfiguredObject<?> root) {
ConfiguredObjectFinder finder = _configuredObjectFinders.get(root);
if (finder == null) {
finder = new ConfiguredObjectFinder(root);
final ConfiguredObjectFinder existingValue = _configuredObjectFinders.putIfAbsent(root, finder);
if (existingValue != null) {
finder = existingValue;
} else {
final AbstractConfigurationChangeListener deletionListener = new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
if (newState == State.DELETED) {
_configuredObjectFinders.remove(root);
}
}
};
root.addChangeListener(deletionListener);
if (root.getState() == State.DELETED) {
_configuredObjectFinders.remove(root);
root.removeChangeListener(deletionListener);
}
}
}
return finder;
}
use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.
the class AbstractConfiguredObjectTest method testSuccessfulStateTransitionInvokesListener.
public void testSuccessfulStateTransitionInvokesListener() throws Exception {
TestConfiguredObject parent = new TestConfiguredObject("parent");
parent.create();
final AtomicReference<State> newState = new AtomicReference<>();
final AtomicInteger callCounter = new AtomicInteger();
parent.addChangeListener(new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(final ConfiguredObject<?> object, final State old, final State state) {
super.stateChanged(object, old, state);
callCounter.incrementAndGet();
newState.set(state);
}
});
parent.delete();
assertEquals(State.DELETED, newState.get());
assertEquals(1, callCounter.get());
}
use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.
the class AbstractConfiguredObjectTest method XtestUnsuccessfulStateTransitionDoesNotInvokesListener.
// TODO - not sure if I want to keep the state transition methods on delete
public void XtestUnsuccessfulStateTransitionDoesNotInvokesListener() throws Exception {
final IllegalStateTransitionException expectedException = new IllegalStateTransitionException("This test fails the state transition.");
TestConfiguredObject parent = new TestConfiguredObject("parent") {
@Override
protected ListenableFuture<Void> doDelete() {
throw expectedException;
}
};
parent.create();
final AtomicInteger callCounter = new AtomicInteger();
parent.addChangeListener(new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(final ConfiguredObject<?> object, final State old, final State state) {
super.stateChanged(object, old, state);
callCounter.incrementAndGet();
}
@Override
public void attributeSet(ConfiguredObject<?> object, String attributeName, Object oldAttributeValue, Object newAttributeValue) {
super.attributeSet(object, attributeName, oldAttributeValue, newAttributeValue);
callCounter.incrementAndGet();
}
});
try {
parent.delete();
fail("Exception not thrown.");
} catch (RuntimeException e) {
assertSame("State transition threw unexpected exception.", expectedException, e);
}
assertEquals(0, callCounter.get());
assertEquals(State.ACTIVE, parent.getDesiredState());
assertEquals(State.ACTIVE, parent.getState());
}
use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.
the class ManagementModeStoreHandlerTest method virtualHostEntryQuiescedStatusTestImpl.
private void virtualHostEntryQuiescedStatusTestImpl(boolean mmQuiesceVhosts) {
UUID virtualHostId = UUID.randomUUID();
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(VirtualHost.TYPE, "STANDARD");
final ConfiguredObjectRecord virtualHost = new ConfiguredObjectRecordImpl(virtualHostId, VirtualHost.class.getSimpleName(), attributes, Collections.singletonMap(Broker.class.getSimpleName(), _root.getId()));
final ArgumentCaptor<ConfiguredObjectRecordHandler> recovererArgumentCaptor = ArgumentCaptor.forClass(ConfiguredObjectRecordHandler.class);
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
ConfiguredObjectRecordHandler recoverer = recovererArgumentCaptor.getValue();
recoverer.handle(_root);
recoverer.handle(_portEntry);
recoverer.handle(virtualHost);
return false;
}
}).when(_store).openConfigurationStore(recovererArgumentCaptor.capture());
State expectedState = mmQuiesceVhosts ? State.QUIESCED : null;
if (mmQuiesceVhosts) {
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_QUIESCE_VIRTUAL_HOSTS, mmQuiesceVhosts);
}
_handler = createManagementModeStoreHandler();
_handler.init(_systemConfig);
Collection<ConfiguredObjectRecord> records = openAndGetRecords();
ConfiguredObjectRecord hostEntry = getEntry(records, virtualHostId);
Map<String, Object> hostAttributes = new HashMap<String, Object>(hostEntry.getAttributes());
assertEquals("Unexpected state", expectedState, hostAttributes.get(VirtualHost.STATE));
hostAttributes.remove(VirtualHost.STATE);
assertEquals("Unexpected attributes", attributes, hostAttributes);
}
use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.
the class AbstractKeyStore method initializeExpiryChecking.
protected void initializeExpiryChecking() {
int checkFrequency = getCertificateExpiryCheckFrequency();
if (getBroker().getState() == State.ACTIVE) {
_checkExpiryTaskFuture = getBroker().scheduleHouseKeepingTask(checkFrequency, TimeUnit.DAYS, new Runnable() {
@Override
public void run() {
checkCertificateExpiry();
}
});
} else {
final int frequency = checkFrequency;
getBroker().addChangeListener(new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
if (newState == State.ACTIVE) {
_checkExpiryTaskFuture = getBroker().scheduleHouseKeepingTask(frequency, TimeUnit.DAYS, () -> checkCertificateExpiry());
getBroker().removeChangeListener(this);
}
}
});
}
}
Aggregations