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

org.wildfly.swarm.config.modcluster.proxy.DynamicLoadProvider Maven / Gradle / Ivy

package org.wildfly.swarm.config.modcluster.proxy;

import org.wildfly.swarm.config.runtime.AttributeDocumentation;
import org.wildfly.swarm.config.runtime.ResourceDocumentation;
import org.wildfly.swarm.config.runtime.SingletonResource;
import org.wildfly.swarm.config.runtime.Address;
import org.wildfly.swarm.config.runtime.ResourceType;
import org.wildfly.swarm.config.runtime.Implicit;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeListener;
import java.util.List;
import org.wildfly.swarm.config.runtime.Subresource;
import org.wildfly.swarm.config.modcluster.proxy.load_provider.LoadMetricConsumer;
import org.wildfly.swarm.config.modcluster.proxy.load_provider.LoadMetricSupplier;
import org.wildfly.swarm.config.modcluster.proxy.load_provider.LoadMetric;
import org.wildfly.swarm.config.runtime.SubresourceInfo;
import org.wildfly.swarm.config.modcluster.proxy.load_provider.CustomLoadMetricConsumer;
import org.wildfly.swarm.config.modcluster.proxy.load_provider.CustomLoadMetricSupplier;
import org.wildfly.swarm.config.modcluster.proxy.load_provider.CustomLoadMetric;
import org.wildfly.swarm.config.runtime.ModelNodeBinding;

/**
 * Configuration and runtime operations for mod_cluster subsystem.
 */
