org.terracotta.toolkit.builder
Class ToolkitCacheConfigBuilder

java.lang.Object
  extended by org.terracotta.toolkit.builder.ToolkitCacheConfigBuilder

public final class ToolkitCacheConfigBuilder
extends Object

A helper to build a Configuration for ToolkitCache. Builds up configuration based on ToolkitConfigFields


Constructor Summary
ToolkitCacheConfigBuilder()
           
 
Method Summary
protected  void addFieldToApply(String name, Serializable value)
           
 void apply(ToolkitCache cache)
          Applies the current changes from the builder to the ToolkitCache.
 void apply(ToolkitStore store)
          Apply changes of this builder to the ToolkitStore parameter.
 Configuration build()
          Builds a Configuration for ToolkitCache by filling in appropriate mappings.
 ToolkitCacheConfigBuilder compressionEnabled(boolean compressionEnabledParam)
          Sets compression enabled
 ToolkitCacheConfigBuilder concurrency(int concurrencyParam)
          Sets the concurrency config to the new value and returns this
 ToolkitCacheConfigBuilder configField(String fieldName, Serializable value)
           
 ToolkitCacheConfigBuilder consistency(ToolkitConfigFields.Consistency consistencyParam)
          Sets the ToolkitConfigFields.Consistency of the key-value store
 ToolkitCacheConfigBuilder copyOnReadEnabled(boolean copyOnReadEnabledParam)
          Sets copy on read enabled
 ToolkitCacheConfigBuilder evictionEnabled(boolean evictionEnabledParam)
          Sets eviction enabled/disabled
 int getConcurrency()
          Concurrency of the store
 ToolkitConfigFields.Consistency getConsistency()
          Getter for consistency
 long getMaxBytesLocalHeap()
          Gets the max bytes local heap
 long getMaxBytesLocalOffheap()
          Gets the max bytes local offheap
 long getMaxCountLocalHeap()
          Gets the max count local heap
 int getMaxTotalCount()
          Returns max total count
 int getMaxTTISeconds()
          Max TTI in seconds for the map.
 int getMaxTTLSeconds()
          Max TTL in seconds for the map.
 boolean isCompressionEnabled()
          Compression enabled or not getter
 boolean isCopyOnReadEnabled()
          copy-on-read enabled or not getter
 boolean isEvictionEnabled()
          Returns eviction enabled
 boolean isLocalCacheEnabled()
          Query whether local cache is enabled or not
 boolean isOffheapEnabled()
          Returns true if offheap is enabled
 boolean isPinnedInLocalMemory()
           
 ToolkitCacheConfigBuilder localCacheEnabled(boolean localCacheEnabledParam)
          Sets local cache enabled
 ToolkitCacheConfigBuilder maxBytesLocalHeap(long maxBytesLocalHeapParam)
          Sets the maxBytesLocalHeap
 ToolkitCacheConfigBuilder maxBytesLocalOffheap(long maxBytesLocalOffheapParam)
          Sets the max bytes local offheap
 ToolkitCacheConfigBuilder maxCountLocalHeap(int maxCountLocalHeapParam)
          Sets the max count local heap
 ToolkitCacheConfigBuilder maxTotalCount(int maxTotalCountParam)
          Sets max total count
 ToolkitCacheConfigBuilder maxTTISeconds(int maxTTISecondsParam)
          Sets the TTI in seconds for the config to the new value and returns this.
 ToolkitCacheConfigBuilder maxTTLSeconds(int maxTTLSecondsParam)
          Sets the TTL in seconds for the config to the new value and returns this.
 ToolkitCacheConfigBuilder offheapEnabled(boolean offheapEnabledParam)
          Sets offheap enabled
 ToolkitCacheConfigBuilder pinnedInLocalMemory(boolean pinnedInLocalMemory)
          Sets whether entries should be pinned in local memory
protected  void setCompressionEnabled(boolean compressionEnabledParam)
          Sets compression enabled
protected  void setConcurrency(int concurrencyParam)
           
protected  void setConfigField(String fieldName, Serializable value)
           
protected  void setConsistency(ToolkitConfigFields.Consistency consistencyParam)
          Sets the ToolkitConfigFields.Consistency of the key-value store
protected  void setCopyOnReadEnabled(boolean copyOnReadEnabledParam)
          Sets copy on read enabled
protected  void setLocalCacheEnabled(boolean localCacheEnabledParam)
          Sets local cache enabled
