From 0412e3e2e678ba2c862af154a3c668f08056a780 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 8 Dec 2011 18:08:30 +0200 Subject: [PATCH] create NodeEnvironment outside of guice so if it fails, it fails early and does not takes ages with guice trying to create it per injection --- .../org/elasticsearch/env/NodeEnvironment.java | 4 ++-- .../elasticsearch/env/NodeEnvironmentModule.java | 14 +++++++++++++- .../elasticsearch/node/internal/InternalNode.java | 4 +++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 37ae247c372..eaee48520ec 100644 --- a/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -48,7 +48,7 @@ public class NodeEnvironment extends AbstractComponent { private final int localNodeId; @Inject - public NodeEnvironment(Settings settings, Environment environment) throws IOException { + public NodeEnvironment(Settings settings, Environment environment) { super(settings); if (!DiscoveryNode.nodeRequiresLocalStorage(settings)) { @@ -117,7 +117,7 @@ public class NodeEnvironment extends AbstractComponent { } } if (locks[0] == null) { - throw new IOException("Failed to obtain node lock on " + Arrays.toString(environment.dataWithClusterFiles()), lastException); + throw new ElasticSearchIllegalStateException("Failed to obtain node lock, is the following location writable?: " + Arrays.toString(environment.dataWithClusterFiles()), lastException); } this.localNodeId = localNodeId; diff --git a/src/main/java/org/elasticsearch/env/NodeEnvironmentModule.java b/src/main/java/org/elasticsearch/env/NodeEnvironmentModule.java index c86d9367e82..d9fe10b5651 100644 --- a/src/main/java/org/elasticsearch/env/NodeEnvironmentModule.java +++ b/src/main/java/org/elasticsearch/env/NodeEnvironmentModule.java @@ -19,6 +19,7 @@ package org.elasticsearch.env; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.AbstractModule; /** @@ -26,11 +27,22 @@ import org.elasticsearch.common.inject.AbstractModule; */ public class NodeEnvironmentModule extends AbstractModule { + private final NodeEnvironment nodeEnvironment; + public NodeEnvironmentModule() { + this(null); + } + + public NodeEnvironmentModule(@Nullable NodeEnvironment nodeEnvironment) { + this.nodeEnvironment = nodeEnvironment; } @Override protected void configure() { - bind(NodeEnvironment.class).asEagerSingleton(); + if (nodeEnvironment != null) { + bind(NodeEnvironment.class).toInstance(nodeEnvironment); + } else { + bind(NodeEnvironment.class).asEagerSingleton(); + } } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/node/internal/InternalNode.java b/src/main/java/org/elasticsearch/node/internal/InternalNode.java index 47405382e54..0dd25a4e27f 100644 --- a/src/main/java/org/elasticsearch/node/internal/InternalNode.java +++ b/src/main/java/org/elasticsearch/node/internal/InternalNode.java @@ -117,6 +117,8 @@ public final class InternalNode implements Node { this.settings = pluginsService.updatedSettings(); this.environment = tuple.v2(); + NodeEnvironment nodeEnvironment = new NodeEnvironment(this.settings, this.environment); + ModulesBuilder modules = new ModulesBuilder(); modules.add(new PluginsModule(settings, pluginsService)); modules.add(new SettingsModule(settings)); @@ -126,7 +128,7 @@ public final class InternalNode implements Node { modules.add(new ScriptModule(settings)); modules.add(new JmxModule(settings)); modules.add(new EnvironmentModule(environment)); - modules.add(new NodeEnvironmentModule()); + modules.add(new NodeEnvironmentModule(nodeEnvironment)); modules.add(new ClusterNameModule(settings)); modules.add(new ThreadPoolModule(settings)); modules.add(new DiscoveryModule(settings));