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

org.wildfly.swarm.config.undertow.configuration.ReverseProxy Maven / Gradle / Ivy

The newest version!
package org.wildfly.swarm.config.undertow.configuration;

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.undertow.configuration.reverse_proxy.HostConsumer;
import org.wildfly.swarm.config.undertow.configuration.reverse_proxy.HostSupplier;
import org.wildfly.swarm.config.undertow.configuration.reverse_proxy.Host;
import org.wildfly.swarm.config.runtime.SubresourceInfo;
import org.wildfly.swarm.config.runtime.ModelNodeBinding;

/**
 * A reverse proxy handler
 */
@Address("/subsystem=undertow/configuration=handler/reverse-proxy=*")
@ResourceType("reverse-proxy")
public class ReverseProxy>
		implements
			org.wildfly.swarm.config.runtime.Keyed {

	private String key;
	private PropertyChangeSupport pcs;
	private ReverseProxyResources subresources = new ReverseProxyResources();
	@AttributeDocumentation("The number of connections that will be kept alive indefinitely")
	private Integer cachedConnectionsPerThread;
	@AttributeDocumentation("The amount of time a connection can be idle before it will be closed. Connections will not time out once the pool size is down to the configured minimum (as configured by cached-connections-per-thread)")
	private Integer connectionIdleTimeout;
	@AttributeDocumentation("The number of connections that will be maintained to backend servers, per IO thread.")
	private Integer connectionsPerThread;
	@AttributeDocumentation("The maximum time that a proxy request can be active for, before being killed")
	private Integer maxRequestTime;
	@AttributeDocumentation("The number of times to attempt to retry a request if it fails. Note that if a request is not considered idempotent then it will only be retried if the proxy can be sure it was not sent to the backend server).")
	private Integer maxRetries;
	@AttributeDocumentation("Time in seconds to wait before attempting to reconnect to a server that is down")
	private Integer problemServerRetry;
	@AttributeDocumentation("The number of requests that can be queued if the connection pool is full before requests are rejected with a 503")
	private Integer requestQueueSize;
	@AttributeDocumentation("Comma separated list of session cookie names. Generally this will just be JSESSIONID.")
	private String sessionCookieNames;

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

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

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

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

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

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

	/**
	 * Child mutators for ReverseProxy
	 */
	public static class ReverseProxyResources {
		/**
		 * A host that the reverse proxy will forward requests to
		 */
		@ResourceDocumentation("A host that the reverse proxy will forward requests to")
		@SubresourceInfo("host")
		private List hosts = new java.util.ArrayList<>();

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

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

	/**
	 * The number of connections that will be kept alive indefinitely
	 */
	@ModelNodeBinding(detypedName = "cached-connections-per-thread")
	public Integer cachedConnectionsPerThread() {
		return this.cachedConnectionsPerThread;
	}

	/**
	 * The number of connections that will be kept alive indefinitely
	 */
	@SuppressWarnings("unchecked")
	public T cachedConnectionsPerThread(java.lang.Integer value) {
		Object oldValue = this.cachedConnectionsPerThread;
		this.cachedConnectionsPerThread = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("cachedConnectionsPerThread", oldValue,
					value);
		return (T) this;
	}

	/**
	 * The amount of time a connection can be idle before it will be closed.
	 * Connections will not time out once the pool size is down to the
	 * configured minimum (as configured by cached-connections-per-thread)
	 */
	@ModelNodeBinding(detypedName = "connection-idle-timeout")
	public Integer connectionIdleTimeout() {
		return this.connectionIdleTimeout;
	}

	/**
	 * The amount of time a connection can be idle before it will be closed.
	 * Connections will not time out once the pool size is down to the
	 * configured minimum (as configured by cached-connections-per-thread)
	 */
	@SuppressWarnings("unchecked")
	public T connectionIdleTimeout(java.lang.Integer value) {
		Object oldValue = this.connectionIdleTimeout;
		this.connectionIdleTimeout = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("connectionIdleTimeout", oldValue,
					value);
		return (T) this;
	}

	/**
	 * The number of connections that will be maintained to backend servers, per
	 * IO thread.
	 */
	@ModelNodeBinding(detypedName = "connections-per-thread")
	public Integer connectionsPerThread() {
		return this.connectionsPerThread;
	}

	/**
	 * The number of connections that will be maintained to backend servers, per
	 * IO thread.
	 */
	@SuppressWarnings("unchecked")
	public T connectionsPerThread(java.lang.Integer value) {
		Object oldValue = this.connectionsPerThread;
		this.connectionsPerThread = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("connectionsPerThread", oldValue, value);
		return (T) this;
	}

	/**
	 * The maximum time that a proxy request can be active for, before being
	 * killed
	 */
	@ModelNodeBinding(detypedName = "max-request-time")
	public Integer maxRequestTime() {
		return this.maxRequestTime;
	}

	/**
	 * The maximum time that a proxy request can be active for, before being
	 * killed
	 */
	@SuppressWarnings("unchecked")
	public T maxRequestTime(java.lang.Integer value) {
		Object oldValue = this.maxRequestTime;
		this.maxRequestTime = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("maxRequestTime", oldValue, value);
		return (T) this;
	}

	/**
	 * The number of times to attempt to retry a request if it fails. Note that
	 * if a request is not considered idempotent then it will only be retried if
	 * the proxy can be sure it was not sent to the backend server).
	 */
	@ModelNodeBinding(detypedName = "max-retries")
	public Integer maxRetries() {
		return this.maxRetries;
	}

	/**
	 * The number of times to attempt to retry a request if it fails. Note that
	 * if a request is not considered idempotent then it will only be retried if
	 * the proxy can be sure it was not sent to the backend server).
	 */
	@SuppressWarnings("unchecked")
	public T maxRetries(java.lang.Integer value) {
		Object oldValue = this.maxRetries;
		this.maxRetries = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("maxRetries", oldValue, value);
		return (T) this;
	}

	/**
	 * Time in seconds to wait before attempting to reconnect to a server that
	 * is down
	 */
	@ModelNodeBinding(detypedName = "problem-server-retry")
	public Integer problemServerRetry() {
		return this.problemServerRetry;
	}

	/**
	 * Time in seconds to wait before attempting to reconnect to a server that
	 * is down
	 */
	@SuppressWarnings("unchecked")
	public T problemServerRetry(java.lang.Integer value) {
		Object oldValue = this.problemServerRetry;
		this.problemServerRetry = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("problemServerRetry", oldValue, value);
		return (T) this;
	}

	/**
	 * The number of requests that can be queued if the connection pool is full
	 * before requests are rejected with a 503
	 */
	@ModelNodeBinding(detypedName = "request-queue-size")
	public Integer requestQueueSize() {
		return this.requestQueueSize;
	}

	/**
	 * The number of requests that can be queued if the connection pool is full
	 * before requests are rejected with a 503
	 */
	@SuppressWarnings("unchecked")
	public T requestQueueSize(java.lang.Integer value) {
		Object oldValue = this.requestQueueSize;
		this.requestQueueSize = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("requestQueueSize", oldValue, value);
		return (T) this;
	}

	/**
	 * Comma separated list of session cookie names. Generally this will just be
	 * JSESSIONID.
	 */
	@ModelNodeBinding(detypedName = "session-cookie-names")
	public String sessionCookieNames() {
		return this.sessionCookieNames;
	}

	/**
	 * Comma separated list of session cookie names. Generally this will just be
	 * JSESSIONID.
	 */
	@SuppressWarnings("unchecked")
	public T sessionCookieNames(java.lang.String value) {
		Object oldValue = this.sessionCookieNames;
		this.sessionCookieNames = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("sessionCookieNames", oldValue, value);
		return (T) this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy