@ManagedResource(description="provides a throttling Cassandra session") public class ThrottlingCassandraProvider extends Object implements ApplicationEventPublisherAware, CassandraProvider, InitializingBean
Cassandra provider that wraps another Cassandra Provider and supplies a
ThrottlingSession
.
This implementation of the CassandraProvider
interface takes another
Cassandra provider (that is set through the
setCassandraProvider(CassandraProvider)
) method and wraps the
Session
provided by this Cassandra provider in a
ThrottlingSession
. This implementation is useful when a component
expects a Cassandra provider and not a session to be injected.
For convenience, this class is annotated with the ManagedResource
annotation and thus exposes information about its configuration and the
current status of the ThrottlingSession
through JMX.
Please refer to the documentation of ThrottlingSession
for
limitations of the throttling logic.
Constructor and Description |
---|
ThrottlingCassandraProvider() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
Cluster |
getCluster()
Returns a reference to the Cassandra cluster.
|
ListenableFuture<Cluster> |
getClusterFuture()
Returns a future reference to the Cassandra cluster.
|
int |
getMaxConcurrentReadStatements()
Returns the maximum number of read statements that are executed
concurrently.
|
int |
getMaxConcurrentWriteStatements()
Returns the maximum number of write statements that are executed
concurrently.
|
int |
getPendingReadStatements()
Returns the current number of read statements that are waiting for
execution.
|
int |
getPendingWriteStatements()
Returns the current number of write statements that are waiting for
execution.
|
int |
getRunningReadStatements()
Returns the current number of read statements that are running.
|
int |
getRunningWriteStatements()
Returns the current number of write statements that are running.
|
Session |
getSession()
Returns a reference to the Cassandra session.
|
ListenableFuture<Session> |
getSessionFuture()
Returns a future reference to the Cassandra session.
|
boolean |
isInitialized()
Tells whether this provider has been completely initialized.
|
void |
onCassandraProviderInitializedEvent(CassandraProviderInitializedEvent event)
Handles
CassandraProviderInitializedEvent s. |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
void |
setCassandraProvider(CassandraProvider cassandraProvider)
Sets the backing Cassandra provider that provides access to the Apache
Cassandra database.
|
void |
setMaxConcurrentReadStatements(int maxConcurrentReadStatements)
Set the maximum number of read statements that are executed concurrently.
|
void |
setMaxConcurrentWriteStatements(int maxConcurrentWriteStatements)
Set the maximum number of write statements that are executed
concurrently.
|
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
public Cluster getCluster()
CassandraProvider
getCluster
in interface CassandraProvider
CassandraProvider.getClusterFuture()
public ListenableFuture<Cluster> getClusterFuture()
CassandraProvider
getClusterFuture
in interface CassandraProvider
CassandraProvider.getCluster()
.CassandraProvider.getCluster()
@ManagedAttribute(description="maximum number of read statements that are executed concurrently") public int getMaxConcurrentReadStatements()
ThrottlingSession
. The default value is
Integer.MAX_VALUE
, effectively not limiting the number of
concurrent statements. This property is exposed through JMX (read only).setMaxConcurrentReadStatements(int)
@ManagedAttribute(description="maximum number of write statements that are executed concurrently") public int getMaxConcurrentWriteStatements()
ThrottlingSession
. The default value is
Integer.MAX_VALUE
, effectively not limiting the number of
concurrent statements. This property is exposed through JMX (read only).setMaxConcurrentWriteStatements(int)
@ManagedAttribute(description="number of read statements that are currently waiting for execution") public int getPendingReadStatements()
ThrottlingSession.getPendingReadStatementsCount()
. If the session
has not been initialized yet, this method returns zero. This property is
exposed through JMX (read only).@ManagedAttribute(description="number of write statements that are currently waiting for execution") public int getPendingWriteStatements()
ThrottlingSession.getPendingWriteStatementsCount()
. If the
session has not been initialized yet, this method returns zero. This
property is exposed through JMX (read only).@ManagedAttribute(description="number of read statements that are currently being executed") public int getRunningReadStatements()
executeAsync
method has been called but the future returned by that method has not
completed yet. This method delegates to
ThrottlingSession.getRunningReadStatementsCount()
. If the session
has not been initialized yet, this method returns zero. This property is
exposed through JMX (read only).@ManagedAttribute(description="number of write statements that are currently being executed") public int getRunningWriteStatements()
executeAsync
method has been called but the future returned by that method has not
completed yet. This method delegates to
ThrottlingSession.getRunningReadStatementsCount()
. If the session
has not been initialized yet, this method returns zero. This property is
exposed through JMX (read only).public Session getSession()
CassandraProvider
getSession
in interface CassandraProvider
CassandraProvider.getSessionFuture()
public ListenableFuture<Session> getSessionFuture()
CassandraProvider
getSessionFuture
in interface CassandraProvider
CassandraProvider.getSession()
.CassandraProvider.getSession()
public boolean isInitialized()
CassandraProvider
Tells whether this provider has been completely initialized. If
true
, CassandraProvider.getCluster()
and CassandraProvider.getSession()
will
return a result and not throw an exception.
Please note that the provider might be destroyed after calling this
method. In this case, CassandraProvider.getCluster()
and CassandraProvider.getSession()
might throw, even if this method returned true
previously.
isInitialized
in interface CassandraProvider
true
if this provider is ready for operation,
false
otherwise.@EventListener public void onCassandraProviderInitializedEvent(CassandraProviderInitializedEvent event)
CassandraProviderInitializedEvent
s. If such an event is
sent by the backing Cassandra provider (that has been set through
setCassandraProvider(CassandraProvider)
), it is resent,
replacing the source with this provider. This ensures that components
that use this Cassandra provider instead of the original one are notified
correctly.event
- initialization event sent by the original
CassandraProvider
.public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
public void setCassandraProvider(CassandraProvider cassandraProvider)
CassandraProvider
interface are simply forwarded to the original Cassandra provider. The
getSession()
and getSessionFuture()
methods however do
not forward directly, but return a ThrottlingSession
instead.cassandraProvider
- original provider that provides a connection to the Apache
Cassandra database.IllegalStateException
- if this object has already been initialized (
afterPropertiesSet()
has been called).public void setMaxConcurrentReadStatements(int maxConcurrentReadStatements)
ThrottlingSession
. The default value is
Integer.MAX_VALUE
, effectively not limiting the number of
concurrent statements.maxConcurrentReadStatements
- maximum number of read statements that can run concurrently
(must be greater than zero).IllegalArgumentException
- if the specified value is less than one.IllegalStateException
- if this object has already been initialized (
afterPropertiesSet()
has been called).public void setMaxConcurrentWriteStatements(int maxConcurrentWriteStatements)
ThrottlingSession
. The
default value is Integer.MAX_VALUE
, effectively not limiting the
number of concurrent statements.maxConcurrentWriteStatements
- maximum number of write statements that can run concurrently.IllegalArgumentException
- if the specified value is less than one.IllegalStateException
- if this object has already been initialized (
afterPropertiesSet()
has been called).Copyright © 2011–2017 aquenos GmbH. All rights reserved.