use of org.apache.qpid.server.model.Protocol in project qpid-broker-j by apache.
the class ManagementModeStoreHandler method quiesceEntries.
private Map<UUID, Object> quiesceEntries(final SystemConfig<?> options, List<ConfiguredObjectRecord> records) {
final Map<UUID, Object> quiescedEntries = new HashMap<UUID, Object>();
final int managementModeHttpPortOverride = options.getManagementModeHttpPortOverride();
for (ConfiguredObjectRecord entry : records) {
String entryType = entry.getType();
Map<String, Object> attributes = entry.getAttributes();
boolean quiesce = false;
if (VIRTUAL_HOST_TYPE.equals(entryType) && options.isManagementModeQuiesceVirtualHosts()) {
quiesce = true;
} else if (PORT_TYPE.equals(entryType)) {
if (attributes == null) {
throw new IllegalConfigurationException("Port attributes are not set in " + entry);
}
Set<Protocol> protocols = getPortProtocolsAttribute(attributes);
if (protocols == null) {
quiesce = true;
} else {
for (Protocol protocol : protocols) {
switch(protocol) {
case HTTP:
quiesce = managementModeHttpPortOverride > 0;
break;
default:
quiesce = true;
}
}
}
}
if (quiesce) {
LOGGER.debug("Management mode quiescing entry {}", entry);
// save original state
quiescedEntries.put(entry.getId(), attributes.get(ATTRIBUTE_STATE));
}
}
return quiescedEntries;
}
use of org.apache.qpid.server.model.Protocol in project qpid-broker-j by apache.
the class ManagementModeStoreHandler method recoverRecords.
public void recoverRecords(final List<ConfiguredObjectRecord> records) {
boolean b = _systemConfig.getManagementModeHttpPortOverride() > 0;
for (ConfiguredObjectRecord object : records) {
String entryType = object.getType();
Map<String, Object> attributes = object.getAttributes();
boolean quiesce = false;
if (VIRTUAL_HOST_TYPE.equals(entryType) && _systemConfig.isManagementModeQuiesceVirtualHosts()) {
quiesce = true;
} else if (PORT_TYPE.equals(entryType)) {
if (attributes == null) {
throw new IllegalConfigurationException("Port attributes are not set in " + object);
}
Set<Protocol> protocols = getPortProtocolsAttribute(attributes);
if (protocols == null) {
quiesce = true;
} else {
for (Protocol protocol : protocols) {
switch(protocol) {
case HTTP:
quiesce = b;
break;
default:
quiesce = true;
}
}
}
}
if (quiesce) {
LOGGER.debug("Management mode quiescing entry {}", object);
// save original state
_quiescedEntriesOriginalState.put(object.getId(), attributes.get(ATTRIBUTE_STATE));
Map<String, Object> modifiedAttributes = new HashMap<String, Object>(attributes);
modifiedAttributes.put(ATTRIBUTE_STATE, State.QUIESCED);
ConfiguredObjectRecord record = new ConfiguredObjectRecordImpl(object.getId(), object.getType(), modifiedAttributes, object.getParents());
_records.put(record.getId(), record);
} else {
_records.put(object.getId(), object);
}
}
}
use of org.apache.qpid.server.model.Protocol in project qpid-broker-j by apache.
the class AmqpPortImpl method getInstalledProtocolsAsString.
public static String getInstalledProtocolsAsString() {
Set<Protocol> installedProtocols = getInstalledProtocols();
ObjectMapper mapper = new ObjectMapper();
try (StringWriter output = new StringWriter()) {
mapper.writeValue(output, installedProtocols);
return output.toString();
} catch (IOException e) {
throw new ServerScopedRuntimeException(e);
}
}
use of org.apache.qpid.server.model.Protocol in project qpid-broker-j by apache.
the class AmqpPortImpl method getAllAvailableProtocolCombinations.
@SuppressWarnings("unused")
public static Collection<String> getAllAvailableProtocolCombinations() {
Set<Protocol> protocols = getInstalledProtocols();
Set<Set<String>> last = new HashSet<>();
for (Protocol protocol : protocols) {
last.add(Collections.singleton(protocol.name()));
}
Set<Set<String>> protocolCombinations = new HashSet<>(last);
for (int i = 1; i < protocols.size(); i++) {
Set<Set<String>> current = new HashSet<>();
for (Set<String> set : last) {
for (Protocol p : protocols) {
if (!set.contains(p.name())) {
Set<String> potential = new HashSet<>(set);
potential.add(p.name());
current.add(potential);
}
}
}
protocolCombinations.addAll(current);
last = current;
}
Set<String> combinationsAsString = new HashSet<>(protocolCombinations.size());
ObjectMapper mapper = new ObjectMapper();
for (Set<String> combination : protocolCombinations) {
try (StringWriter writer = new StringWriter()) {
mapper.writeValue(writer, combination);
combinationsAsString.add(writer.toString());
} catch (IOException e) {
throw new IllegalArgumentException("Unexpected IO Exception generating JSON string", e);
}
}
return Collections.unmodifiableSet(combinationsAsString);
}
use of org.apache.qpid.server.model.Protocol in project qpid-broker-j by apache.
the class PortFactory method getProtocolType.
private ProtocolType getProtocolType(Map<String, Object> portAttributes, Broker<?> broker) {
Model model = broker.getModel();
ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry();
Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes = typeRegistry.getAttributeTypes(Port.class);
ConfiguredSettableAttribute protocolsAttribute = (ConfiguredSettableAttribute) attributeTypes.get(Port.PROTOCOLS);
Set<Protocol> protocols = (Set<Protocol>) protocolsAttribute.convert(portAttributes.get(Port.PROTOCOLS), broker);
ProtocolType protocolType = null;
if (protocols == null || protocols.isEmpty()) {
// defaulting to AMQP if protocol is not specified
protocolType = ProtocolType.AMQP;
} else {
for (Protocol protocol : protocols) {
if (protocolType == null) {
protocolType = protocol.getProtocolType();
} else if (protocolType != protocol.getProtocolType()) {
throw new IllegalConfigurationException("Found different protocol types '" + protocolType + "' and '" + protocol.getProtocolType() + "' for port configuration: " + portAttributes);
}
}
}
return protocolType;
}
Aggregations