Database Reference
In-Depth Information
For this example, we look at Cassandra's
StorageService
and how it uses MBeans. Here's the
partial definition of the
StorageServiceMBean
class, with some operations omitted for brevity:
public interface StorageServiceMBean
{
public Set<String> getLiveNodes();
public Set<String> getUnreachableNodes();
public void forceTableFlush(String tableName, String... columnFamilies)
throws IOException;
public void removeToken(String token);
//...
}
As you can see by this MBean interface definition, there's no magic going on. This is just a reg-
ular interface defining the set of operations that will be exposed to JMX that the
StorageSer-
vice
implementation must support. This typically means maintaining additional metadata as the
regular operations do their work.
The
StorageService
class implements this interface and must do the work of directly sup-
porting JMX. The consistency manager field has a reference type of
java.util.concur-
rent.ExecutorService
, but the actual implementation is of type
org.apache.cas-
sandra.concurrent.JMXEnabledThreadPoolExecutor
.
private ExecutorService consistencyManager_ =
new
JMXEnabledThreadPoolExecutor
(DatabaseDescriptor.getConsistencyThreads(),
DatabaseDescriptor.getConsistencyThreads(),
StageManager.KEEPALIVE,
TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(),
new NamedThreadFactory("CONSISTENCY-MANAGER"));
The
JMXEnabledThreadPoolExecutor
implements the
JMXEnabledThreadPoolExecutor-
MBean
and, by association,
org.apache.cassandra.concurrent.IExecutorMBean
, so that
all the Cassandra classes that use thread pools can expose the same operations to JMX. It's in
the
JMXEnabledThreadPoolExecutor
that we see how Cassandra becomes JMX-enabled.
The executor pool registers with the platform MBean server in its constructor, as shown here:
public JMXEnabledThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,