mirror of https://github.com/grpc/grpc-java.git
netty: Add ProtocolNegotiator.close
This notifies the negotiator when it will no longer be used, allowing it to clean up any resources.
This commit is contained in:
parent
09737fea7a
commit
99a2cac07a
|
|
@ -61,6 +61,11 @@ public abstract class AltsProtocolNegotiator implements ProtocolNegotiator {
|
|||
handshakerFactory.newHandshaker(grpcHandler.getAuthority()))),
|
||||
new TsiFrameHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// TODO(jiangtaoli2016): release resources
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -75,6 +80,11 @@ public abstract class AltsProtocolNegotiator implements ProtocolNegotiator {
|
|||
new TsiHandshakeHandler(new NettyTsiHandshaker(handshakerFactory.newHandshaker(null))),
|
||||
new TsiFrameHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// TODO(jiangtaoli2016): release resources
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,4 +49,10 @@ public final class GoogleDefaultProtocolNegotiator implements ProtocolNegotiator
|
|||
return tlsProtocolNegotiator.newHandler(grpcHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
altsProtocolNegotiator.close();
|
||||
tlsProtocolNegotiator.close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -526,6 +526,7 @@ public final class NettyChannelBuilder
|
|||
}
|
||||
closed = true;
|
||||
|
||||
protocolNegotiator.close();
|
||||
if (usingSharedGroup) {
|
||||
SharedResourceHolder.release(Utils.DEFAULT_WORKER_EVENT_LOOP_GROUP, group);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,4 +43,11 @@ public interface ProtocolNegotiator {
|
|||
* completed successfully.
|
||||
*/
|
||||
Handler newHandler(GrpcHttp2ConnectionHandler grpcHandler);
|
||||
|
||||
/**
|
||||
* Releases resources held by this negotiator. Called when the Channel transitions to terminated.
|
||||
* Is currently only supported on client-side; server-side protocol negotiators will not see this
|
||||
* method called.
|
||||
*/
|
||||
void close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,9 @@ public final class ProtocolNegotiators {
|
|||
|
||||
return new PlaintextHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +120,9 @@ public final class ProtocolNegotiators {
|
|||
public Handler newHandler(GrpcHttp2ConnectionHandler handler) {
|
||||
return new ServerTlsHandler(sslContext, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -207,6 +213,13 @@ public final class ProtocolNegotiators {
|
|||
return new BufferUntilProxyTunnelledHandler(
|
||||
proxyHandler, negotiator.newHandler(http2Handler));
|
||||
}
|
||||
|
||||
// This method is not normally called, because we use httpProxy on a per-connection basis in
|
||||
// NettyChannelBuilder. Instead, we expect `negotiator' to be closed by NettyTransportFactory.
|
||||
@Override
|
||||
public void close() {
|
||||
negotiator.close();
|
||||
}
|
||||
}
|
||||
|
||||
return new ProxyNegotiator();
|
||||
|
|
@ -310,6 +323,9 @@ public final class ProtocolNegotiators {
|
|||
};
|
||||
return new BufferUntilTlsNegotiatedHandler(sslBootstrap, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
}
|
||||
|
||||
/** A tuple of (host, port). */
|
||||
|
|
@ -341,6 +357,9 @@ public final class ProtocolNegotiators {
|
|||
new HttpClientUpgradeHandler(httpClientCodec, upgradeCodec, 1000);
|
||||
return new BufferingHttp2UpgradeHandler(upgrader, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -357,6 +376,9 @@ public final class ProtocolNegotiators {
|
|||
public Handler newHandler(GrpcHttp2ConnectionHandler handler) {
|
||||
return new BufferUntilChannelActiveHandler(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
}
|
||||
|
||||
private static RuntimeException unavailableException(String msg) {
|
||||
|
|
|
|||
|
|
@ -821,5 +821,8 @@ public class NettyClientTransportTest {
|
|||
this.grpcHandler = grpcHandler;
|
||||
return handler = new NoopHandler(grpcHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue