Class ObservableReactiveSession

java.lang.Object
org.springframework.data.cassandra.observability.ObservableReactiveSession
All Implemented Interfaces:
Closeable, AutoCloseable, ReactiveSession

public class ObservableReactiveSession extends Object implements ReactiveSession
Instrumented ReactiveSession for observability.
Since:
4.0
Author:
Mark Paluch, Marcin Grzejszczak
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Initiates a shutdown of this session instance and blocks until that shutdown completes.
    create(ReactiveSession session, io.micrometer.observation.ObservationRegistry observationRegistry)
    Factory method for creation of a ObservableReactiveSession.
    create(ReactiveSession session, String remoteServiceName, io.micrometer.observation.ObservationRegistry observationRegistry)
    Factory method for creation of a ObservableReactiveSession.
    reactor.core.publisher.Mono<ReactiveResultSet>
    execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement)
    Executes the provided query.
    reactor.core.publisher.Mono<ReactiveResultSet>
    Executes the provided query.
    reactor.core.publisher.Mono<ReactiveResultSet>
    execute(String cql, Object... objects)
    Executes the provided query using the provided values.
    reactor.core.publisher.Mono<ReactiveResultSet>
    Executes the provided query using the provided named values.
    com.datastax.oss.driver.api.core.context.DriverContext
    Returns a context that provides access to all the policies used by this driver instance.
    Optional<com.datastax.oss.driver.api.core.CqlIdentifier>
    The keyspace that this session is currently connected to, or Optional.empty() if this session is not connected to any keyspace.
    com.datastax.oss.driver.api.core.metadata.Metadata
    Returns a snapshot of the Cassandra cluster's topology and schema metadata.
    boolean
    Whether this Session instance has been closed.
    reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement>
    prepare(com.datastax.oss.driver.api.core.cql.SimpleStatement statement)
    Prepares the provided query.
    reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement>
    Prepares the provided query string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static ReactiveSession create(ReactiveSession session, io.micrometer.observation.ObservationRegistry observationRegistry)
      Factory method for creation of a ObservableReactiveSession.
      Parameters:
      session - reactive session.
      observationRegistry - observation registry.
      Returns:
      traced representation of a ReactiveSession.
    • create

      public static ReactiveSession create(ReactiveSession session, String remoteServiceName, io.micrometer.observation.ObservationRegistry observationRegistry)
      Factory method for creation of a ObservableReactiveSession.
      Parameters:
      session - reactive session.
      observationRegistry - observation registry.
      Returns:
      traced representation of a ReactiveSession.
    • isClosed

      public boolean isClosed()
      Description copied from interface: ReactiveSession
      Whether this Session instance has been closed.

      Note that this method returns true as soon as the closing of this Session has started but it does not guarantee that the closing is done. If you want to guarantee that the closing is done, you can call close() and wait until it returns (or call the get method on closeAsync() with a very short timeout and check this doesn't timeout).

      Specified by:
      isClosed in interface ReactiveSession
      Returns:
      true if this Session instance has been closed, false otherwise.
    • getContext

      public com.datastax.oss.driver.api.core.context.DriverContext getContext()
      Description copied from interface: ReactiveSession
      Returns a context that provides access to all the policies used by this driver instance.
      Specified by:
      getContext in interface ReactiveSession
      Returns:
      a context that provides access to all the policies used by this driver instance.
    • getKeyspace

      public Optional<com.datastax.oss.driver.api.core.CqlIdentifier> getKeyspace()
      Description copied from interface: ReactiveSession
      The keyspace that this session is currently connected to, or Optional.empty() if this session is not connected to any keyspace.

      There are two ways that this can be set: before initializing the session (either with the session-keyspace option in the configuration, or with SessionBuilder.withKeyspace(CqlIdentifier)); or at runtime, if the client issues a request that changes the keyspace (such as a CQL USE query). Note that this second method is inherently unsafe, since other requests expecting the old keyspace might be executing concurrently. Therefore it is highly discouraged, aside from trivial cases (such as a cqlsh-style program where requests are never concurrent).

      Specified by:
      getKeyspace in interface ReactiveSession
    • getMetadata

      public com.datastax.oss.driver.api.core.metadata.Metadata getMetadata()
      Description copied from interface: ReactiveSession
      Returns a snapshot of the Cassandra cluster's topology and schema metadata.

      In order to provide atomic updates, this method returns an immutable object: the node list, token map, and schema contained in a given instance will always be consistent with each other (but note that Node itself is not immutable: some of its properties will be updated dynamically, in particular Node.getState()).

      As a consequence of the above, you should call this method each time you need a fresh view of the metadata. Do not call it once and store the result, because it is a frozen snapshot that will become stale over time.

      If a metadata refresh triggers events (such as node added/removed, or schema events), then the new version of the metadata is guaranteed to be visible by the time you receive these events.

      Specified by:
      getMetadata in interface ReactiveSession
      Returns:
      never null, but may be empty if metadata has been disabled in the configuration.
    • execute

      public reactor.core.publisher.Mono<ReactiveResultSet> execute(String cql)
      Description copied from interface: ReactiveSession
      Executes the provided query.

      This is a convenience method for execute(new SimpleStatement(query)).

      Specified by:
      execute in interface ReactiveSession
      Parameters:
      cql - the CQL query to execute.
      Returns:
      the result of the query. That result will never be null but can be empty (and will be for any non SELECT query).
    • execute

      public reactor.core.publisher.Mono<ReactiveResultSet> execute(String cql, Object... objects)
      Description copied from interface: ReactiveSession
      Executes the provided query using the provided values.

      This is a convenience method for execute(new SimpleStatement(query, values)).

      Specified by:
      execute in interface ReactiveSession
      Parameters:
      cql - the CQL query to execute.
      objects - values required for the execution of query. See SimpleStatement.newInstance(String, Object...) for more details.
      Returns:
      the result of the query. That result will never be null but can be empty (and will be for any non SELECT query).
    • execute

      public reactor.core.publisher.Mono<ReactiveResultSet> execute(String cql, Map<String,Object> map)
      Description copied from interface: ReactiveSession
      Executes the provided query using the provided named values.

      This is a convenience method for execute(new SimpleStatement(query, values)).

      Specified by:
      execute in interface ReactiveSession
      Parameters:
      cql - the CQL query to execute.
      map - values required for the execution of query. See SimpleStatement.newInstance(String, Map) for more details.
      Returns:
      the result of the query. That result will never be null but can be empty (and will be for any non SELECT query).
    • execute

      public reactor.core.publisher.Mono<ReactiveResultSet> execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement)
      Description copied from interface: ReactiveSession
      Executes the provided query.

      This method blocks until at least some result has been received from the database. However, for SELECT queries, it does not guarantee that the result has been received in full. But it does guarantee that some response has been received from the database, and in particular guarantees that if the request is invalid, an exception will be thrown by this method.

      Specified by:
      execute in interface ReactiveSession
      Parameters:
      statement - the CQL query to execute (that can be any Statement).
      Returns:
      the result of the query. That result will never be null but can be empty (and will be for any non SELECT query).
    • prepare

      public reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement> prepare(String cql)
      Description copied from interface: ReactiveSession
      Prepares the provided query string.
      Specified by:
      prepare in interface ReactiveSession
      Parameters:
      cql - the CQL query string to prepare
      Returns:
      the prepared statement corresponding to query.
    • prepare

      public reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement> prepare(com.datastax.oss.driver.api.core.cql.SimpleStatement statement)
      Description copied from interface: ReactiveSession
      Prepares the provided query.

      This method behaves like ReactiveSession.prepare(String), but note that the resulting PreparedStatement will inherit the query properties set on statement. Concretely, this means that in the following code:

       Statement toPrepare = SimpleStatement.newInstance("SELECT * FROM test WHERE k=?")
                      .setConsistencyLevel(ConsistencyLevel.QUORUM);
       PreparedStatement prepared = session.prepare(toPrepare);
       session.execute(prepared.bind("someValue"));
       
      the final execution will be performed with Quorum consistency.

      Please note that if the same CQL statement is prepared more than once, all calls to this method will return the same PreparedStatement object but the method will still apply the properties of the prepared Statement to this object.

      Specified by:
      prepare in interface ReactiveSession
      Parameters:
      statement - the statement to prepare
      Returns:
      the prepared statement corresponding to statement.
    • close

      public void close()
      Description copied from interface: ReactiveSession
      Initiates a shutdown of this session instance and blocks until that shutdown completes.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface ReactiveSession