All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.node.NodeBuilder Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to Elasticsearch 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.node;

import org.elasticsearch.common.settings.Settings;

/**
 * A node builder is used to construct a {@link Node} instance.
 * 

* Settings will be loaded relative to the ES home (with or without config/ prefix) and if not found, * within the classpath (with or without config/ prefix). The settings file loaded can either be named * elasticsearch.yml or elasticsearch.json). *

* Explicit settings can be passed by using the {@link #settings(org.elasticsearch.common.settings.Settings)} method. *

* In any case, settings will be resolved from system properties as well that are either prefixed with es. * or elasticsearch.. *

* An example for creating a simple node with optional settings loaded from the classpath: *

 * Node node = NodeBuilder.nodeBuilder().node();
 * 
*

* An example for creating a node with explicit settings (in this case, a node in the cluster that does not hold * data): *

 * Node node = NodeBuilder.nodeBuilder()
 *                      .settings(Settings.settingsBuilder().put("node.data", false)
 *                      .node();
 * 
*

* When done with the node, make sure you call {@link Node#close()} on it. * * */ public class NodeBuilder { private final Settings.Builder settings = Settings.settingsBuilder(); /** * A convenient factory method to create a {@link NodeBuilder}. */ public static NodeBuilder nodeBuilder() { return new NodeBuilder(); } /** * Set addition settings simply by working directly against the settings builder. */ public Settings.Builder settings() { return settings; } /** * Set addition settings simply by working directly against the settings builder. */ public Settings.Builder getSettings() { return settings; } /** * Explicit node settings to set. */ public NodeBuilder settings(Settings.Builder settings) { return settings(settings.build()); } /** * Explicit node settings to set. */ public NodeBuilder settings(Settings settings) { this.settings.put(settings); return this; } /** * Is the node going to be a client node which means it will hold no data (node.data is * set to false) and other optimizations by different modules. * * @param client Should the node be just a client node or not. */ public NodeBuilder client(boolean client) { settings.put("node.client", client); return this; } /** * Is the node going to be allowed to allocate data (shards) to it or not. This setting map to * the node.data setting. Note, when setting {@link #client(boolean)}, the node will * not hold any data by default. * * @param data Should the node be allocated data to or not. */ public NodeBuilder data(boolean data) { settings.put("node.data", data); return this; } /** * Is the node a local node. A local node is a node that uses a local (JVM level) discovery and * transport. Other (local) nodes started within the same JVM (actually, class-loader) will be * discovered and communicated with. Nodes outside of the JVM will not be discovered. * * @param local Should the node be local or not */ public NodeBuilder local(boolean local) { settings.put("node.local", local); return this; } /** * The cluster name this node is part of (maps to the cluster.name setting). Defaults * to elasticsearch. * * @param clusterName The cluster name this node is part of. */ public NodeBuilder clusterName(String clusterName) { settings.put("cluster.name", clusterName); return this; } /** * Builds the node without starting it. */ public Node build() { return new Node(settings.build()); } /** * {@link #build()}s and starts the node. */ public Node node() { return build().start(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy