use of org.apache.qpid.server.model.Transport in project qpid-broker-j by apache.
the class HttpManagement method createConnector.
private ServerConnector createConnector(final HttpPort<?> port, final Server server) {
port.setPortManager(this);
if (port.getState() != State.ACTIVE) {
// TODO - RG - probably does nothing
port.startAsync();
}
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory();
httpConnectionFactory.getHttpConfiguration().setSendServerVersion(false);
httpConnectionFactory.getHttpConfiguration().setSendXPoweredBy(false);
HttpConfiguration.Customizer requestAttributeCustomizer = (connector, httpConfiguration, request) -> HttpManagementUtil.getPortAttributeAction(port).performAction(request);
httpConnectionFactory.getHttpConfiguration().addCustomizer(requestAttributeCustomizer);
httpConnectionFactory.getHttpConfiguration().addCustomizer(new SecureRequestCustomizer());
ConnectionFactory[] connectionFactories;
Collection<Transport> transports = port.getTransports();
if (!transports.contains(Transport.SSL)) {
connectionFactories = new ConnectionFactory[] { httpConnectionFactory };
} else if (transports.contains(Transport.SSL)) {
SslContextFactory sslContextFactory = getSslContextFactory(port);
ConnectionFactory sslConnectionFactory;
if (port.getTransports().contains(Transport.TCP)) {
sslConnectionFactory = new TlsOrPlainConnectionFactory(sslContextFactory, httpConnectionFactory.getProtocol());
} else {
sslConnectionFactory = new SslConnectionFactory(sslContextFactory, httpConnectionFactory.getProtocol());
}
connectionFactories = new ConnectionFactory[] { sslConnectionFactory, httpConnectionFactory };
} else {
throw new IllegalArgumentException("Unexpected transport on port " + port.getName() + ":" + transports);
}
ServerConnector connector = new ServerConnector(server, new QBBTrackingThreadPool(port.getThreadPoolMaximum(), port.getThreadPoolMinimum()), null, null, port.getDesiredNumberOfAcceptors(), port.getDesiredNumberOfSelectors(), connectionFactories) {
@Override
public void open() throws IOException {
try {
super.open();
} catch (BindException e) {
InetSocketAddress addr = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
throw new PortBindFailureException(addr);
}
}
};
connector.setAcceptQueueSize(port.getAcceptBacklogSize());
String bindingAddress = port.getBindingAddress();
if (bindingAddress != null && !bindingAddress.trim().equals("") && !bindingAddress.trim().equals("*")) {
connector.setHost(bindingAddress.trim());
}
connector.setPort(port.getPort());
if (transports.contains(Transport.SSL)) {
connector.addBean(new SslHandshakeListener() {
@Override
public void handshakeFailed(final Event event, final Throwable failure) {
SSLEngine sslEngine = event.getSSLEngine();
if (LOGGER.isDebugEnabled()) {
LOGGER.info("TLS handshake failed: host='{}', port={}", sslEngine.getPeerHost(), sslEngine.getPeerPort(), failure);
} else {
LOGGER.info("TLS handshake failed: host='{}', port={}: {}", sslEngine.getPeerHost(), sslEngine.getPeerPort(), String.valueOf(failure));
}
}
});
}
int acceptors = connector.getAcceptors();
int selectors = connector.getSelectorManager().getSelectorCount();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Created connector for http port {} with maxThreads={}, minThreads={}, acceptors={}, selectors={}, acceptBacklog={}", port.getName(), port.getThreadPoolMaximum(), port.getThreadPoolMinimum(), acceptors, selectors, port.getAcceptBacklogSize());
}
int requiredNumberOfConnections = acceptors + 2 * selectors + 1;
if (port.getThreadPoolMaximum() < requiredNumberOfConnections) {
throw new IllegalConfigurationException(String.format("Insufficient number of threads is configured on http port '%s': max=%d < needed(acceptors=%d + selectors=2*%d + request=1)", port.getName(), port.getThreadPoolMaximum(), acceptors, selectors));
}
return connector;
}
use of org.apache.qpid.server.model.Transport in project qpid-broker-j by apache.
the class AmqpPortImpl method onActivate.
@Override
protected State onActivate() {
if (getAncestor(SystemConfig.class).isManagementMode()) {
return State.QUIESCED;
} else {
Collection<Transport> transports = getTransports();
TransportProvider transportProvider = null;
final HashSet<Transport> transportSet = new HashSet<>(transports);
for (TransportProviderFactory tpf : (new QpidServiceLoader()).instancesOf(TransportProviderFactory.class)) {
if (tpf.getSupportedTransports().contains(transports)) {
transportProvider = tpf.getTransportProvider(transportSet);
}
}
if (transportProvider == null) {
throw new IllegalConfigurationException("No transport providers found which can satisfy the requirement to support the transports: " + transports);
}
if (transports.contains(Transport.SSL) || transports.contains(Transport.WSS)) {
_sslContext = createSslContext();
}
Protocol defaultSupportedProtocolReply = getDefaultAmqpSupportedReply();
try {
_transport = transportProvider.createTransport(transportSet, _sslContext, this, getProtocols(), defaultSupportedProtocolReply);
_transport.start();
_boundPort = _transport.getAcceptingPort();
for (Transport transport : getTransports()) {
_container.getEventLogger().message(BrokerMessages.LISTENING(String.valueOf(transport), _transport.getAcceptingPort()));
}
return State.ACTIVE;
} catch (PortBindFailureException e) {
_container.getEventLogger().message(PortMessages.BIND_FAILED(getType().toUpperCase(), getPort()));
throw e;
}
}
}
use of org.apache.qpid.server.model.Transport in project qpid-broker-j by apache.
the class AmqpPortImpl method getAllAvailableTransportCombinations.
@SuppressWarnings("unused")
public static Collection<String> getAllAvailableTransportCombinations() {
Set<Set<Transport>> combinations = new HashSet<>();
for (TransportProviderFactory providerFactory : (new QpidServiceLoader()).instancesOf(TransportProviderFactory.class)) {
combinations.addAll(providerFactory.getSupportedTransports());
}
Set<String> combinationsAsString = new HashSet<>(combinations.size());
ObjectMapper mapper = new ObjectMapper();
for (Set<Transport> combination : combinations) {
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);
}
Aggregations