com.marklogic.xcc.spi

## Interface ServerConnection

-     public interface ServerConnection

  This class encapsulates a server connection as returned from a `ConnectionProvider` instance.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.nio.channels.ByteChannel` | `channel()` The channel to be used for server communication.
    `void` | `close()` Close this server connection.
    `long` | `getTimeoutMillis()` A timeout value, in milliseconds, which is a hint to the provider upon return to indicate how long this connection should be considered valid.
    `long` | `getTimeoutTime()` Get the exact time, in milliseconds, at which this connection is considered to be expired.
    `boolean` | `isOpen()` Indicates whether the underlying connection channel is open.
    `ConnectionProvider` | `provider()` The `ConnectionProvider` to which this connection should be returned.
    `void` | `setTimeoutMillis(long timeoutMillis)` Deprecated. Use `setTimeoutTime(long)` instead.
    `void` | `setTimeoutTime(long timeMillis)` Set the exact time, as milliseconds since the epoch, at which this connection is to be considered expired.

- - ### Method Detail

    - #### channel

          java.nio.channels.ByteChannel channel()

      The channel to be used for server communication.
      Returns:
        An open, bi-directional `ByteChannel` connected to a server.

    - #### provider

          ConnectionProvider provider()

      The `ConnectionProvider` to which this connection should be returned.
      Returns:
        An instance of `ConnectionProvider`.

    - #### getTimeoutMillis

          long getTimeoutMillis()

      A timeout value, in milliseconds, which is a hint to the provider upon return to indicate how long this connection should be considered valid. Providers are expected to set this value to zero when giving out a connection via `ConnectionProvider.obtainConnection(com.marklogic.xcc.Session,com.marklogic.xcc.Request,java.util.logging.Logger)` .

      As of 3.2-6 and later, this method returns the number of milliseconds until this connection will expire. If the connection is already expired, then zero is returned.

      Returns:
        A duration, in milliseconds, or zero if already expired.

    - #### setTimeoutMillis

          @Deprecated
          void setTimeoutMillis(long timeoutMillis)

      Deprecated. Use `setTimeoutTime(long)` instead.
      Set the suggested timeout value for this connection. This value is only used by the provider when a connection is passed to `ConnectionProvider.returnConnection(ServerConnection, java.util.logging.Logger)`.
      Parameters:
        `timeoutMillis` - A duration, in milliseconds.

    - #### getTimeoutTime

          long getTimeoutTime()

      Get the exact time, in milliseconds, at which this connection is considered to be expired.
      Returns:
        A time in milliseconds, as for `System.currentTimeMillis()`
      Since:
        3.2-6

    - #### setTimeoutTime

          void setTimeoutTime(long timeMillis)

      Set the exact time, as milliseconds since the epoch, at which this connection is to be considered expired.
      Parameters:
        `timeMillis` - A time in milliseconds, as for `System.currentTimeMillis()`
      Since:
        3.2-6

    - #### close

          void close()

      Close this server connection. If a connection is closed when returned to the provider, it will be silently dropped.

    - #### isOpen

          boolean isOpen()

      Indicates whether the underlying connection channel is open.
      Returns:
        true is open, false if closed.

Copyright © 2025 MarkLogic Corporation. All Rights Reserved.

Complete online documentation for MarkLogic Server, XQuery and related components may be found at developer.marklogic.com