1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.config.generator.model.elements;
18
19 import net.sf.ehcache.config.CacheWriterConfiguration;
20 import net.sf.ehcache.config.CacheWriterConfiguration.CacheWriterFactoryConfiguration;
21 import net.sf.ehcache.config.generator.model.NodeElement;
22 import net.sf.ehcache.config.generator.model.SimpleNodeAttribute;
23 import net.sf.ehcache.config.generator.model.SimpleNodeElement;
24
25 /***
26 * Element representing the {@link CacheWriterConfiguration}
27 *
28 * @author Abhishek Sanoujam
29 *
30 */
31 public class CacheWriterConfigurationElement extends SimpleNodeElement {
32
33 private final CacheWriterConfiguration cacheWriterConfiguration;
34
35 /***
36 * Constructor accepting the parent and the {@link CacheWriterConfiguration}
37 *
38 * @param parent
39 * @param cacheWriterConfiguration
40 */
41 public CacheWriterConfigurationElement(NodeElement parent, CacheWriterConfiguration cacheWriterConfiguration) {
42 super(parent, "cacheWriter");
43 this.cacheWriterConfiguration = cacheWriterConfiguration;
44 init();
45 }
46
47 private void init() {
48 if (cacheWriterConfiguration == null) {
49 return;
50 }
51 addAttribute(new SimpleNodeAttribute("minWriteDelay", cacheWriterConfiguration.getMinWriteDelay()).optional(true).defaultValue(
52 CacheWriterConfiguration.DEFAULT_MIN_WRITE_DELAY));
53 addAttribute(new SimpleNodeAttribute("writeMode", cacheWriterConfiguration.getWriteMode()).optional(true).defaultValue(
54 CacheWriterConfiguration.DEFAULT_WRITE_MODE));
55 addAttribute(new SimpleNodeAttribute("writeBatchSize", cacheWriterConfiguration.getWriteBatchSize()).optional(true).defaultValue(
56 CacheWriterConfiguration.DEFAULT_WRITE_BATCH_SIZE));
57 addAttribute(new SimpleNodeAttribute("maxWriteDelay", cacheWriterConfiguration.getMaxWriteDelay()).optional(true).defaultValue(
58 CacheWriterConfiguration.DEFAULT_MAX_WRITE_DELAY));
59 addAttribute(new SimpleNodeAttribute("retryAttempts", cacheWriterConfiguration.getRetryAttempts()).optional(true).defaultValue(
60 CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPTS));
61 addAttribute(new SimpleNodeAttribute("rateLimitPerSecond", cacheWriterConfiguration.getRateLimitPerSecond()).optional(true)
62 .defaultValue(CacheWriterConfiguration.DEFAULT_RATE_LIMIT_PER_SECOND));
63 addAttribute(new SimpleNodeAttribute("writeBatching", cacheWriterConfiguration.getWriteBatching()).optional(true).defaultValue(
64 CacheWriterConfiguration.DEFAULT_WRITE_BATCHING));
65 addAttribute(new SimpleNodeAttribute("writeCoalescing", cacheWriterConfiguration.getWriteCoalescing()).optional(true).defaultValue(
66 CacheWriterConfiguration.DEFAULT_WRITE_COALESCING));
67 addAttribute(new SimpleNodeAttribute("notifyListenersOnException", cacheWriterConfiguration.getNotifyListenersOnException())
68 .optional(true).defaultValue(CacheWriterConfiguration.DEFAULT_NOTIFY_LISTENERS_ON_EXCEPTION));
69 addAttribute(new SimpleNodeAttribute("retryAttemptDelaySeconds", cacheWriterConfiguration.getRetryAttemptDelaySeconds()).optional(
70 true).defaultValue(CacheWriterConfiguration.DEFAULT_RETRY_ATTEMPT_DELAY_SECONDS));
71 addAttribute(new SimpleNodeAttribute("writeBehindConcurrency", cacheWriterConfiguration.getWriteBehindConcurrency()).optional(
72 true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_CONCURRENCY));
73 addAttribute(new SimpleNodeAttribute("writeBehindMaxQueueSize", cacheWriterConfiguration.getWriteBehindMaxQueueSize()).optional(
74 true).defaultValue(CacheWriterConfiguration.DEFAULT_WRITE_BEHIND_MAX_QUEUE_SIZE));
75
76 CacheWriterFactoryConfiguration cacheWriterFactoryConfiguration = cacheWriterConfiguration.getCacheWriterFactoryConfiguration();
77 if (cacheWriterFactoryConfiguration != null) {
78 addChildElement(new FactoryConfigurationElement(this, "cacheWriterFactory", cacheWriterFactoryConfiguration));
79 }
80 }
81
82 }