Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ProxyServerBuilder class. #581

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.hotels.styx.proxy;
package com.hotels.styx;

import com.codahale.metrics.Histogram;
import com.hotels.styx.api.HttpHandler;
import com.hotels.styx.api.MetricRegistry;
import com.hotels.styx.proxy.HttpCompressor;
import com.hotels.styx.proxy.ServerProtocolDistributionRecorder;
import com.hotels.styx.proxy.encoders.ConfigurableUnwiseCharsEncoder;
import com.hotels.styx.server.ConnectorConfig;
import com.hotels.styx.server.HttpErrorStatusListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2018 Expedia Inc.
Copyright (C) 2013-2019 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -13,17 +13,15 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.hotels.styx.proxy;

import com.hotels.styx.Environment;
package com.hotels.styx;

import static com.hotels.styx.StyxConfig.NO_JVM_ROUTE_SET;
import com.hotels.styx.api.LiveHttpRequest;

/**
* Formats response info into a string.
*/
public class ResponseInfoFormat {
class ResponseInfoFormat {
private final String format;

ResponseInfoFormat(Environment environment) {
Expand Down
31 changes: 28 additions & 3 deletions components/proxy/src/main/java/com/hotels/styx/StyxServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
import com.hotels.styx.api.extension.service.spi.StyxService;
import com.hotels.styx.config.schema.SchemaValidationException;
import com.hotels.styx.infrastructure.MemoryBackedRegistry;
import com.hotels.styx.proxy.ProxyServerBuilder;
import com.hotels.styx.proxy.plugin.NamedPlugin;
import com.hotels.styx.server.ConnectorConfig;
import com.hotels.styx.server.HttpServer;
import com.hotels.styx.server.ServerEventLoopFactory;
import com.hotels.styx.server.netty.NettyServerBuilder;
import com.hotels.styx.server.netty.NettyServerConfig;
import com.hotels.styx.server.netty.ServerConnector;
import com.hotels.styx.server.netty.eventloop.PlatformAwareServerEventLoopFactory;
import com.hotels.styx.startup.StyxServerComponents;
import io.netty.util.ResourceLeakDetector;
import org.jetbrains.annotations.NotNull;
Expand All @@ -50,6 +54,8 @@

import static com.hotels.styx.infrastructure.logging.LOGBackConfigurer.initLogging;
import static com.hotels.styx.infrastructure.logging.LOGBackConfigurer.shutdownLogging;
import static com.hotels.styx.proxy.encoders.ConfigurableUnwiseCharsEncoder.ENCODE_UNWISECHARS;
import static com.hotels.styx.server.netty.eventloop.ServerEventLoopFactories.memoize;
import static com.hotels.styx.startup.CoreMetrics.registerCoreMetrics;
import static io.netty.util.ResourceLeakDetector.Level.DISABLED;
import static java.lang.Runtime.getRuntime;
Expand Down Expand Up @@ -224,10 +230,29 @@ public InetSocketAddress adminHttpAddress() {
return adminServer.inetAddress();
}

// This function will be removed in near future:
private static ServerEventLoopFactory serverEventLoopFactory(String name, NettyServerConfig serverConfig) {
return memoize(new PlatformAwareServerEventLoopFactory(name, serverConfig.bossThreadsCount(), serverConfig.workerThreadsCount()));
}

private static HttpServer httpServer(Environment environment, ConnectorConfig connectorConfig, HttpHandler styxDataPlane) {
return new ProxyServerBuilder(environment)
CharSequence styxInfoHeaderName = environment.configuration().styxHeaderConfig().styxInfoHeaderName();
ResponseInfoFormat responseInfoFormat = new ResponseInfoFormat(environment);

ServerConnector proxyConnector = new ProxyConnectorFactory(
environment.configuration().proxyServerConfig(),
environment.metricRegistry(),
environment.errorListener(),
environment.configuration().get(ENCODE_UNWISECHARS).orElse(""),
(builder, request) -> builder.header(styxInfoHeaderName, responseInfoFormat.format(request)),
environment.configuration().get("requestTracking", Boolean.class).orElse(false))
.create(connectorConfig);

return NettyServerBuilder.newBuilder()
.setMetricsRegistry(environment.metricRegistry())
.setServerEventLoopFactory(serverEventLoopFactory("Proxy", environment.configuration().proxyServerConfig()))
.setProtocolConnector(proxyConnector)
.handler(styxDataPlane)
.connectorConfig(connectorConfig)
.build();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.hotels.styx.proxy;
package com.hotels.styx;

import com.hotels.styx.Environment;
import com.hotels.styx.StyxConfig;
import com.hotels.styx.api.LiveHttpRequest;
import com.hotels.styx.api.configuration.Configuration;
import com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2019 Expedia Inc.
Copyright (C) 2013-2020 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,6 @@ import com.hotels.styx.api.HttpResponseStatus.{BAD_GATEWAY, INTERNAL_SERVER_ERRO
import com.hotels.styx.api.extension.service.BackendService
import com.hotels.styx.infrastructure.{MemoryBackedRegistry, RegistryServiceAdapter}
import com.hotels.styx.support.ImplicitStyxConversions
import com.hotels.styx.support.backends.FakeHttpServer
import com.hotels.styx.support.backends.FakeHttpServer.HttpStartupConfig
import com.hotels.styx.support.configuration
import com.hotels.styx.support.configuration._
Expand Down