org.apache.tinkerpop.gremlin.server

## Class ResponseHandlerContext

- java.lang.Object
- - org.apache.tinkerpop.gremlin.server.ResponseHandlerContext

-     public class ResponseHandlerContext
      extends Object

  A context for asynchronously writing response messages related to a particular request.

  The "write" methods of this class ensure that at most one `final` response message is written to the underlying channel. Attempts to write more than one final response message will be ignored with a warning log message.

  Note: an object of this class should be used instead of writing to the channel directly when multiple threads are expected to produce final response messages concurrently. Callers must ensure that the same `ResponseHandlerContext` is used by all threads writing response messages for the same request.

  Author:
    Dmitri Bourlatchkov

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResponseHandlerContext(Context context)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Context` | `getContext()`
    `void` | `writeAndFlush(ResponseMessage message)` Writes a response message to the underlying channel while ensuring that at most one `final` response is written.
    `void` | `writeAndFlush(ResponseStatusCode code, Object responseMessage)` Writes a response message to the underlying channel while ensuring that at most one `final` response is written.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ResponseHandlerContext

          public ResponseHandlerContext(Context context)

  - ### Method Detail

    - #### getContext

          public Context getContext()

    - #### writeAndFlush

          public void writeAndFlush(ResponseMessage message)

      Writes a response message to the underlying channel while ensuring that at most one `final` response is written.

      Note: this method should be used instead of writing to the channel directly when multiple threads are expected to produce response messages concurrently.

      Attempts to write more than one final response message will be ignored.

      See Also:
        `writeAndFlush(ResponseStatusCode, Object)`

    - #### writeAndFlush

          public void writeAndFlush(ResponseStatusCode code,
                                    Object responseMessage)

      Writes a response message to the underlying channel while ensuring that at most one `final` response is written.

      The caller must make sure that the provided response status code matches the content of the message.

      Note: this method should be used instead of writing to the channel directly when multiple threads are expected to produce response messages concurrently.

      Attempts to write more than one final response message will be ignored.

      See Also:
        `writeAndFlush(ResponseMessage)`

Copyright © 2013–2019 Apache Software Foundation. All rights reserved.