use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.
the class TrustStoreMessageSourceCreator method register.
@Override
public void register(final SystemNodeRegistry registry) {
final VirtualHost<?> vhost = registry.getVirtualHost();
VirtualHostNode<?> virtualHostNode = (VirtualHostNode<?>) vhost.getParent();
final Broker<?> broker = (Broker<?>) virtualHostNode.getParent();
final Collection<TrustStore> trustStores = broker.getChildren(TrustStore.class);
final TrustStoreChangeListener trustStoreChangeListener = new TrustStoreChangeListener(registry);
for (final TrustStore trustStore : trustStores) {
updateTrustStoreSourceRegistration(registry, trustStore);
trustStore.addChangeListener(trustStoreChangeListener);
}
AbstractConfigurationChangeListener brokerListener = new AbstractConfigurationChangeListener() {
@Override
public void childAdded(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
if (child instanceof TrustStore) {
TrustStore<?> trustStore = (TrustStore<?>) child;
updateTrustStoreSourceRegistration(registry, trustStore);
trustStore.addChangeListener(trustStoreChangeListener);
}
}
@Override
public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
if (child instanceof TrustStore) {
TrustStore<?> trustStore = (TrustStore<?>) child;
trustStore.removeChangeListener(trustStoreChangeListener);
registry.removeSystemNode(TrustStoreMessageSource.getSourceNameFromTrustStore(trustStore));
} else if (child == virtualHostNode) {
object.removeChangeListener(this);
broker.getChildren(TrustStore.class).forEach(t -> t.removeChangeListener(trustStoreChangeListener));
}
}
};
broker.addChangeListener(brokerListener);
virtualHostNode.addChangeListener(new AbstractConfigurationChangeListener() {
@Override
public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
if (child == vhost) {
broker.removeChangeListener(brokerListener);
object.removeChangeListener(this);
broker.getChildren(TrustStore.class).forEach(t -> t.removeChangeListener(trustStoreChangeListener));
}
}
});
}
use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.
the class VirtualHostAliasTest method setUp.
@Before
public void setUp() throws Exception {
_broker = BrokerTestHelper.createBrokerMock();
AuthenticationProvider dummyAuthProvider = mock(AuthenticationProvider.class);
when(dummyAuthProvider.getName()).thenReturn("dummy");
when(dummyAuthProvider.getId()).thenReturn(UUID.randomUUID());
when(dummyAuthProvider.getMechanisms()).thenReturn(Arrays.asList("PLAIN"));
when(_broker.getChildren(eq(AuthenticationProvider.class))).thenReturn(Collections.singleton(dummyAuthProvider));
for (String name : new String[] { "red", "blue", "purple", "black" }) {
boolean defaultVHN = "black".equals(name);
VirtualHost<?> virtualHost = BrokerTestHelper.createVirtualHost(name, _broker, defaultVHN, this);
VirtualHostNode vhn = (VirtualHostNode) virtualHost.getParent();
assertNotSame(vhn.getName(), virtualHost.getName());
_vhosts.put(name, virtualHost);
if (defaultVHN) {
when(_broker.findDefautVirtualHostNode()).thenReturn(vhn);
}
}
ConfiguredObjectFactory objectFactory = _broker.getObjectFactory();
final Map<String, Object> attributes = new HashMap<>();
attributes.put(Port.NAME, getTestName());
attributes.put(Port.PORT, 0);
attributes.put(Port.AUTHENTICATION_PROVIDER, "dummy");
attributes.put(Port.TYPE, "AMQP");
_port = (AmqpPort) objectFactory.create(Port.class, attributes, _broker);
}
use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.
the class JDBCVirtualHostNodeTest method testDeleteAction.
@Test
public void testDeleteAction() {
_connectionURL = "jdbc:derby:memory:/" + getTestName();
Map<String, Object> attributes = new HashMap<>();
attributes.put(ConfiguredObject.NAME, getTestName());
attributes.put(ConfiguredObject.TYPE, JDBCVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
attributes.put("connectionUrl", _connectionURL + ";create=true");
Broker<?> broker = BrokerTestHelper.createBrokerMock();
final VirtualHostNode virtualHostNode = broker.getObjectFactory().create(VirtualHostNode.class, attributes, broker);
virtualHostNode.start();
AtomicBoolean deleted = new AtomicBoolean();
((JDBCContainer) virtualHostNode).addDeleteAction(object -> deleted.set(true));
virtualHostNode.delete();
assertEquals("Delete action was not invoked", true, deleted.get());
}
use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.
the class AbstractVirtualHostNode method validateChange.
@Override
protected void validateChange(final ConfiguredObject<?> proxyForValidation, final Set<String> changedAttributes) {
super.validateChange(proxyForValidation, changedAttributes);
VirtualHostNode updated = (VirtualHostNode) proxyForValidation;
if (changedAttributes.contains(DEFAULT_VIRTUAL_HOST_NODE) && updated.isDefaultVirtualHostNode()) {
VirtualHostNode existingDefault = _broker.findDefautVirtualHostNode();
if (existingDefault != null && existingDefault != this) {
throw new IntegrityViolationException("Cannot make '" + getName() + "' the default virtual host node for" + " the Broker as virtual host node '" + existingDefault.getName() + "' is already the default.");
}
}
}
use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.
the class ProvidedStoreVirtualHostImpl method createMessageStore.
@Override
protected MessageStore createMessageStore() {
VirtualHostNode<?> virtualHostNode = (VirtualHostNode) getParent();
MessageStoreProvider messageStoreProvider = (MessageStoreProvider) virtualHostNode.getConfigurationStore();
return messageStoreProvider.getMessageStore();
}
Aggregations