Jmx: Only register JMX beans when jmx.create_connector is set to `true`, or explicitly set by setting `jmx.export` to true, closes #1666.

This commit is contained in:
Shay Banon 2012-02-05 18:52:56 +02:00
parent 80607dd7c3
commit 44a6040293
11 changed files with 105 additions and 10 deletions

View File

@ -20,17 +20,27 @@
package org.elasticsearch.index;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.index.service.InternalIndexService;
import org.elasticsearch.jmx.JmxService;
/**
*
*/
public class IndexModule extends AbstractModule {
private final Settings settings;
public IndexModule(Settings settings) {
this.settings = settings;
}
@Override
protected void configure() {
bind(IndexService.class).to(InternalIndexService.class).asEagerSingleton();
bind(IndexServiceManagement.class).asEagerSingleton();
if (JmxService.shouldExport(settings)) {
bind(IndexServiceManagement.class).asEagerSingleton();
}
}
}

View File

@ -295,7 +295,7 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde
ModulesBuilder modules = new ModulesBuilder();
modules.add(new ShardsPluginsModule(indexSettings, pluginsService));
modules.add(new IndexShardModule(shardId));
modules.add(new IndexShardModule(indexSettings, shardId));
modules.add(new ShardIndexingModule());
modules.add(new ShardSearchModule());
modules.add(new ShardGetModule());

View File

@ -20,17 +20,22 @@
package org.elasticsearch.index.shard;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.shard.service.IndexShard;
import org.elasticsearch.index.shard.service.InternalIndexShard;
import org.elasticsearch.jmx.JmxService;
/**
*
*/
public class IndexShardModule extends AbstractModule {
private final Settings settings;
private final ShardId shardId;
public IndexShardModule(ShardId shardId) {
public IndexShardModule(Settings settings, ShardId shardId) {
this.settings = settings;
this.shardId = shardId;
}
@ -38,6 +43,8 @@ public class IndexShardModule extends AbstractModule {
protected void configure() {
bind(ShardId.class).toInstance(shardId);
bind(IndexShard.class).to(InternalIndexShard.class).asEagerSingleton();
bind(IndexShardManagement.class).asEagerSingleton();
if (JmxService.shouldExport(settings)) {
bind(IndexShardManagement.class).asEagerSingleton();
}
}
}

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.store;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.jmx.JmxService;
/**
*
@ -39,7 +40,9 @@ public class StoreModule extends AbstractModule {
@Override
protected void configure() {
bind(DirectoryService.class).to(indexStore.shardDirectory()).asEagerSingleton();
bind(StoreManagement.class).asEagerSingleton();
bind(Store.class).asEagerSingleton();
if (JmxService.shouldExport(settings)) {
bind(StoreManagement.class).asEagerSingleton();
}
}
}

View File

@ -279,7 +279,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
modules.add(new MapperServiceModule());
modules.add(new IndexAliasesServiceModule());
modules.add(new IndexGatewayModule(indexSettings, injector.getInstance(Gateway.class)));
modules.add(new IndexModule());
modules.add(new IndexModule(indexSettings));
modules.add(new PercolatorModule());
Injector indexInjector;

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.jmx;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings;
/**
* Simple based class for JMX related services with {@link #doConfigure()} only being called if
* jmx is enabled.
*/
public abstract class AbstractJmxModule extends AbstractModule {
private final Settings settings;
protected AbstractJmxModule(Settings settings) {
this.settings = settings;
}
@Override
protected void configure() {
if (JmxService.shouldExport(settings)) {
doConfigure();
}
}
protected abstract void doConfigure();
}

View File

@ -45,7 +45,9 @@ public class JmxModule extends AbstractModule {
JmxService jmxService = new JmxService(Loggers.getLogger(JmxService.class, settings.get("name")), settings);
bind(JmxService.class).toInstance(jmxService);
bind(GetJmxServiceUrlAction.class).asEagerSingleton();
bindListener(Matchers.any(), new JmxExporterTypeListener(jmxService));
if (JmxService.shouldExport(settings)) {
bindListener(Matchers.any(), new JmxExporterTypeListener(jmxService));
}
}
private static class JmxExporterTypeListener implements TypeListener {

View File

@ -43,9 +43,14 @@ public class JmxService {
public static class SettingsConstants {
public static final String EXPORT = "jmx.export";
public static final String CREATE_CONNECTOR = "jmx.create_connector";
}
public static boolean shouldExport(Settings settings) {
return settings.getAsBoolean(SettingsConstants.CREATE_CONNECTOR, false) || settings.getAsBoolean(SettingsConstants.EXPORT, false);
}
// we use {jmx.port} without prefix of $ since we don't want it to be resolved as a setting property
public static final String JMXRMI_URI_PATTERN = "service:jmx:rmi:///jndi/rmi://:{jmx.port}/jmxrmi";

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.Modules;
import org.elasticsearch.common.inject.SpawnModules;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.jmx.JmxService;
import org.elasticsearch.transport.local.LocalTransportModule;
import org.elasticsearch.transport.netty.NettyTransportModule;
@ -53,6 +54,8 @@ public class TransportModule extends AbstractModule implements SpawnModules {
@Override
protected void configure() {
bind(TransportService.class).asEagerSingleton();
bind(TransportServiceManagement.class).asEagerSingleton();
if (JmxService.shouldExport(settings)) {
bind(TransportServiceManagement.class).asEagerSingleton();
}
}
}

View File

@ -20,6 +20,8 @@
package org.elasticsearch.transport.local;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.jmx.JmxService;
import org.elasticsearch.transport.Transport;
/**
@ -27,10 +29,18 @@ import org.elasticsearch.transport.Transport;
*/
public class LocalTransportModule extends AbstractModule {
private final Settings settings;
public LocalTransportModule(Settings settings) {
this.settings = settings;
}
@Override
protected void configure() {
bind(LocalTransport.class).asEagerSingleton();
bind(Transport.class).to(LocalTransport.class).asEagerSingleton();
bind(LocalTransportManagement.class).asEagerSingleton();
if (JmxService.shouldExport(settings)) {
bind(LocalTransportManagement.class).asEagerSingleton();
}
}
}

View File

@ -20,6 +20,8 @@
package org.elasticsearch.transport.netty;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.jmx.JmxService;
import org.elasticsearch.transport.Transport;
/**
@ -27,10 +29,18 @@ import org.elasticsearch.transport.Transport;
*/
public class NettyTransportModule extends AbstractModule {
private final Settings settings;
public NettyTransportModule(Settings settings) {
this.settings = settings;
}
@Override
protected void configure() {
bind(NettyTransport.class).asEagerSingleton();
bind(Transport.class).to(NettyTransport.class).asEagerSingleton();
bind(NettyTransportManagement.class).asEagerSingleton();
if (JmxService.shouldExport(settings)) {
bind(NettyTransportManagement.class).asEagerSingleton();
}
}
}