Class ObservableReactiveSession
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ReactiveSession
ReactiveSession
for observability.- Since:
- 4.0
- Author:
- Mark Paluch, Marcin Grzejszczak
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Initiates a shutdown of this session instance and blocks until that shutdown completes.static ReactiveSession
create
(ReactiveSession session, io.micrometer.observation.ObservationRegistry observationRegistry) Factory method for creation of aObservableReactiveSession
.static ReactiveSession
create
(ReactiveSession session, String remoteServiceName, io.micrometer.observation.ObservationRegistry observationRegistry) Factory method for creation of aObservableReactiveSession
.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>
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, orOptional.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
isClosed()
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.
-
Method Details
-
create
public static ReactiveSession create(ReactiveSession session, io.micrometer.observation.ObservationRegistry observationRegistry) Factory method for creation of aObservableReactiveSession
.- 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 aObservableReactiveSession
.- 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 oncloseAsync()
with a very short timeout and check this doesn't timeout).- Specified by:
isClosed
in interfaceReactiveSession
- 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 interfaceReactiveSession
- Returns:
- a context that provides access to all the policies used by this driver instance.
-
getKeyspace
Description copied from interface:ReactiveSession
The keyspace that this session is currently connected to, orOptional.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 withSessionBuilder.withKeyspace(CqlIdentifier)
); or at runtime, if the client issues a request that changes the keyspace (such as a CQLUSE
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 interfaceReactiveSession
-
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 particularNode.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 interfaceReactiveSession
- Returns:
- never
null
, but may be empty if metadata has been disabled in the configuration.
-
execute
Description copied from interface:ReactiveSession
Executes the provided query.This is a convenience method for
execute(new SimpleStatement(query))
.- Specified by:
execute
in interfaceReactiveSession
- 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
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 interfaceReactiveSession
- Parameters:
cql
- the CQL query to execute.objects
- values required for the execution ofquery
. SeeSimpleStatement.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
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 interfaceReactiveSession
- Parameters:
cql
- the CQL query to execute.map
- values required for the execution ofquery
. SeeSimpleStatement.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 interfaceReactiveSession
- Parameters:
statement
- the CQL query to execute (that can be anyStatement
).- 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 interfaceReactiveSession
- 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 resultingPreparedStatement
will inherit the query properties set onstatement
. 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 preparedStatement
to this object.- Specified by:
prepare
in interfaceReactiveSession
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceReactiveSession
-