/** * Allows BeanHandler to add the CacheWriterConfiguration to the configuration. */ public final void addCacheWriter(CacheWriterConfiguration cacheWriterConfiguration) { if (null == cacheWriterConfiguration) { this.cacheWriterConfiguration = new CacheWriterConfiguration(); } else { this.cacheWriterConfiguration = cacheWriterConfiguration; } }
@Override public WriteBehind createWriteBehind(Ehcache cache) { final CacheWriterConfiguration config = cache.getCacheConfiguration().getCacheWriterConfiguration(); final AsyncConfig asyncConfig = new WriteBehindAsyncConfig(config.getMinWriteDelay() * 1000, config.getMaxWriteDelay() * 1000, config.getWriteBatching(), config.getWriteBatchSize(), cache.getCacheConfiguration() .getTerracottaConfiguration().isSynchronousWrites(), config.getRetryAttempts(), config.getRetryAttemptDelaySeconds() * 1000, config.getRateLimitPerSecond(), config.getWriteBehindMaxQueueSize()); final AsyncCoordinator asyncCoordinator = asyncCoordinatorFactory.getOrCreateAsyncCoordinator(cache, asyncConfig); return new AsyncWriteBehind(asyncCoordinator, config.getWriteBehindConcurrency()); }
/** * @return this configuration instance * @see #addCacheWriterFactory(CacheWriterFactoryConfiguration) */ public CacheWriterConfiguration cacheWriterFactory(CacheWriterFactoryConfiguration cacheWriterFactory) { addCacheWriterFactory(cacheWriterFactory); return this; }
/** * Check for errors/inconsistencies in this configuration. Add any erros found as * {@link ConfigError} in the errors collection. * @param errors collection to add errors to. */ public void validate(Collection<ConfigError> errors) { if (writeMode.equals(WriteMode.WRITE_BEHIND)) { if (!getWriteBatching() && getWriteBatchSize() != 1) { errors.add(new ConfigError("Configured Write Batch Size is not equal to 1 with Write Batching turned off.")); } } } }
addAttribute(new SimpleNodeAttribute("minWriteDelay", cacheWriterConfiguration.getMinWriteDelay()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_MIN_WRITE_DELAY)); addAttribute(new SimpleNodeAttribute("writeMode", cacheWriterConfiguration.getWriteMode()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_MODE)); addAttribute(new SimpleNodeAttribute("writeBatchSize", cacheWriterConfiguration.getWriteBatchSize()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_BATCH_SIZE)); addAttribute(new SimpleNodeAttribute("maxWriteDelay", cacheWriterConfiguration.getMaxWriteDelay()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_MAX_WRITE_DELAY)); addAttribute(new SimpleNodeAttribute("retryAttempts", cacheWriterConfiguration.getRetryAttempts()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPTS)); addAttribute(new SimpleNodeAttribute("rateLimitPerSecond", cacheWriterConfiguration.getRateLimitPerSecond()).optional(true) .defaultValue(CacheWriterConfiguration.DEFAULT_RATE_LIMIT_PER_SECOND)); addAttribute(new SimpleNodeAttribute("writeBatching", cacheWriterConfiguration.getWriteBatching()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_BATCHING)); addAttribute(new SimpleNodeAttribute("writeCoalescing", cacheWriterConfiguration.getWriteCoalescing()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_COALESCING)); addAttribute(new SimpleNodeAttribute("notifyListenersOnException", cacheWriterConfiguration.getNotifyListenersOnException()) .optional(true).defaultValue(CacheWriterConfiguration.DEFAULT_NOTIFY_LISTENERS_ON_EXCEPTION)); addAttribute(new SimpleNodeAttribute("retryAttemptDelaySeconds", cacheWriterConfiguration.getRetryAttemptDelaySeconds()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPT_DELAY_SECONDS)); addAttribute(new SimpleNodeAttribute("writeBehindConcurrency", cacheWriterConfiguration.getWriteBehindConcurrency()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_CONCURRENCY)); addAttribute(new SimpleNodeAttribute("writeBehindMaxQueueSize", cacheWriterConfiguration.getWriteBehindMaxQueueSize()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_MAX_QUEUE_SIZE)); CacheWriterFactoryConfiguration cacheWriterFactoryConfiguration = cacheWriterConfiguration.getCacheWriterFactoryConfiguration(); if (cacheWriterFactoryConfiguration != null) { addChildElement(new FactoryConfigurationElement(this, "cacheWriterFactory", cacheWriterFactoryConfiguration));
private CacheConfiguration toEhcacheConfig(final String name, final Configuration configuration) { final int maxSize = cacheManager.getConfiguration().isMaxBytesLocalHeapSet() ? 0 : DEFAULT_SIZE; CacheConfiguration cfg = new CacheConfiguration(name, maxSize); cfg.setClassLoader(cacheManager.getConfiguration().getClassLoader()); if(configuration.isStoreByValue()) { final CopyStrategyConfiguration copyStrategyConfiguration = new CopyStrategyConfiguration(); copyStrategyConfiguration.setCopyStrategyInstance(new JCacheCopyOnWriteStrategy()); cfg.copyOnRead(true).copyOnWrite(true) .addCopyStrategy(copyStrategyConfiguration); } if(configuration instanceof CompleteConfiguration) { if(((CompleteConfiguration)configuration).isWriteThrough()) { cfg.addCacheWriter(new CacheWriterConfiguration().writeMode(CacheWriterConfiguration.WriteMode.WRITE_THROUGH)); } } return cfg; }
config.cacheWriterConfiguration = cacheWriterConfiguration.clone();
addAttribute(new SimpleNodeAttribute("minWriteDelay", cacheWriterConfiguration.getMinWriteDelay()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_MIN_WRITE_DELAY)); addAttribute(new SimpleNodeAttribute("writeMode", cacheWriterConfiguration.getWriteMode()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_MODE)); addAttribute(new SimpleNodeAttribute("writeBatchSize", cacheWriterConfiguration.getWriteBatchSize()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_BATCH_SIZE)); addAttribute(new SimpleNodeAttribute("maxWriteDelay", cacheWriterConfiguration.getMaxWriteDelay()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_MAX_WRITE_DELAY)); addAttribute(new SimpleNodeAttribute("retryAttempts", cacheWriterConfiguration.getRetryAttempts()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPTS)); addAttribute(new SimpleNodeAttribute("rateLimitPerSecond", cacheWriterConfiguration.getRateLimitPerSecond()).optional(true) .defaultValue(CacheWriterConfiguration.DEFAULT_RATE_LIMIT_PER_SECOND)); addAttribute(new SimpleNodeAttribute("writeBatching", cacheWriterConfiguration.getWriteBatching()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_BATCHING)); addAttribute(new SimpleNodeAttribute("writeCoalescing", cacheWriterConfiguration.getWriteCoalescing()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_COALESCING)); addAttribute(new SimpleNodeAttribute("notifyListenersOnException", cacheWriterConfiguration.getNotifyListenersOnException()) .optional(true).defaultValue(CacheWriterConfiguration.DEFAULT_NOTIFY_LISTENERS_ON_EXCEPTION)); addAttribute(new SimpleNodeAttribute("retryAttemptDelaySeconds", cacheWriterConfiguration.getRetryAttemptDelaySeconds()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPT_DELAY_SECONDS)); addAttribute(new SimpleNodeAttribute("writeBehindConcurrency", cacheWriterConfiguration.getWriteBehindConcurrency()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_CONCURRENCY)); addAttribute(new SimpleNodeAttribute("writeBehindMaxQueueSize", cacheWriterConfiguration.getWriteBehindMaxQueueSize()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_MAX_QUEUE_SIZE)); CacheWriterFactoryConfiguration cacheWriterFactoryConfiguration = cacheWriterConfiguration.getCacheWriterFactoryConfiguration(); if (cacheWriterFactoryConfiguration != null) { addChildElement(new FactoryConfigurationElement(this, "cacheWriterFactory", cacheWriterFactoryConfiguration));
if (!cacheWriterConfiguration.getWriteBatching() && cacheWriterConfiguration.getWriteBatchSize() != 1) { throw new InvalidConfigurationException("CacheWriter Batch Size !=1 and CacheWriter Batching " + "turned off");
private CacheConfiguration toEhcacheConfig(final String name, final Configuration configuration) { final int maxSize = cacheManager.getConfiguration().isMaxBytesLocalHeapSet() ? 0 : DEFAULT_SIZE; CacheConfiguration cfg = new CacheConfiguration(name, maxSize); cfg.setClassLoader(cacheManager.getConfiguration().getClassLoader()); if(configuration.isStoreByValue()) { final CopyStrategyConfiguration copyStrategyConfiguration = new CopyStrategyConfiguration(); copyStrategyConfiguration.setCopyStrategyInstance(new JCacheCopyOnWriteStrategy()); cfg.copyOnRead(true).copyOnWrite(true) .addCopyStrategy(copyStrategyConfiguration); } if(configuration instanceof CompleteConfiguration) { if(((CompleteConfiguration)configuration).isWriteThrough()) { cfg.addCacheWriter(new CacheWriterConfiguration().writeMode(CacheWriterConfiguration.WriteMode.WRITE_THROUGH)); } } return cfg; }
config.cacheWriterConfiguration = cacheWriterConfiguration.clone();
addAttribute(new SimpleNodeAttribute("minWriteDelay", cacheWriterConfiguration.getMinWriteDelay()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_MIN_WRITE_DELAY)); addAttribute(new SimpleNodeAttribute("writeMode", cacheWriterConfiguration.getWriteMode()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_MODE)); addAttribute(new SimpleNodeAttribute("writeBatchSize", cacheWriterConfiguration.getWriteBatchSize()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_BATCH_SIZE)); addAttribute(new SimpleNodeAttribute("maxWriteDelay", cacheWriterConfiguration.getMaxWriteDelay()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_MAX_WRITE_DELAY)); addAttribute(new SimpleNodeAttribute("retryAttempts", cacheWriterConfiguration.getRetryAttempts()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPTS)); addAttribute(new SimpleNodeAttribute("rateLimitPerSecond", cacheWriterConfiguration.getRateLimitPerSecond()).optional(true) .defaultValue(CacheWriterConfiguration.DEFAULT_RATE_LIMIT_PER_SECOND)); addAttribute(new SimpleNodeAttribute("writeBatching", cacheWriterConfiguration.getWriteBatching()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_BATCHING)); addAttribute(new SimpleNodeAttribute("writeCoalescing", cacheWriterConfiguration.getWriteCoalescing()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_COALESCING)); addAttribute(new SimpleNodeAttribute("notifyListenersOnException", cacheWriterConfiguration.getNotifyListenersOnException()) .optional(true).defaultValue(CacheWriterConfiguration.DEFAULT_NOTIFY_LISTENERS_ON_EXCEPTION)); addAttribute(new SimpleNodeAttribute("retryAttemptDelaySeconds", cacheWriterConfiguration.getRetryAttemptDelaySeconds()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPT_DELAY_SECONDS)); addAttribute(new SimpleNodeAttribute("writeBehindConcurrency", cacheWriterConfiguration.getWriteBehindConcurrency()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_CONCURRENCY)); addAttribute(new SimpleNodeAttribute("writeBehindMaxQueueSize", cacheWriterConfiguration.getWriteBehindMaxQueueSize()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_MAX_QUEUE_SIZE)); CacheWriterFactoryConfiguration cacheWriterFactoryConfiguration = cacheWriterConfiguration.getCacheWriterFactoryConfiguration(); if (cacheWriterFactoryConfiguration != null) { addChildElement(new FactoryConfigurationElement(this, "cacheWriterFactory", cacheWriterFactoryConfiguration));
/** * Create a new write behind queue. * * @param config the configuration for the queue */ public AbstractWriteBehindQueue(CacheConfiguration config) { this.stopping = false; this.stopped = true; this.cacheName = config.getName(); // making a copy of the configuration locally to ensure that it will not be changed at runtime final CacheWriterConfiguration cacheWriterConfig = config.getCacheWriterConfiguration(); this.minWriteDelayMs = cacheWriterConfig.getMinWriteDelay() * MS_IN_SEC; this.maxWriteDelayMs = cacheWriterConfig.getMaxWriteDelay() * MS_IN_SEC; this.rateLimitPerSecond = cacheWriterConfig.getRateLimitPerSecond(); this.maxQueueSize = cacheWriterConfig.getWriteBehindMaxQueueSize(); this.writeBatching = cacheWriterConfig.getWriteBatching(); this.writeBatchSize = cacheWriterConfig.getWriteBatchSize(); this.retryAttempts = cacheWriterConfig.getRetryAttempts(); this.retryAttemptDelaySeconds = cacheWriterConfig.getRetryAttemptDelaySeconds(); this.processingThread = new Thread(new ProcessingThread(), cacheName + " write-behind"); this.processingThread.setDaemon(true); }
/** * Check for errors/inconsistencies in this configuration. Add any erros found as * {@link ConfigError} in the errors collection. * @param errors collection to add errors to. */ public void validate(Collection<ConfigError> errors) { if (writeMode.equals(WriteMode.WRITE_BEHIND)) { if (!getWriteBatching() && getWriteBatchSize() != 1) { errors.add(new ConfigError("Configured Write Batch Size is not equal to 1 with Write Batching turned off.")); } } } }
private void cacheWriter(final Config conf) { String path = this.path + ".cacheWriter"; CacheWriterConfiguration writer = new CacheWriterConfiguration(); sint(path, conf, "maxWriteDelay", writer::setMaxWriteDelay); sint(path, conf, "minWriteDelay", writer::setMinWriteDelay); sbool(path, conf, "notifyListenersOnException", writer::setNotifyListenersOnException); sint(path, conf, "rateLimitPerSecond", writer::setRateLimitPerSecond); siseconds(path, conf, "retryAttemptDelay", writer::setRetryAttemptDelaySeconds); sint(path, conf, "retryAttemptDelaySeconds", writer::setRetryAttemptDelaySeconds); sint(path, conf, "retryAttempts", writer::setRetryAttempts); sbool(path, conf, "writeBatching", writer::setWriteBatching); sint(path, conf, "writeBatchSize", writer::setWriteBatchSize); sint(path, conf, "writeBehindConcurrency", writer::setWriteBehindConcurrency); sint(path, conf, "writeBehindMaxQueueSize", writer::setWriteBehindMaxQueueSize); sbool(path, conf, "writeCoalescing", writer::setWriteCoalescing); sstr(path, conf, "writeMode", writer::setWriteMode); cache.addCacheWriter(writer); }
/** * @return this configuration instance * @see #addCacheWriterFactory(CacheWriterFactoryConfiguration) */ public CacheWriterConfiguration cacheWriterFactory(CacheWriterFactoryConfiguration cacheWriterFactory) { addCacheWriterFactory(cacheWriterFactory); return this; }
config.cacheWriterConfiguration = cacheWriterConfiguration.clone();
addAttribute(new SimpleNodeAttribute("minWriteDelay", cacheWriterConfiguration.getMinWriteDelay()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_MIN_WRITE_DELAY)); addAttribute(new SimpleNodeAttribute("writeMode", cacheWriterConfiguration.getWriteMode()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_MODE)); addAttribute(new SimpleNodeAttribute("writeBatchSize", cacheWriterConfiguration.getWriteBatchSize()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_BATCH_SIZE)); addAttribute(new SimpleNodeAttribute("maxWriteDelay", cacheWriterConfiguration.getMaxWriteDelay()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_MAX_WRITE_DELAY)); addAttribute(new SimpleNodeAttribute("retryAttempts", cacheWriterConfiguration.getRetryAttempts()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPTS)); addAttribute(new SimpleNodeAttribute("rateLimitPerSecond", cacheWriterConfiguration.getRateLimitPerSecond()).optional(true) .defaultValue(CacheWriterConfiguration.DEFAULT_RATE_LIMIT_PER_SECOND)); addAttribute(new SimpleNodeAttribute("writeBatching", cacheWriterConfiguration.getWriteBatching()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_BATCHING)); addAttribute(new SimpleNodeAttribute("writeCoalescing", cacheWriterConfiguration.getWriteCoalescing()).optional(true).defaultValue( CacheWriterConfiguration.DEFAULT_WRITE_COALESCING)); addAttribute(new SimpleNodeAttribute("notifyListenersOnException", cacheWriterConfiguration.getNotifyListenersOnException()) .optional(true).defaultValue(CacheWriterConfiguration.DEFAULT_NOTIFY_LISTENERS_ON_EXCEPTION)); addAttribute(new SimpleNodeAttribute("retryAttemptDelaySeconds", cacheWriterConfiguration.getRetryAttemptDelaySeconds()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPT_DELAY_SECONDS)); addAttribute(new SimpleNodeAttribute("writeBehindConcurrency", cacheWriterConfiguration.getWriteBehindConcurrency()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_CONCURRENCY)); addAttribute(new SimpleNodeAttribute("writeBehindMaxQueueSize", cacheWriterConfiguration.getWriteBehindMaxQueueSize()).optional( true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_MAX_QUEUE_SIZE)); CacheWriterFactoryConfiguration cacheWriterFactoryConfiguration = cacheWriterConfiguration.getCacheWriterFactoryConfiguration(); if (cacheWriterFactoryConfiguration != null) { addChildElement(new FactoryConfigurationElement(this, "cacheWriterFactory", cacheWriterFactoryConfiguration));
/** * Create a new write behind queue. * * @param config the configuration for the queue */ public AbstractWriteBehindQueue(CacheConfiguration config) { this.stopping = false; this.stopped = true; this.cacheName = config.getName(); // making a copy of the configuration locally to ensure that it will not be changed at runtime final CacheWriterConfiguration cacheWriterConfig = config.getCacheWriterConfiguration(); this.minWriteDelayMs = cacheWriterConfig.getMinWriteDelay() * MS_IN_SEC; this.maxWriteDelayMs = cacheWriterConfig.getMaxWriteDelay() * MS_IN_SEC; this.rateLimitPerSecond = cacheWriterConfig.getRateLimitPerSecond(); this.maxQueueSize = cacheWriterConfig.getWriteBehindMaxQueueSize(); this.writeBatching = cacheWriterConfig.getWriteBatching(); this.writeBatchSize = cacheWriterConfig.getWriteBatchSize(); this.retryAttempts = cacheWriterConfig.getRetryAttempts(); this.retryAttemptDelaySeconds = cacheWriterConfig.getRetryAttemptDelaySeconds(); this.processingThread = new Thread(new ProcessingThread(), cacheName + " write-behind"); this.processingThread.setDaemon(true); }
/** * Check for errors/inconsistencies in this configuration. Add any erros found as * {@link ConfigError} in the errors collection. * @param errors collection to add errors to. */ public void validate(Collection<ConfigError> errors) { if (writeMode.equals(WriteMode.WRITE_BEHIND)) { if (!getWriteBatching() && getWriteBatchSize() != 1) { errors.add(new ConfigError("Configured Write Batch Size is not equal to 1 with Write Batching turned off.")); } } } }