protected  void setMaxBytesLocalHeap(long maxBytesLocalHeapParam)
          Sets the maxBytesLocalHeap
protected  void setMaxBytesLocalOffheap(long maxBytesLocalOffheapParam)
          Sets the max bytes local offheap
protected  void setMaxCountLocalHeap(int maxCountLocalHeapParam)
          Sets the max count local heap
protected  void setOffheapEnabled(boolean offheapEnabledParam)
          Sets offheap enabled
 void setPinnedInLocalMemory(boolean pinnedInLocalMemory)
          Sets whether entries should be pinned in local memory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToolkitCacheConfigBuilder

public ToolkitCacheConfigBuilder()
Method Detail

concurrency

public ToolkitCacheConfigBuilder concurrency(int concurrencyParam)
                                      throws IllegalArgumentException
Sets the concurrency config to the new value and returns this

Parameters:
concurrencyParam - new value of concurrency.
Returns:
same instance
Throws:
IllegalArgumentException - for non-positive concurrency params

consistency

public ToolkitCacheConfigBuilder consistency(ToolkitConfigFields.Consistency consistencyParam)
Sets the ToolkitConfigFields.Consistency of the key-value store

Returns:
same instance

maxBytesLocalHeap

public ToolkitCacheConfigBuilder maxBytesLocalHeap(long maxBytesLocalHeapParam)
                                            throws IllegalArgumentException
Sets the maxBytesLocalHeap

Returns:
same instance
Throws:
IllegalArgumentException - for negative values

maxBytesLocalOffheap

public ToolkitCacheConfigBuilder maxBytesLocalOffheap(long maxBytesLocalOffheapParam)
                                               throws IllegalArgumentException
Sets the max bytes local offheap

Returns:
same instance
Throws:
IllegalArgumentException - for negative values

maxCountLocalHeap

public ToolkitCacheConfigBuilder maxCountLocalHeap(int maxCountLocalHeapParam)
                                            throws IllegalArgumentException
Sets the max count local heap

Returns:
same instance
Throws:
IllegalArgumentException - for negative values

offheapEnabled

public ToolkitCacheConfigBuilder offheapEnabled(boolean offheapEnabledParam)
Sets offheap enabled

Returns:
same instance

localCacheEnabled

public ToolkitCacheConfigBuilder localCacheEnabled(boolean localCacheEnabledParam)
Sets local cache enabled

Returns:
same instance

compressionEnabled

public ToolkitCacheConfigBuilder compressionEnabled(boolean compressionEnabledParam)
Sets compression enabled

Returns:
same instance

copyOnReadEnabled

public ToolkitCacheConfigBuilder copyOnReadEnabled(boolean copyOnReadEnabledParam)
Sets copy on read enabled

Returns:
same instance

pinnedInLocalMemory

public ToolkitCacheConfigBuilder pinnedInLocalMemory(boolean pinnedInLocalMemory)
Sets whether entries should be pinned in local memory

Returns:
same instance

getMaxTTISeconds

public int getMaxTTISeconds()
Max TTI in seconds for the map. Zero means no TTI

Returns:
max tti

maxTTISeconds

public ToolkitCacheConfigBuilder maxTTISeconds(int maxTTISecondsParam)
                                        throws IllegalArgumentException
Sets the TTI in seconds for the config to the new value and returns this. Zero means no TTI.

Returns:
same instance
Throws:
IllegalArgumentException - for negative parameters

getMaxTTLSeconds

public int getMaxTTLSeconds()
Max TTL in seconds for the map. Zero means no TTL

Returns:
max ttl

maxTTLSeconds

public ToolkitCacheConfigBuilder maxTTLSeconds(int maxTTLSecondsParam)
                                        throws IllegalArgumentException
Sets the TTL in seconds for the config to the new value and returns this. Zero means no TTL.

Returns:
same instance
Throws:
IllegalArgumentException - for negative parameters

getMaxTotalCount

public int getMaxTotalCount()
Returns max total count

Returns:
max total count

maxTotalCount

public ToolkitCacheConfigBuilder maxTotalCount(int maxTotalCountParam)
                                        throws IllegalArgumentException
Sets max total count

Returns:
same instance
Throws:
IllegalArgumentException - for negative parameters

isEvictionEnabled

public boolean isEvictionEnabled()
Returns eviction enabled

Returns:
eviction enabled

evictionEnabled

public ToolkitCacheConfigBuilder evictionEnabled(boolean evictionEnabledParam)
Sets eviction enabled/disabled

Returns:
same instance

configField

public ToolkitCacheConfigBuilder configField(String fieldName,
                                             Serializable value)

build

public Configuration build()
Builds a Configuration for ToolkitCache by filling in appropriate mappings. Only adds mappings for values which were set explicitly in this builder, and doesn’t fills in default values in the returned config. Consult ToolkitConfigFields, ToolkitConfigFields for the various configs supported and its default values


apply

public void apply(ToolkitCache cache)
Applies the current changes from the builder to the ToolkitCache. The changes are the ones between each apply.


addFieldToApply

protected void addFieldToApply(String name,
                               Serializable value)

getConcurrency

public int getConcurrency()
Concurrency of the store

Returns:
Concurrency of the store

getConsistency

public ToolkitConfigFields.Consistency getConsistency()
Getter for consistency

Returns:
ToolkitConfigFields.Consistency of the key-value store

getMaxBytesLocalHeap

public long getMaxBytesLocalHeap()
Gets the max bytes local heap

Returns:
max bytes local heap

getMaxBytesLocalOffheap

public long getMaxBytesLocalOffheap()
Gets the max bytes local offheap

Returns:
max bytes local offheap

getMaxCountLocalHeap

public long getMaxCountLocalHeap()
Gets the max count local heap

Returns:
max count local heap

isOffheapEnabled

public boolean isOffheapEnabled()
Returns true if offheap is enabled

Returns:
true if offheap is enabled, otherwise false

isLocalCacheEnabled

public boolean isLocalCacheEnabled()
Query whether local cache is enabled or not

Returns:
true if local cache is enabled, otherwise false

isCompressionEnabled

public boolean isCompressionEnabled()
Compression enabled or not getter

Returns:
whether compression is enabled

setPinnedInLocalMemory

public void setPinnedInLocalMemory(boolean pinnedInLocalMemory)
Sets whether entries should be pinned in local memory


isPinnedInLocalMemory

public boolean isPinnedInLocalMemory()

isCopyOnReadEnabled

public boolean isCopyOnReadEnabled()
copy-on-read enabled or not getter

Returns:
true if copy on read is enabled, otherwise false

setConcurrency

protected void setConcurrency(int concurrencyParam)
                       throws IllegalArgumentException
Throws:
IllegalArgumentException

setConsistency

protected void setConsistency(ToolkitConfigFields.Consistency consistencyParam)
Sets the ToolkitConfigFields.Consistency of the key-value store


setMaxBytesLocalHeap

protected void setMaxBytesLocalHeap(long maxBytesLocalHeapParam)
                             throws IllegalArgumentException
Sets the maxBytesLocalHeap

Throws:
IllegalArgumentException - for negative values

setMaxBytesLocalOffheap

protected void setMaxBytesLocalOffheap(long maxBytesLocalOffheapParam)
                                throws IllegalArgumentException
Sets the max bytes local offheap

Throws:
IllegalArgumentException - for negative values

setMaxCountLocalHeap

protected void setMaxCountLocalHeap(int maxCountLocalHeapParam)
                             throws IllegalArgumentException
Sets the max count local heap

Throws:
IllegalArgumentException - for negative values

setOffheapEnabled

protected void setOffheapEnabled(boolean offheapEnabledParam)
Sets offheap enabled


setLocalCacheEnabled

protected void setLocalCacheEnabled(boolean localCacheEnabledParam)
Sets local cache enabled


setCompressionEnabled

protected void setCompressionEnabled(boolean compressionEnabledParam)
Sets compression enabled


setCopyOnReadEnabled

protected void setCopyOnReadEnabled(boolean copyOnReadEnabledParam)
Sets copy on read enabled


setConfigField

protected void setConfigField(String fieldName,
                              Serializable value)

apply

public void apply(ToolkitStore store)
Apply changes of this builder to the ToolkitStore parameter. The changes are the ones between each apply.

If the store's configuration has ToolkitConfigFields.MAX_BYTES_LOCAL_HEAP_FIELD_NAME property set then AbstractToolkitStoreCacheConfigBuilder.setMaxCountLocalHeap(int) would result in an error.

If the store's configuration has ToolkitConfigFields.MAX_COUNT_LOCAL_HEAP_FIELD_NAME property set then AbstractToolkitStoreCacheConfigBuilder.setMaxBytesLocalHeap(long) would result in an error.



Copyright © 2014 Terracotta, Inc.. All Rights Reserved.