@Address("/subsystem=modcluster/proxy=*/load-provider=dynamic")
@ResourceType("load-provider")
@Implicit
public class DynamicLoadProvider>
		implements
			org.wildfly.swarm.config.runtime.Keyed {

	private String key;
	private PropertyChangeSupport pcs;
	private DynamicLoadProviderResources subresources = new DynamicLoadProviderResources();
	@AttributeDocumentation("The factor by which a historic load values should degrade in significance.")
	private Double decay;
	@AttributeDocumentation("The number of historic (previous) load values to consider in the load balance factor computation.")
	private Integer history;
	@AttributeDocumentation("Initial load within the range [0..100] with which to prepopulate historical values. Used to gradually drive load to the node. Value of 0 prepopulates with full load and value of -1 disables this behavior.")
	private Integer initialLoad;

	public DynamicLoadProvider() {
		super();
		this.key = "dynamic";
		this.pcs = new PropertyChangeSupport(this);
	}

	public String getKey() {
		return this.key;
	}

	/**
	 * Adds a property change listener
	 */
	public void addPropertyChangeListener(PropertyChangeListener listener) {
		if (null == this.pcs)
			this.pcs = new PropertyChangeSupport(this);
		this.pcs.addPropertyChangeListener(listener);
	}

	/**
	 * Removes a property change listener
	 */
	public void removePropertyChangeListener(
			java.beans.PropertyChangeListener listener) {
		if (this.pcs != null)
			this.pcs.removePropertyChangeListener(listener);
	}

	public DynamicLoadProviderResources subresources() {
		return this.subresources;
	}

	/**
	 * Add all LoadMetric objects to this subresource
	 * 
	 * @return this
	 * @param value
	 *            List of LoadMetric objects.
	 */
	@SuppressWarnings("unchecked")
	public T loadMetrics(java.util.List value) {
		this.subresources.loadMetrics = value;
		return (T) this;
	}

	/**
	 * Add the LoadMetric object to the list of subresources
	 * 
	 * @param value
	 *            The LoadMetric to add
	 * @return this
	 */
	@SuppressWarnings("unchecked")
	public T loadMetric(LoadMetric value) {
		this.subresources.loadMetrics.add(value);
		return (T) this;
	}

	/**
	 * Create and configure a LoadMetric object to the list of subresources
	 * 
	 * @param key
	 *            The key for the LoadMetric resource
	 * @param config
	 *            The LoadMetricConsumer to use
	 * @return this
	 */
	@SuppressWarnings("unchecked")
	public T loadMetric(java.lang.String childKey, LoadMetricConsumer consumer) {
		LoadMetric child = new LoadMetric<>(childKey);
		if (consumer != null) {
			consumer.accept(child);
		}
		loadMetric(child);
		return (T) this;
	}

	/**
	 * Create and configure a LoadMetric object to the list of subresources
	 * 
	 * @param key
	 *            The key for the LoadMetric resource
	 * @return this
	 */
	@SuppressWarnings("unchecked")
	public T loadMetric(java.lang.String childKey) {
		loadMetric(childKey, null);
		return (T) this;
	}

	/**
	 * Install a supplied LoadMetric object to the list of subresources
	 */
	@SuppressWarnings("unchecked")
	public T loadMetric(LoadMetricSupplier supplier) {
		loadMetric(supplier.get());
		return (T) this;
	}

	/**
	 * Add all CustomLoadMetric objects to this subresource
	 * 
	 * @return this
	 * @param value
	 *            List of CustomLoadMetric objects.
	 */
	@SuppressWarnings("unchecked")
	public T customLoadMetrics(java.util.List value) {
		this.subresources.customLoadMetrics = value;
		return (T) this;
	}

	/**
	 * Add the CustomLoadMetric object to the list of subresources
	 * 
	 * @param value
	 *            The CustomLoadMetric to add
	 * @return this
	 */
	@SuppressWarnings("unchecked")
	public T customLoadMetric(CustomLoadMetric value) {
		this.subresources.customLoadMetrics.add(value);
		return (T) this;
	}

	/**
	 * Create and configure a CustomLoadMetric object to the list of
	 * subresources
	 * 
	 * @param key
	 *            The key for the CustomLoadMetric resource
	 * @param config
	 *            The CustomLoadMetricConsumer to use
	 * @return this
	 */
	@SuppressWarnings("unchecked")
	public T customLoadMetric(java.lang.String childKey,
			CustomLoadMetricConsumer consumer) {
		CustomLoadMetric child = new CustomLoadMetric<>(
				childKey);
		if (consumer != null) {
			consumer.accept(child);
		}
		customLoadMetric(child);
		return (T) this;
	}

	/**
	 * Create and configure a CustomLoadMetric object to the list of
	 * subresources
	 * 
	 * @param key
	 *            The key for the CustomLoadMetric resource
	 * @return this
	 */
	@SuppressWarnings("unchecked")
	public T customLoadMetric(java.lang.String childKey) {
		customLoadMetric(childKey, null);
		return (T) this;
	}

	/**
	 * Install a supplied CustomLoadMetric object to the list of subresources
	 */
	@SuppressWarnings("unchecked")
	public T customLoadMetric(CustomLoadMetricSupplier supplier) {
		customLoadMetric(supplier.get());
		return (T) this;
	}

	/**
	 * Child mutators for DynamicLoadProvider
	 */
	public static class DynamicLoadProviderResources {
		/**
		 * Built-in load metric contributing a value to the overall load factor
		 * of a node. The load factors from each metric are aggregated according
		 * to their weights.
		 */
		@ResourceDocumentation("Built-in load metric contributing a value to the overall load factor of a node. The load factors from each metric are aggregated according to their weights.")
		@SubresourceInfo("loadMetric")
		private List loadMetrics = new java.util.ArrayList<>();
		/**
		 * Built-in load metric contributing a value to the overall load factor
		 * of a node. The load factors from each metric are aggregated according
		 * to their weights.
		 */
		@ResourceDocumentation("Built-in load metric contributing a value to the overall load factor of a node. The load factors from each metric are aggregated according to their weights.")
		@SubresourceInfo("customLoadMetric")
		private List customLoadMetrics = new java.util.ArrayList<>();

		/**
		 * Get the list of LoadMetric resources
		 * 
		 * @return the list of resources
		 */
		@Subresource
		public List loadMetrics() {
			return this.loadMetrics;
		}

		public LoadMetric loadMetric(java.lang.String key) {
			return this.loadMetrics.stream()
					.filter(e -> e.getKey().equals(key)).findFirst()
					.orElse(null);
		}
		/**
		 * Get the list of CustomLoadMetric resources
		 * 
		 * @return the list of resources
		 */
		@Subresource
		public List customLoadMetrics() {
			return this.customLoadMetrics;
		}

		public CustomLoadMetric customLoadMetric(java.lang.String key) {
			return this.customLoadMetrics.stream()
					.filter(e -> e.getKey().equals(key)).findFirst()
					.orElse(null);
		}
	}

	/**
	 * The factor by which a historic load values should degrade in
	 * significance.
	 */
	@ModelNodeBinding(detypedName = "decay")
	public Double decay() {
		return this.decay;
	}

	/**
	 * The factor by which a historic load values should degrade in
	 * significance.
	 */
	@SuppressWarnings("unchecked")
	public T decay(java.lang.Double value) {
		Object oldValue = this.decay;
		this.decay = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("decay", oldValue, value);
		return (T) this;
	}

	/**
	 * The number of historic (previous) load values to consider in the load
	 * balance factor computation.
	 */
	@ModelNodeBinding(detypedName = "history")
	public Integer history() {
		return this.history;
	}

	/**
	 * The number of historic (previous) load values to consider in the load
	 * balance factor computation.
	 */
	@SuppressWarnings("unchecked")
	public T history(java.lang.Integer value) {
		Object oldValue = this.history;
		this.history = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("history", oldValue, value);
		return (T) this;
	}

	/**
	 * Initial load within the range [0..100] with which to prepopulate
	 * historical values. Used to gradually drive load to the node. Value of 0
	 * prepopulates with full load and value of -1 disables this behavior.
	 */
	@ModelNodeBinding(detypedName = "initial-load")
	public Integer initialLoad() {
		return this.initialLoad;
	}

	/**
	 * Initial load within the range [0..100] with which to prepopulate
	 * historical values. Used to gradually drive load to the node. Value of 0
	 * prepopulates with full load and value of -1 disables this behavior.
	 */
	@SuppressWarnings("unchecked")
	public T initialLoad(java.lang.Integer value) {
		Object oldValue = this.initialLoad;
		this.initialLoad = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("initialLoad", oldValue, value);
		return (T) this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy