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

org.wildfly.swarm.config.infinispan.cache_container.HotrodStore Maven / Gradle / Ivy

package org.wildfly.swarm.config.infinispan.cache_container;

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.Addresses;
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.infinispan.cache_container.PropertyConsumer;
import org.wildfly.swarm.config.infinispan.cache_container.PropertySupplier;
import org.wildfly.swarm.config.infinispan.cache_container.Property;
import org.wildfly.swarm.config.runtime.SubresourceInfo;
import org.wildfly.swarm.config.infinispan.cache_container.ThroughWriteConsumer;
import org.wildfly.swarm.config.infinispan.cache_container.ThroughWriteSupplier;
import org.wildfly.swarm.config.infinispan.cache_container.BehindWriteConsumer;
import org.wildfly.swarm.config.infinispan.cache_container.BehindWriteSupplier;
import org.wildfly.swarm.config.runtime.ModelNodeBinding;
import java.util.Map;

/**
 * HotRod-based store using Infinispan Server instance to store data.
 */
@Addresses({
		"/subsystem=infinispan/cache-container=*/invalidation-cache=*/store=hotrod",
		"/subsystem=infinispan/cache-container=*/local-cache=*/store=hotrod",
		"/subsystem=infinispan/cache-container=*/replicated-cache=*/store=hotrod",
		"/subsystem=infinispan/cache-container=*/distributed-cache=*/store=hotrod",
		"/subsystem=infinispan/cache-container=*/scattered-cache=*/store=hotrod"})
@ResourceType("store")
@Implicit
public class HotrodStore>
		implements
			org.wildfly.swarm.config.runtime.Keyed {

	private String key;
	private PropertyChangeSupport pcs;
	private HotrodStoreResources subresources = new HotrodStoreResources();
	@AttributeDocumentation("Name of the cache configuration template defined in Infinispan Server to create caches from.")
	private String cacheConfiguration;
	@AttributeDocumentation("The number of cache loader node loads.")
	private Long cacheLoaderLoads;
	@AttributeDocumentation("The number of cache loader node misses.")
	private Long cacheLoaderMisses;
	@AttributeDocumentation("If true, fetch persistent state when joining a cluster. If multiple cache stores are chained, only one of them can have this property enabled.")
	private Boolean fetchState;
	@AttributeDocumentation("The maximum size of a batch to be inserted/deleted from the store. If the value is less than one, then no upper limit is placed on the number of operations in a batch.")
	private Integer maxBatchSize;
	@AttributeDocumentation("If true, data is only written to the cache store when it is evicted from memory, a phenomenon known as 'passivation'. Next time the data is requested, it will be 'activated' which means that data will be brought back to memory and removed from the persistent store. If false, the cache store contains a copy of the contents in memory, so writes to cache result in cache store writes. This essentially gives you a 'write-through' configuration.")
	private Boolean passivation;
	@AttributeDocumentation("If true, when the cache starts, data stored in the cache store will be pre-loaded into memory. This is particularly useful when data in the cache store will be needed immediately after startup and you want to avoid cache operations being delayed as a result of loading this data lazily. Can be used to provide a 'warm-cache' on startup, however there is a performance penalty as startup time is affected by this process.")
	private Boolean preload;
	@AttributeDocumentation("A list of cache store properties.")
	private Map properties;
	@AttributeDocumentation("If true, purges this cache store when it starts up.")
	private Boolean purge;
	@AttributeDocumentation("Reference to a container-managed remote-cache-container.")
	private String remoteCacheContainer;
	@AttributeDocumentation("This setting should be set to true when multiple cache instances share the same cache store (e.g., multiple nodes in a cluster using a JDBC-based CacheStore pointing to the same, shared database.) Setting this to true avoids multiple cache instances writing the same modification multiple times. If enabled, only the node where the modification originated will write to the cache store. If disabled, each individual cache reacts to a potential remote update by storing the data to the cache store.")
	private Boolean shared;
	@AttributeDocumentation("If true, the singleton store cache store is enabled. SingletonStore is a delegating cache store used for situations when only one instance in a cluster should interact with the underlying store.")
	private Boolean singleton;

	public HotrodStore() {
		super();
		this.key = "hotrod";
		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 HotrodStoreResources subresources() {
		return this.subresources;
	}

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

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

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

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

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

	/**
	 * Configures a cache store as write-through.
	 */
	@SuppressWarnings("unchecked")
	public T throughWrite(
			org.wildfly.swarm.config.infinispan.cache_container.ThroughWrite value) {
		this.subresources.throughWrite = value;
		return (T) this;
	}

	/**
	 * Configures a cache store as write-through.
	 */
	@SuppressWarnings("unchecked")
	public T throughWrite(ThroughWriteConsumer consumer) {
		ThroughWrite child = new ThroughWrite<>();
		if (consumer != null) {
			consumer.accept(child);
		}
		this.subresources.throughWrite = child;
		return (T) this;
	}

	/**
	 * Configures a cache store as write-through.
	 */
	@SuppressWarnings("unchecked")
	public T throughWrite() {
		ThroughWrite child = new ThroughWrite<>();
		this.subresources.throughWrite = child;
		return (T) this;
	}

	/**
	 * Configures a cache store as write-through.
	 */
	@SuppressWarnings("unchecked")
	public T throughWrite(ThroughWriteSupplier supplier) {
		this.subresources.throughWrite = supplier.get();
		return (T) this;
	}

	/**
	 * Configures a cache store as write-behind instead of write-through.
	 */
	@SuppressWarnings("unchecked")
	public T behindWrite(
			org.wildfly.swarm.config.infinispan.cache_container.BehindWrite value) {
		this.subresources.behindWrite = value;
		return (T) this;
	}

	/**
	 * Configures a cache store as write-behind instead of write-through.
	 */
	@SuppressWarnings("unchecked")
	public T behindWrite(BehindWriteConsumer consumer) {
		BehindWrite child = new BehindWrite<>();
		if (consumer != null) {
			consumer.accept(child);
		}
		this.subresources.behindWrite = child;
		return (T) this;
	}

	/**
	 * Configures a cache store as write-behind instead of write-through.
	 */
	@SuppressWarnings("unchecked")
	public T behindWrite() {
		BehindWrite child = new BehindWrite<>();
		this.subresources.behindWrite = child;
		return (T) this;
	}

	/**
	 * Configures a cache store as write-behind instead of write-through.
	 */
	@SuppressWarnings("unchecked")
	public T behindWrite(BehindWriteSupplier supplier) {
		this.subresources.behindWrite = supplier.get();
		return (T) this;
	}

	/**
	 * Child mutators for HotrodStore
	 */
	public static class HotrodStoreResources {
		/**
		 * A cache store property with name and value.
		 */
		@ResourceDocumentation("A cache store property with name and value.")
		@SubresourceInfo("property")
		private List properties = new java.util.ArrayList<>();
		@SingletonResource
		@ResourceDocumentation("Configures a cache store as write-through.")
		private ThroughWrite throughWrite;
		@SingletonResource
		@ResourceDocumentation("Configures a cache store as write-behind instead of write-through.")
		private BehindWrite behindWrite;

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

		public Property property(java.lang.String key) {
			return this.properties.stream().filter(e -> e.getKey().equals(key))
					.findFirst().orElse(null);
		}
		/**
		 * Configures a cache store as write-through.
		 */
		@Subresource
		public ThroughWrite throughWrite() {
			return this.throughWrite;
		}

		/**
		 * Configures a cache store as write-behind instead of write-through.
		 */
		@Subresource
		public BehindWrite behindWrite() {
			return this.behindWrite;
		}
	}

	/**
	 * Name of the cache configuration template defined in Infinispan Server to
	 * create caches from.
	 */
	@ModelNodeBinding(detypedName = "cache-configuration")
	public String cacheConfiguration() {
		return this.cacheConfiguration;
	}

	/**
	 * Name of the cache configuration template defined in Infinispan Server to
	 * create caches from.
	 */
	@SuppressWarnings("unchecked")
	public T cacheConfiguration(java.lang.String value) {
		Object oldValue = this.cacheConfiguration;
		this.cacheConfiguration = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("cacheConfiguration", oldValue, value);
		return (T) this;
	}

	/**
	 * The number of cache loader node loads.
	 * 
	 * @deprecated Deprecated. Use metric from corresponding runtime cache
	 *             resource.
	 */
	@Deprecated
	@ModelNodeBinding(detypedName = "cache-loader-loads")
	public Long cacheLoaderLoads() {
		return this.cacheLoaderLoads;
	}

	/**
	 * The number of cache loader node loads.
	 * 
	 * @deprecated Deprecated. Use metric from corresponding runtime cache
	 *             resource.
	 */
	@SuppressWarnings("unchecked")
	@Deprecated
	public T cacheLoaderLoads(java.lang.Long value) {
		Object oldValue = this.cacheLoaderLoads;
		this.cacheLoaderLoads = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("cacheLoaderLoads", oldValue, value);
		return (T) this;
	}

	/**
	 * The number of cache loader node misses.
	 * 
	 * @deprecated Deprecated. Use metric from corresponding runtime cache
	 *             resource.
	 */
	@Deprecated
	@ModelNodeBinding(detypedName = "cache-loader-misses")
	public Long cacheLoaderMisses() {
		return this.cacheLoaderMisses;
	}

	/**
	 * The number of cache loader node misses.
	 * 
	 * @deprecated Deprecated. Use metric from corresponding runtime cache
	 *             resource.
	 */
	@SuppressWarnings("unchecked")
	@Deprecated
	public T cacheLoaderMisses(java.lang.Long value) {
		Object oldValue = this.cacheLoaderMisses;
		this.cacheLoaderMisses = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("cacheLoaderMisses", oldValue, value);
		return (T) this;
	}

	/**
	 * If true, fetch persistent state when joining a cluster. If multiple cache
	 * stores are chained, only one of them can have this property enabled.
	 */
	@ModelNodeBinding(detypedName = "fetch-state")
	public Boolean fetchState() {
		return this.fetchState;
	}

	/**
	 * If true, fetch persistent state when joining a cluster. If multiple cache
	 * stores are chained, only one of them can have this property enabled.
	 */
	@SuppressWarnings("unchecked")
	public T fetchState(java.lang.Boolean value) {
		Object oldValue = this.fetchState;
		this.fetchState = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("fetchState", oldValue, value);
		return (T) this;
	}

	/**
	 * The maximum size of a batch to be inserted/deleted from the store. If the
	 * value is less than one, then no upper limit is placed on the number of
	 * operations in a batch.
	 */
	@ModelNodeBinding(detypedName = "max-batch-size")
	public Integer maxBatchSize() {
		return this.maxBatchSize;
	}

	/**
	 * The maximum size of a batch to be inserted/deleted from the store. If the
	 * value is less than one, then no upper limit is placed on the number of
	 * operations in a batch.
	 */
	@SuppressWarnings("unchecked")
	public T maxBatchSize(java.lang.Integer value) {
		Object oldValue = this.maxBatchSize;
		this.maxBatchSize = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("maxBatchSize", oldValue, value);
		return (T) this;
	}

	/**
	 * If true, data is only written to the cache store when it is evicted from
	 * memory, a phenomenon known as 'passivation'. Next time the data is
	 * requested, it will be 'activated' which means that data will be brought
	 * back to memory and removed from the persistent store. If false, the cache
	 * store contains a copy of the contents in memory, so writes to cache
	 * result in cache store writes. This essentially gives you a
	 * 'write-through' configuration.
	 */
	@ModelNodeBinding(detypedName = "passivation")
	public Boolean passivation() {
		return this.passivation;
	}

	/**
	 * If true, data is only written to the cache store when it is evicted from
	 * memory, a phenomenon known as 'passivation'. Next time the data is
	 * requested, it will be 'activated' which means that data will be brought
	 * back to memory and removed from the persistent store. If false, the cache
	 * store contains a copy of the contents in memory, so writes to cache
	 * result in cache store writes. This essentially gives you a
	 * 'write-through' configuration.
	 */
	@SuppressWarnings("unchecked")
	public T passivation(java.lang.Boolean value) {
		Object oldValue = this.passivation;
		this.passivation = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("passivation", oldValue, value);
		return (T) this;
	}

	/**
	 * If true, when the cache starts, data stored in the cache store will be
	 * pre-loaded into memory. This is particularly useful when data in the
	 * cache store will be needed immediately after startup and you want to
	 * avoid cache operations being delayed as a result of loading this data
	 * lazily. Can be used to provide a 'warm-cache' on startup, however there
	 * is a performance penalty as startup time is affected by this process.
	 */
	@ModelNodeBinding(detypedName = "preload")
	public Boolean preload() {
		return this.preload;
	}

	/**
	 * If true, when the cache starts, data stored in the cache store will be
	 * pre-loaded into memory. This is particularly useful when data in the
	 * cache store will be needed immediately after startup and you want to
	 * avoid cache operations being delayed as a result of loading this data
	 * lazily. Can be used to provide a 'warm-cache' on startup, however there
	 * is a performance penalty as startup time is affected by this process.
	 */
	@SuppressWarnings("unchecked")
	public T preload(java.lang.Boolean value) {
		Object oldValue = this.preload;
		this.preload = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("preload", oldValue, value);
		return (T) this;
	}

	/**
	 * A list of cache store properties.
	 */
	@ModelNodeBinding(detypedName = "properties")
	public Map properties() {
		return this.properties;
	}

	/**
	 * A list of cache store properties.
	 */
	@SuppressWarnings("unchecked")
	public T properties(java.util.Map value) {
		Object oldValue = this.properties;
		this.properties = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("properties", oldValue, value);
		return (T) this;
	}

	/**
	 * A list of cache store properties.
	 */
	@SuppressWarnings("unchecked")
	public T property(java.lang.String key, java.lang.Object value) {
		if (this.properties == null) {
			this.properties = new java.util.HashMap<>();
		}
		this.properties.put(key, value);
		return (T) this;
	}

	/**
	 * If true, purges this cache store when it starts up.
	 */
	@ModelNodeBinding(detypedName = "purge")
	public Boolean purge() {
		return this.purge;
	}

	/**
	 * If true, purges this cache store when it starts up.
	 */
	@SuppressWarnings("unchecked")
	public T purge(java.lang.Boolean value) {
		Object oldValue = this.purge;
		this.purge = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("purge", oldValue, value);
		return (T) this;
	}

	/**
	 * Reference to a container-managed remote-cache-container.
	 */
	@ModelNodeBinding(detypedName = "remote-cache-container")
	public String remoteCacheContainer() {
		return this.remoteCacheContainer;
	}

	/**
	 * Reference to a container-managed remote-cache-container.
	 */
	@SuppressWarnings("unchecked")
	public T remoteCacheContainer(java.lang.String value) {
		Object oldValue = this.remoteCacheContainer;
		this.remoteCacheContainer = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("remoteCacheContainer", oldValue, value);
		return (T) this;
	}

	/**
	 * This setting should be set to true when multiple cache instances share
	 * the same cache store (e.g., multiple nodes in a cluster using a
	 * JDBC-based CacheStore pointing to the same, shared database.) Setting
	 * this to true avoids multiple cache instances writing the same
	 * modification multiple times. If enabled, only the node where the
	 * modification originated will write to the cache store. If disabled, each
	 * individual cache reacts to a potential remote update by storing the data
	 * to the cache store.
	 */
	@ModelNodeBinding(detypedName = "shared")
	public Boolean shared() {
		return this.shared;
	}

	/**
	 * This setting should be set to true when multiple cache instances share
	 * the same cache store (e.g., multiple nodes in a cluster using a
	 * JDBC-based CacheStore pointing to the same, shared database.) Setting
	 * this to true avoids multiple cache instances writing the same
	 * modification multiple times. If enabled, only the node where the
	 * modification originated will write to the cache store. If disabled, each
	 * individual cache reacts to a potential remote update by storing the data
	 * to the cache store.
	 */
	@SuppressWarnings("unchecked")
	public T shared(java.lang.Boolean value) {
		Object oldValue = this.shared;
		this.shared = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("shared", oldValue, value);
		return (T) this;
	}

	/**
	 * If true, the singleton store cache store is enabled. SingletonStore is a
	 * delegating cache store used for situations when only one instance in a
	 * cluster should interact with the underlying store.
	 * 
	 * @deprecated Deprecated. Consider using a shared store instead, where
	 *             writes are only performed by primary owners.
	 */
	@Deprecated
	@ModelNodeBinding(detypedName = "singleton")
	public Boolean singleton() {
		return this.singleton;
	}

	/**
	 * If true, the singleton store cache store is enabled. SingletonStore is a
	 * delegating cache store used for situations when only one instance in a
	 * cluster should interact with the underlying store.
	 * 
	 * @deprecated Deprecated. Consider using a shared store instead, where
	 *             writes are only performed by primary owners.
	 */
	@SuppressWarnings("unchecked")
	@Deprecated
	public T singleton(java.lang.Boolean value) {
		Object oldValue = this.singleton;
		this.singleton = value;
		if (this.pcs != null)
			this.pcs.firePropertyChange("singleton", oldValue, value);
		return (T) this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy