@Override
    public void doClose(ServerStatusAndMetadata statusAndMetadata) {
        final Status status = statusAndMetadata.status();
        final Metadata metadata = statusAndMetadata.metadata();
        final boolean trailersOnly;
        if (firstResponse != null) {
            // ResponseHeaders was written successfully.
            trailersOnly = false;
        } else {
            final ResponseHeaders responseHeaders = responseHeaders();
            if (!status.isOk() || responseHeaders == null) {
                // Trailers-Only is permitted for calls that produce an immediate error.
                // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses
                trailersOnly = true;
            } else {
                // A unary response should not reach hear.
                // The status should be non-OK if serverSendsOneMessage's firstResponse is null.
                assert !method.getType().serverSendsOneMessage();

                // SERVER_STREAMING or BIDI_STREAMING may not produce a response.
                // Try to write the pending response headers.
                if (res.tryWrite(responseHeaders)) {
                    trailersOnly = false;
                } else {
                    // A stream was closed already.
                    statusAndMetadata.shouldCancel(true);
                    closeListener(statusAndMetadata);
                    return;
                }
            }
        }

        // Set responseContent before closing stream to use responseCause in error handling
        ctx.logBuilder().responseContent(GrpcLogUtil.rpcResponse(statusAndMetadata, firstResponse), null);
        try {
            if (res.tryWrite(responseTrailers(ctx, status, metadata, trailersOnly))) {
                res.close();
            }
        } finally {
            closeListener(statusAndMetadata);
        }
    }
Encapsulates the state of a single server call, reading messages from the client, passing to business logic
via {@link ServerCall.Listener}, and writing messages passed back to the response.
grpc/src/main/java/com/linecorp/armeria/server/grpc/StreamingServerCall.java