Skip to content

Commit

Permalink
Rename a few internal classes for being more consistent in naming
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 10, 2017
1 parent 103de5e commit 528d8bb
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 76 deletions.
Expand Up @@ -63,9 +63,9 @@
*
* @author <a href="http://tfox.org">Tim Fox</a>
*/
class ClientConnection extends Http1xConnectionBase implements HttpClientConnection, HttpClientStream {
class Http1xClientConnection extends Http1xConnectionBase implements HttpClientConnection, HttpClientStream {

private static final Logger log = LoggerFactory.getLogger(ClientConnection.class);
private static final Logger log = LoggerFactory.getLogger(Http1xClientConnection.class);

private final ConnectionListener<HttpClientConnection> listener;
private final HttpClientImpl client;
Expand All @@ -91,16 +91,16 @@ class ClientConnection extends Http1xConnectionBase implements HttpClientConnect
private boolean paused;
private Buffer pausedChunk;

ClientConnection(ConnectionListener<HttpClientConnection> listener,
HttpVersion version,
HttpClientImpl client,
Object endpointMetric,
ChannelHandlerContext channel,
boolean ssl,
String host,
int port,
ContextImpl context,
HttpClientMetrics metrics) {
Http1xClientConnection(ConnectionListener<HttpClientConnection> listener,
HttpVersion version,
HttpClientImpl client,
Object endpointMetric,
ChannelHandlerContext channel,
boolean ssl,
String host,
int port,
ContextImpl context,
HttpClientMetrics metrics) {
super(client.getVertx(), channel, context);
this.listener = listener;
this.client = client;
Expand Down Expand Up @@ -253,7 +253,7 @@ private void handshakeComplete(ChannelHandlerContext ctx, FullHttpResponse respo
}
// Need to set context before constructor is called as writehandler registration needs this
ContextImpl.setContext(context);
WebSocketImpl webSocket = new WebSocketImpl(vertx, ClientConnection.this, supportsContinuation,
WebSocketImpl webSocket = new WebSocketImpl(vertx, Http1xClientConnection.this, supportsContinuation,
client.getOptions().getMaxWebsocketFrameSize(),
client.getOptions().getMaxWebsocketMessageSize());
ws = webSocket;
Expand Down
Expand Up @@ -34,7 +34,7 @@
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
class ClientHandler extends VertxHttpHandler<ClientConnection> {
class Http1xClientHandler extends VertxHttpHandler<Http1xClientConnection> {
private boolean closeFrameSent;
private ContextImpl context;
private ChannelHandlerContext chctx;
Expand All @@ -47,15 +47,15 @@ class ClientHandler extends VertxHttpHandler<ClientConnection> {
private final ConnectionListener<HttpClientConnection> listener;
private final Object endpointMetric;

public ClientHandler(ConnectionListener<HttpClientConnection> listener,
ContextImpl context,
HttpVersion version,
String host,
int port,
boolean ssl,
HttpClientImpl client,
Object endpointMetric,
HttpClientMetrics metrics) {
public Http1xClientHandler(ConnectionListener<HttpClientConnection> listener,
ContextImpl context,
HttpVersion version,
String host,
int port,
boolean ssl,
HttpClientImpl client,
Object endpointMetric,
HttpClientMetrics metrics) {
this.context = context;
this.version = version;
this.client = client;
Expand All @@ -70,7 +70,7 @@ public ClientHandler(ConnectionListener<HttpClientConnection> listener,
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
chctx = ctx;
ClientConnection conn = new ClientConnection(listener, version, client, endpointMetric, ctx, ssl, host, port, context, metrics);
Http1xClientConnection conn = new Http1xClientConnection(listener, version, client, endpointMetric, ctx, ssl, host, port, context, metrics);
if (metrics != null) {
Object metric = metrics.connected(conn.remoteAddress(), conn.remoteName());
conn.metric(metric);
Expand All @@ -92,7 +92,7 @@ public void channelInactive(ChannelHandlerContext chctx) throws Exception {
}

@Override
protected void handleMessage(ClientConnection conn, ContextImpl context, ChannelHandlerContext chctx, Object msg) throws Exception {
protected void handleMessage(Http1xClientConnection conn, ContextImpl context, ChannelHandlerContext chctx, Object msg) throws Exception {
if (msg instanceof HttpObject) {
HttpObject obj = (HttpObject) msg;
DecoderResult result = obj.decoderResult();
Expand Down
Expand Up @@ -81,9 +81,9 @@
*
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class ServerConnection extends Http1xConnectionBase implements HttpConnection {
public class Http1xServerConnection extends Http1xConnectionBase implements HttpConnection {

private static final Logger log = LoggerFactory.getLogger(ServerConnection.class);
private static final Logger log = LoggerFactory.getLogger(Http1xServerConnection.class);

private static final Handler<HttpServerRequest> NULL_REQUEST_HANDLER = req -> {};

Expand Down Expand Up @@ -111,13 +111,13 @@ public class ServerConnection extends Http1xConnectionBase implements HttpConnec
// queuing == true <=> (paused || (pendingResponse != null && msg instanceof HttpRequest) || !pending.isEmpty())
private boolean queueing;

public ServerConnection(VertxInternal vertx,
SSLHelper sslHelper,
HttpServerOptions options,
ChannelHandlerContext channel,
ContextImpl context,
String serverOrigin,
HttpServerMetrics metrics) {
public Http1xServerConnection(VertxInternal vertx,
SSLHelper sslHelper,
HttpServerOptions options,
ChannelHandlerContext channel,
ContextImpl context,
String serverOrigin,
HttpServerMetrics metrics) {
super(vertx, channel, context);
this.serverOrigin = serverOrigin;
this.options = options;
Expand Down Expand Up @@ -221,7 +221,7 @@ ServerWebSocket upgrade(HttpServerRequest request, HttpRequest nettyReq) {
if (ws != null) {
return ws;
}
ServerHandler serverHandler = (ServerHandler) chctx.pipeline().get("handler");
Http1xServerHandler serverHandler = (Http1xServerHandler) chctx.pipeline().get("handler");
handshaker = serverHandler.createHandshaker(this, chctx.channel(), nettyReq);
if (handshaker == null) {
throw new IllegalStateException("Can't upgrade this request");
Expand Down Expand Up @@ -507,7 +507,7 @@ private void checkNextTick() {
}
if (channelPaused && pending.isEmpty()) {
//Resume the actual channel
ServerConnection.super.doResume();
Http1xServerConnection.super.doResume();
channelPaused = false;
}
}
Expand Down
Expand Up @@ -23,17 +23,17 @@
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class ServerHandler extends VertxHttpHandler<ServerConnection> {
public class Http1xServerHandler extends VertxHttpHandler<Http1xServerConnection> {

private static final Logger log = LoggerFactory.getLogger(ServerHandler.class);
private static final Logger log = LoggerFactory.getLogger(Http1xServerHandler.class);

private final SSLHelper sslHelper;
private final HttpServerOptions options;
private final String serverOrigin;
private final HttpServerMetrics metrics;
private final HandlerHolder<HttpHandlers> holder;

public ServerHandler(SSLHelper sslHelper, HttpServerOptions options, String serverOrigin, HandlerHolder<HttpHandlers> holder, HttpServerMetrics metrics) {
public Http1xServerHandler(SSLHelper sslHelper, HttpServerOptions options, String serverOrigin, HandlerHolder<HttpHandlers> holder, HttpServerMetrics metrics) {
this.holder = holder;
this.metrics = metrics;
this.sslHelper = sslHelper;
Expand All @@ -44,7 +44,7 @@ public ServerHandler(SSLHelper sslHelper, HttpServerOptions options, String serv
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
super.handlerAdded(ctx);
ServerConnection conn = new ServerConnection(holder.context.owner(),
Http1xServerConnection conn = new Http1xServerConnection(holder.context.owner(),
sslHelper,
options,
ctx,
Expand All @@ -65,11 +65,11 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
}

@Override
protected void handleMessage(ServerConnection conn, ContextImpl context, ChannelHandlerContext chctx, Object msg) throws Exception {
protected void handleMessage(Http1xServerConnection conn, ContextImpl context, ChannelHandlerContext chctx, Object msg) throws Exception {
conn.handleMessage(msg);
}

WebSocketServerHandshaker createHandshaker(ServerConnection conn, Channel ch, HttpRequest request) {
WebSocketServerHandshaker createHandshaker(Http1xServerConnection conn, Channel ch, HttpRequest request) {
// As a fun part, Firefox 6.0.2 supports Websockets protocol '7'. But,
// it doesn't send a normal 'Connection: Upgrade' header. Instead it
// sends: 'Connection: keep-alive, Upgrade'. Brilliant.
Expand Down
Expand Up @@ -248,7 +248,7 @@ private void http1xConnected(ConnectionListener<HttpClientConnection> listener,
ContextImpl context,
Channel ch,
Handler<AsyncResult<HttpClientConnection>> handler) {
ClientHandler clientHandler = new ClientHandler(
Http1xClientHandler clientHandler = new Http1xClientHandler(
listener,
context,
version,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/vertx/core/http/impl/HttpClientImpl.java
Expand Up @@ -948,7 +948,7 @@ public HttpClientOptions getOptions() {
private void getConnectionForWebsocket(boolean ssl,
int port,
String host,
Handler<ClientConnection> handler,
Handler<Http1xClientConnection> handler,
Handler<Throwable> connectionExceptionHandler,
ContextImpl context) {
websocketCM.getConnection(host, ssl, port, host, new Waiter<HttpClientConnection>(context) {
Expand All @@ -957,7 +957,7 @@ public void initConnection(HttpClientConnection conn) {
}
@Override
public void handleConnection(HttpClientConnection conn) {
handler.handle((ClientConnection) conn);
handler.handle((Http1xClientConnection) conn);
}
@Override
public void handleFailure(Throwable failure) {
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/io/vertx/core/http/impl/HttpConnectionPool.java
Expand Up @@ -91,8 +91,8 @@ public int maxSize() {

@Override
public void initConnection(HttpClientConnection conn) {
if (conn instanceof ClientConnection && current instanceof Http2) {
fallbackToHttp1x(((ClientConnection) conn).version());
if (conn instanceof Http1xClientConnection && current instanceof Http2) {
fallbackToHttp1x(((Http1xClientConnection) conn).version());
}
((ConnectionPool<HttpClientConnection>) current).initConnection(conn);
}
Expand Down Expand Up @@ -184,10 +184,10 @@ public ContextImpl getContext(Http2ClientConnection conn) {
}
}

private class Http1x implements ConnectionPool<ClientConnection> {
private class Http1x implements ConnectionPool<Http1xClientConnection> {

private final Set<ClientConnection> allConnections = new HashSet<>();
private final Queue<ClientConnection> availableConnections = new ArrayDeque<>();
private final Set<Http1xClientConnection> allConnections = new HashSet<>();
private final Queue<Http1xClientConnection> availableConnections = new ArrayDeque<>();
private final int maxSockets;

Http1x() {
Expand All @@ -205,8 +205,8 @@ public boolean canBorrow(int connCount) {
}

@Override
public ClientConnection pollConnection() {
ClientConnection conn;
public Http1xClientConnection pollConnection() {
Http1xClientConnection conn;
while ((conn = availableConnections.poll()) != null && !conn.isValid()) {
}
return conn;
Expand All @@ -218,20 +218,20 @@ public boolean canCreateConnection(int connCount) {
}

@Override
public void initConnection(ClientConnection conn) {
public void initConnection(Http1xClientConnection conn) {
allConnections.add(conn);
}

@Override
public void recycleConnection(ClientConnection conn) {
public void recycleConnection(Http1xClientConnection conn) {
availableConnections.add(conn);
}

public void closeAllConnections() {
Set<ClientConnection> copy = new HashSet<>(allConnections);
Set<Http1xClientConnection> copy = new HashSet<>(allConnections);
allConnections.clear();
// Close outside sync block to avoid potential deadlock
for (ClientConnection conn : copy) {
for (Http1xClientConnection conn : copy) {
try {
conn.close();
} catch (Throwable t) {
Expand All @@ -241,18 +241,18 @@ public void closeAllConnections() {
}

@Override
public void evictConnection(ClientConnection conn) {
public void evictConnection(Http1xClientConnection conn) {
allConnections.remove(conn);
availableConnections.remove(conn);
}

@Override
public boolean isValid(ClientConnection conn) {
public boolean isValid(Http1xClientConnection conn) {
return conn.isValid();
}

@Override
public ContextImpl getContext(ClientConnection conn) {
public ContextImpl getContext(Http1xClientConnection conn) {
return conn.getContext();
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/vertx/core/http/impl/HttpServerImpl.java
Expand Up @@ -122,7 +122,7 @@ public class HttpServerImpl implements HttpServer, Closeable, MetricsProvider {
private final VertxInternal vertx;
private final SSLHelper sslHelper;
private final ContextImpl creatingContext;
private final Map<Channel, ServerConnection> connectionMap = new ConcurrentHashMap<>();
private final Map<Channel, Http1xServerConnection> connectionMap = new ConcurrentHashMap<>();
private final Map<Channel, Http2ServerConnection> connectionMap2 = new ConcurrentHashMap<>();
private final VertxEventLoopGroup availableWorkers = new VertxEventLoopGroup();
private final HandlerManager<HttpHandlers> httpHandlerMgr = new HandlerManager<>(availableWorkers);
Expand Down Expand Up @@ -455,11 +455,11 @@ private void configureHttp1(ChannelPipeline pipeline) {
pipeline.addLast("h2c", new Http2UpgradeHandler());
}
HandlerHolder<HttpHandlers> holder = httpHandlerMgr.chooseHandler(pipeline.channel().eventLoop());
ServerHandler handler;
Http1xServerHandler handler;
if (DISABLE_WEBSOCKETS) {
// As a performance optimisation you can set a system property to disable websockets altogether which avoids
// some casting and a header check
handler = new ServerHandler(sslHelper, options, serverOrigin, holder, metrics);
handler = new Http1xServerHandler(sslHelper, options, serverOrigin, holder, metrics);
} else {
handler = new ServerHandlerWithWebSockets(sslHelper, options, serverOrigin, holder, metrics);
}
Expand Down Expand Up @@ -585,7 +585,7 @@ private void actualClose(final ContextImpl closeContext, final Handler<AsyncResu

ContextImpl currCon = vertx.getContext();

for (ServerConnection conn : connectionMap.values()) {
for (Http1xServerConnection conn : connectionMap.values()) {
conn.close();
}
for (Http2ServerConnection conn : connectionMap2.values()) {
Expand Down Expand Up @@ -617,7 +617,7 @@ private void executeCloseDone(final ContextImpl closeContext, final Handler<Asyn
}
}

public class ServerHandlerWithWebSockets extends ServerHandler {
public class ServerHandlerWithWebSockets extends Http1xServerHandler {

private boolean closeFrameSent;
private FullHttpRequest wsRequest;
Expand All @@ -629,7 +629,7 @@ public ServerHandlerWithWebSockets(SSLHelper sslHelper, HttpServerOptions option
}

@Override
protected void handleMessage(ServerConnection conn, ContextImpl context, ChannelHandlerContext chctx, Object msg) throws Exception {
protected void handleMessage(Http1xServerConnection conn, ContextImpl context, ChannelHandlerContext chctx, Object msg) throws Exception {
Channel ch = chctx.channel();
if (msg instanceof HttpRequest) {
final HttpRequest request = (HttpRequest) msg;
Expand Down Expand Up @@ -714,7 +714,7 @@ protected void handleMessage(ServerConnection conn, ContextImpl context, Channel
}
}

protected void handshake(ServerConnection conn, FullHttpRequest request, Channel ch, ChannelHandlerContext ctx) throws Exception {
protected void handshake(Http1xServerConnection conn, FullHttpRequest request, Channel ch, ChannelHandlerContext ctx) throws Exception {

WebSocketServerHandshaker shake = createHandshaker(conn, ch, request);
if (shake == null) {
Expand Down
Expand Up @@ -64,7 +64,7 @@ public class HttpServerRequestImpl implements HttpServerRequest {

private static final Logger log = LoggerFactory.getLogger(HttpServerRequestImpl.class);

private final ServerConnection conn;
private final Http1xServerConnection conn;
private final HttpRequest request;
private final HttpServerResponse response;

Expand All @@ -91,7 +91,7 @@ public class HttpServerRequestImpl implements HttpServerRequest {
private boolean ended;


HttpServerRequestImpl(ServerConnection conn,
HttpServerRequestImpl(Http1xServerConnection conn,
HttpRequest request,
HttpServerResponse response) {
this.conn = conn;
Expand Down
Expand Up @@ -59,7 +59,7 @@ public class HttpServerResponseImpl implements HttpServerResponse {
private static final Logger log = LoggerFactory.getLogger(HttpServerResponseImpl.class);

private final VertxInternal vertx;
private final ServerConnection conn;
private final Http1xServerConnection conn;
private HttpResponseStatus status;
private final HttpVersion version;
private final boolean keepAlive;
Expand All @@ -81,7 +81,7 @@ public class HttpServerResponseImpl implements HttpServerResponse {
private String statusMessage;
private long bytesWritten;

HttpServerResponseImpl(final VertxInternal vertx, ServerConnection conn, HttpRequest request) {
HttpServerResponseImpl(final VertxInternal vertx, Http1xServerConnection conn, HttpRequest request) {
this.vertx = vertx;
this.conn = conn;
this.version = request.getProtocolVersion();
Expand Down

0 comments on commit 528d8bb

Please sign in to comment.