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

org.wildfly.swarm.config.jca.DistributedWorkmanager Maven / Gradle / Ivy

The newest version!
package org.wildfly.swarm.config.jca;

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 java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeListener;
import java.util.List;
import org.wildfly.swarm.config.runtime.Subresource;
import org.wildfly.swarm.config.jca.LongRunningThreadsConsumer;
import org.wildfly.swarm.config.jca.LongRunningThreadsSupplier;
import org.wildfly.swarm.config.jca.LongRunningThreads;
import org.wildfly.swarm.config.runtime.SubresourceInfo;
import org.wildfly.swarm.config.jca.ShortRunningThreadsConsumer;
import org.wildfly.swarm.config.jca.ShortRunningThreadsSupplier;
import org.wildfly.swarm.config.jca.ShortRunningThreads;
import org.wildfly.swarm.config.runtime.ModelNodeBinding;
import java.util.Arrays;
import java.util.Map;

/**
 * DistributedWorkManager for resource adapters
 */
@Address("/subsystem=jca/distributed-workmanager=*")
@ResourceType("distributed-workmanager")
public class DistributedWorkmanager>
		implements
			org.wildfly.swarm.config.runtime.Keyed {

	private String key;
	private PropertyChangeSupport pcs;
	private DistributedWorkmanagerResources subresources = new DistributedWorkmanagerResources();
	@AttributeDocumentation("Enables Elytron security for this workmanager.")
	private Boolean elytronEnabled;
	@AttributeDocumentation("The name of the DistributedWorkManager")
	private String name;
	@AttributeDocumentation("The policy decides when to redistribute a Work instance")
	private Policy policy;
	@AttributeDocumentation("List of policy's options key/value pairs")
	private Map policyOptions;
	@AttributeDocumentation("The selector decides to which nodes in the network to redistribute the Work instance to")
	private Selector selector;
	@AttributeDocumentation("List of selector's options key/value pairs")
	private Map selectorOptions;

	public DistributedWorkmanager(java.lang.String key) {
		super();
		this.key = key;
	}

	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 DistributedWorkmanagerResources subresources() {
		return this.subresources;
	}

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

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

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

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

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

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

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

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

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

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

	/**
	 * Child mutators for DistributedWorkmanager
	 */
	public static class DistributedWorkmanagerResources {
		/**
		 * A thread pool executor with a bounded queue where threads submittings
		 * tasks will not block. Such a thread pool has a core and maximum size
		 * and a specified queue length. When a task is submitted, if the number
		 * of running threads is less than the core size, a new thread is
		 * created. Otherwise, if there is room in the queue, the task is
		 * enqueued. Otherwise, if the number of running threads is less than
		 * the maximum size, a new thread is created. Otherwise, the task is
		 * handed off to the designated handoff executor, if one is specified.
		 * Otherwise, the task is discarded.
		 */
		@ResourceDocumentation("A thread pool executor with a bounded queue where threads submittings tasks will not block. Such a thread pool has a core and maximum size and a specified queue length.  When a task is submitted, if the number of running threads is less than the core size, a new thread is created.  Otherwise, if there is room in the queue, the task is enqueued. Otherwise, if the number of running threads is less than the maximum size, a new thread is created. Otherwise, the task is handed off to the designated handoff executor, if one is specified.  Otherwise, the task is discarded.")
		@SubresourceInfo("longRunningThreads")
		private List longRunningThreads = new java.util.ArrayList<>();
		/**
		 * A thread pool executor with a bounded queue where threads submittings
		 * tasks will not block. Such a thread pool has a core and maximum size
		 * and a specified queue length. When a task is submitted, if the number
		 * of running threads is less than the core size, a new thread is
		 * created. Otherwise, if there is room in the queue, the task is
		 * enqueued. Otherwise, if the number of running threads is less than
		 * the maximum size, a new thread is created. Otherwise, the task is
		 * handed off to the designated handoff executor, if one is specified.
		 * Otherwise, the task is discarded.
		 */
		@ResourceDocumentation("A thread pool executor with a bounded queue where threads submittings tasks will not block. Such a thread pool has a core and maximum size and a specified queue length.  When a task is submitted, if the number of running threads is less than the core size, a new thread is created.  Otherwise, if there is room in the queue, the task is enqueued. Otherwise, if the number of running threads is less than the maximum size, a new thread is created. Otherwise, the task is handed off to the designated handoff executor, if one is specified.  Otherwise, the task is discarded.")
		@SubresourceInfo("shortRunningThreads")
		private List shortRunningThreads = new java.util.ArrayList<>();

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

		public LongRunningThreads longRunningThreads(java.lang.String key) {
			return this.longRunningThreads.stream()
					.filter(e -> e.getKey().equals(key)).findFirst()
					.orElse(null);
		}
		/**
		 * Get the list of ShortRunningThreads resources
		 * 
		 * @return the list of resources
		 */
		@Subresource
		public List shortRunningThreads() {
			return this.shortRunningThreads;
		}

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

	public static enum Policy {
		NEVER("NEVER"), ALWAYS("ALWAYS"), WATERMARK("WATERMARK");
		private final String allowedValue;

		/**
		 * Returns the allowed value for the management model.
		 * 
		 * @return the allowed model value
		 */
		public String getAllowedValue() {
			return allowedValue;
		}

		Policy(java.lang.String allowedValue) {
			this.allowedValue = allowedValue;
		}

		@Override
		public String toString() {
			return allowedValue;
		}
	}

	public static enum Selector {
		FIRST_AVAILABLE("FIRST_AVAILABLE"), PING_TIME("PING_TIME"), MAX_FREE_THREADS(
				"MAX_FREE_THREADS");
		private final String allowedValue;

		/**
		 * Returns the allowed value for the management model.
		 * 
		 * @return the allowed model value
		 */
		public String getAllowedValue() {
			return allowedValue;
		}

		Selector(java.lang.String allowedValue) {
			this.allowedValue = allowedValue;
		}

		@Override
		public String toString() {
			return allowedValue;
		}
	}

	/**
	 * Enables Elytron security for this workmanager.
	 */
	@ModelNodeBinding(detypedName = "elytron-enabled")
	public Boolean elytronEnabled() {
		return this.elytronEnabled;
	}

	/**
	 * Enables Elytron security for this workmanager.
	 */
	@SuppressWarnings("unchecked")
	public T elytronEnabled(java.lang.Boolean value) {
		Object oldValue = this.elytronEnabled;
		this.elytronEnabled = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("elytronEnabled", oldValue, value);
		return (T) this;
	}

	/**
	 * The name of the DistributedWorkManager
	 */
	@ModelNodeBinding(detypedName = "name")
	public String name() {
		return this.name;
	}

	/**
	 * The name of the DistributedWorkManager
	 */
	@SuppressWarnings("unchecked")
	public T name(java.lang.String value) {
		Object oldValue = this.name;
		this.name = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("name", oldValue, value);
		return (T) this;
	}

	/**
	 * The policy decides when to redistribute a Work instance
	 */
	@ModelNodeBinding(detypedName = "policy")
	public Policy policy() {
		return this.policy;
	}

	/**
	 * The policy decides when to redistribute a Work instance
	 */
	@SuppressWarnings("unchecked")
	public T policy(Policy value) {
		Object oldValue = this.policy;
		this.policy = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("policy", oldValue, value);
		return (T) this;
	}

	/**
	 * List of policy's options key/value pairs
	 */
	@ModelNodeBinding(detypedName = "policy-options")
	public Map policyOptions() {
		return this.policyOptions;
	}

	/**
	 * List of policy's options key/value pairs
	 */
	@SuppressWarnings("unchecked")
	public T policyOptions(java.util.Map value) {
		Object oldValue = this.policyOptions;
		this.policyOptions = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("policyOptions", oldValue, value);
		return (T) this;
	}

	/**
	 * List of policy's options key/value pairs
	 */
	@SuppressWarnings("unchecked")
	public T policyOption(java.lang.String key, java.lang.Object value) {
		if (this.policyOptions == null) {
			this.policyOptions = new java.util.HashMap<>();
		}
		this.policyOptions.put(key, value);
		return (T) this;
	}

	/**
	 * The selector decides to which nodes in the network to redistribute the
	 * Work instance to
	 */
	@ModelNodeBinding(detypedName = "selector")
	public Selector selector() {
		return this.selector;
	}

	/**
	 * The selector decides to which nodes in the network to redistribute the
	 * Work instance to
	 */
	@SuppressWarnings("unchecked")
	public T selector(Selector value) {
		Object oldValue = this.selector;
		this.selector = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("selector", oldValue, value);
		return (T) this;
	}

	/**
	 * List of selector's options key/value pairs
	 */
	@ModelNodeBinding(detypedName = "selector-options")
	public Map selectorOptions() {
		return this.selectorOptions;
	}

	/**
	 * List of selector's options key/value pairs
	 */
	@SuppressWarnings("unchecked")
	public T selectorOptions(java.util.Map value) {
		Object oldValue = this.selectorOptions;
		this.selectorOptions = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("selectorOptions", oldValue, value);
		return (T) this;
	}

	/**
	 * List of selector's options key/value pairs
	 */
	@SuppressWarnings("unchecked")
	public T selectorOption(java.lang.String key, java.lang.Object value) {
		if (this.selectorOptions == null) {
			this.selectorOptions = new java.util.HashMap<>();
		}
		this.selectorOptions.put(key, value);
		return (T) this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy