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

org.wildfly.swarm.config.logging.AsyncHandler Maven / Gradle / Ivy

package org.wildfly.swarm.config.logging;

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 org.wildfly.swarm.config.runtime.ModelNodeBinding;
import java.util.Map;
import java.util.Arrays;
import org.wildfly.swarm.config.logging.Level;
import org.wildfly.swarm.config.logging.OverflowAction;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Defines a handler which writes to the sub-handlers in an asynchronous thread.
 * Used for handlers which introduce a substantial amount of lag.
 */
@Address("/subsystem=logging/async-handler=*")
@ResourceType("async-handler")
public class AsyncHandler>
		implements
			org.wildfly.swarm.config.runtime.Keyed {

	private String key;
	private PropertyChangeSupport pcs;
	@AttributeDocumentation("If set to true the handler is enabled and functioning as normal, if set to false the handler is ignored when processing log messages.")
	private Boolean enabled;
	@AttributeDocumentation("Defines a simple filter type.")
	private Map filter;
	@AttributeDocumentation("A filter expression value to define a filter. Example for a filter that does not match a pattern: not(match(\"JBAS.*\"))")
	private String filterSpec;
	@AttributeDocumentation("The log level specifying which message levels will be logged by this handler. Message levels lower than this value will be discarded.")
	private Level level;
	@AttributeDocumentation("The name of the handler.")
	private String name;
	@AttributeDocumentation("Specify what action to take when the overflowing.  The valid options are 'block' and 'discard'")
	private OverflowAction overflowAction;
	@AttributeDocumentation("The queue length to use before flushing writing")
	private Integer queueLength;
	@AttributeDocumentation("The Handlers associated with this async handler.")
	private List subhandlers;

	public AsyncHandler(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);
	}

	/**
	 * If set to true the handler is enabled and functioning as normal, if set
	 * to false the handler is ignored when processing log messages.
	 */
	@ModelNodeBinding(detypedName = "enabled")
	public Boolean enabled() {
		return this.enabled;
	}

	/**
	 * If set to true the handler is enabled and functioning as normal, if set
	 * to false the handler is ignored when processing log messages.
	 */
	@SuppressWarnings("unchecked")
	public T enabled(java.lang.Boolean value) {
		Object oldValue = this.enabled;
		this.enabled = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("enabled", oldValue, value);
		return (T) this;
	}

	/**
	 * Defines a simple filter type.
	 * 
	 * @deprecated Use filter-spec.
	 */
	@Deprecated
	@ModelNodeBinding(detypedName = "filter")
	public Map filter() {
		return this.filter;
	}

	/**
	 * Defines a simple filter type.
	 * 
	 * @deprecated Use filter-spec.
	 */
	@SuppressWarnings("unchecked")
	@Deprecated
	public T filter(java.util.Map value) {
		Object oldValue = this.filter;
		this.filter = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("filter", oldValue, value);
		return (T) this;
	}

	/**
	 * Defines a simple filter type.
	 * 
	 * @deprecated Use filter-spec.
	 */
	@SuppressWarnings("unchecked")
	@Deprecated
	public T filter(java.lang.String key, java.lang.Object value) {
		if (this.filter == null) {
			this.filter = new java.util.HashMap<>();
		}
		this.filter.put(key, value);
		return (T) this;
	}

	/**
	 * A filter expression value to define a filter. Example for a filter that
	 * does not match a pattern: not(match("JBAS.*"))
	 */
	@ModelNodeBinding(detypedName = "filter-spec")
	public String filterSpec() {
		return this.filterSpec;
	}

	/**
	 * A filter expression value to define a filter. Example for a filter that
	 * does not match a pattern: not(match("JBAS.*"))
	 */
	@SuppressWarnings("unchecked")
	public T filterSpec(java.lang.String value) {
		Object oldValue = this.filterSpec;
		this.filterSpec = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("filterSpec", oldValue, value);
		return (T) this;
	}

	/**
	 * The log level specifying which message levels will be logged by this
	 * handler. Message levels lower than this value will be discarded.
	 */
	@ModelNodeBinding(detypedName = "level")
	public Level level() {
		return this.level;
	}

	/**
	 * The log level specifying which message levels will be logged by this
	 * handler. Message levels lower than this value will be discarded.
	 */
	@SuppressWarnings("unchecked")
	public T level(Level value) {
		Object oldValue = this.level;
		this.level = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("level", oldValue, value);
		return (T) this;
	}

	/**
	 * The name of the handler.
	 * 
	 * @deprecated The name attribute should not be used as the handler's
	 *             address contains the name.
	 */
	@Deprecated
	@ModelNodeBinding(detypedName = "name")
	public String name() {
		return this.name;
	}

	/**
	 * The name of the handler.
	 * 
	 * @deprecated The name attribute should not be used as the handler's
	 *             address contains the name.
	 */
	@SuppressWarnings("unchecked")
	@Deprecated
	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;
	}

	/**
	 * Specify what action to take when the overflowing. The valid options are
	 * 'block' and 'discard'
	 */
	@ModelNodeBinding(detypedName = "overflow-action")
	public OverflowAction overflowAction() {
		return this.overflowAction;
	}

	/**
	 * Specify what action to take when the overflowing. The valid options are
	 * 'block' and 'discard'
	 */
	@SuppressWarnings("unchecked")
	public T overflowAction(OverflowAction value) {
		Object oldValue = this.overflowAction;
		this.overflowAction = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("overflowAction", oldValue, value);
		return (T) this;
	}

	/**
	 * The queue length to use before flushing writing
	 */
	@ModelNodeBinding(detypedName = "queue-length")
	public Integer queueLength() {
		return this.queueLength;
	}

	/**
	 * The queue length to use before flushing writing
	 */
	@SuppressWarnings("unchecked")
	public T queueLength(java.lang.Integer value) {
		Object oldValue = this.queueLength;
		this.queueLength = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("queueLength", oldValue, value);
		return (T) this;
	}

	/**
	 * The Handlers associated with this async handler.
	 */
	@ModelNodeBinding(detypedName = "subhandlers")
	public List subhandlers() {
		return this.subhandlers;
	}

	/**
	 * The Handlers associated with this async handler.
	 */
	@SuppressWarnings("unchecked")
	public T subhandlers(java.util.List value) {
		Object oldValue = this.subhandlers;
		this.subhandlers = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("subhandlers", oldValue, value);
		return (T) this;
	}

	/**
	 * The Handlers associated with this async handler.
	 */
	@SuppressWarnings("unchecked")
	public T subhandler(String value) {
		if (this.subhandlers == null) {
			this.subhandlers = new java.util.ArrayList<>();
		}
		this.subhandlers.add(value);
		return (T) this;
	}

	/**
	 * The Handlers associated with this async handler.
	 */
	@SuppressWarnings("unchecked")
	public T subhandlers(String... args) {
		subhandlers(Arrays.stream(args).collect(Collectors.toList()));
		return (T) this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy