/cachestore/cassandra/src/main/java/org/infinispan/loaders/cassandra/CassandraCacheStoreConfig.java

https://bitbucket.org/cprenzberg/infinispan · Java · 254 lines · 146 code · 52 blank · 56 comment · 7 complexity · 5c479614e0f2ccbaa4b7865d39e36e80 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2010 Red Hat Inc. and/or its affiliates and other
  4. * contributors as indicated by the @author tags. All rights reserved.
  5. * See the copyright.txt in the distribution for a full listing of
  6. * individual contributors.
  7. *
  8. * This is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU Lesser General Public License as
  10. * published by the Free Software Foundation; either version 2.1 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This software is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this software; if not, write to the Free
  20. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  22. */
  23. package org.infinispan.loaders.cassandra;
  24. import java.io.IOException;
  25. import java.io.InputStream;
  26. import java.util.Properties;
  27. import net.dataforte.cassandra.pool.PoolProperties;
  28. import org.apache.cassandra.thrift.ConsistencyLevel;
  29. import org.infinispan.config.ConfigurationException;
  30. import org.infinispan.loaders.AbstractCacheStoreConfig;
  31. import org.infinispan.loaders.keymappers.DefaultTwoWayKey2StringMapper;
  32. import org.infinispan.util.FileLookupFactory;
  33. import org.infinispan.util.Util;
  34. /**
  35. * Configures {@link CassandraCacheStore}.
  36. */
  37. public class CassandraCacheStoreConfig extends AbstractCacheStoreConfig {
  38. /**
  39. * @configRef desc="The Cassandra keyspace"
  40. */
  41. String keySpace = "Infinispan";
  42. /**
  43. * @configRef desc="The Cassandra column family for entries"
  44. */
  45. String entryColumnFamily = "InfinispanEntries";
  46. /**
  47. * @configRef desc="The Cassandra column family for expirations"
  48. */
  49. String expirationColumnFamily = "InfinispanExpiration";
  50. /**
  51. * @configRef desc="Whether the keySpace is shared between multiple caches"
  52. */
  53. boolean sharedKeyspace = false;
  54. /**
  55. * @configRef desc="Which Cassandra consistency level to use when reading"
  56. */
  57. String readConsistencyLevel = "ONE";
  58. /**
  59. * @configRef desc="Which Cassandra consistency level to use when writing"
  60. */
  61. String writeConsistencyLevel = "ONE";
  62. /**
  63. * @configRef desc=
  64. * "An optional properties file for configuring the underlying cassandra connection pool"
  65. */
  66. String configurationPropertiesFile;
  67. /**
  68. * @configRef desc=
  69. * "The keymapper for converting keys to strings (uses the DefaultTwoWayKey2Stringmapper by default)"
  70. */
  71. String keyMapper = DefaultTwoWayKey2StringMapper.class.getName();
  72. /**
  73. * @configRef desc=
  74. * "Whether to automatically create the keyspace with the appropriate column families (true by default)"
  75. */
  76. boolean autoCreateKeyspace = true;
  77. protected PoolProperties poolProperties;
  78. public CassandraCacheStoreConfig() {
  79. setCacheLoaderClassName(CassandraCacheStore.class.getName());
  80. poolProperties = new PoolProperties();
  81. }
  82. public String getKeySpace() {
  83. return keySpace;
  84. }
  85. public void setKeySpace(String keySpace) {
  86. this.keySpace = keySpace;
  87. }
  88. public String getEntryColumnFamily() {
  89. return entryColumnFamily;
  90. }
  91. public void setEntryColumnFamily(String entryColumnFamily) {
  92. this.entryColumnFamily = entryColumnFamily;
  93. }
  94. public String getExpirationColumnFamily() {
  95. return expirationColumnFamily;
  96. }
  97. public void setExpirationColumnFamily(String expirationColumnFamily) {
  98. this.expirationColumnFamily = expirationColumnFamily;
  99. }
  100. public boolean isSharedKeyspace() {
  101. return sharedKeyspace;
  102. }
  103. public void setSharedKeyspace(boolean sharedKeyspace) {
  104. this.sharedKeyspace = sharedKeyspace;
  105. }
  106. public String getReadConsistencyLevel() {
  107. return readConsistencyLevel;
  108. }
  109. public void setReadConsistencyLevel(String readConsistencyLevel) {
  110. this.readConsistencyLevel = readConsistencyLevel;
  111. }
  112. public String getWriteConsistencyLevel() {
  113. return writeConsistencyLevel;
  114. }
  115. public void setWriteConsistencyLevel(String writeConsistencyLevel) {
  116. this.writeConsistencyLevel = writeConsistencyLevel;
  117. }
  118. public PoolProperties getPoolProperties() {
  119. return poolProperties;
  120. }
  121. public void setHost(String host) {
  122. poolProperties.setHost(host);
  123. }
  124. public String getHost() {
  125. return poolProperties.getHost();
  126. }
  127. public void setPort(int port) {
  128. poolProperties.setPort(port);
  129. }
  130. public int getPort() {
  131. return poolProperties.getPort();
  132. }
  133. public boolean isFramed() {
  134. return poolProperties.isFramed();
  135. }
  136. public String getPassword() {
  137. return poolProperties.getPassword();
  138. }
  139. public String getUsername() {
  140. return poolProperties.getUsername();
  141. }
  142. public void setFramed(boolean framed) {
  143. poolProperties.setFramed(framed);
  144. }
  145. public void setPassword(String password) {
  146. poolProperties.setPassword(password);
  147. }
  148. public void setUsername(String username) {
  149. poolProperties.setUsername(username);
  150. }
  151. public void setDatasourceJndiLocation(String location) {
  152. poolProperties.setDataSourceJNDI(location);
  153. }
  154. public String getDatasourceJndiLocation() {
  155. return poolProperties.getDataSourceJNDI();
  156. }
  157. public String getConfigurationPropertiesFile() {
  158. return configurationPropertiesFile;
  159. }
  160. public void setConfigurationPropertiesFile(String configurationPropertiesFile) {
  161. this.configurationPropertiesFile = configurationPropertiesFile;
  162. readConfigurationProperties();
  163. }
  164. private void readConfigurationProperties() {
  165. if (configurationPropertiesFile == null || configurationPropertiesFile.trim().length() == 0)
  166. return;
  167. InputStream i = FileLookupFactory.newInstance().lookupFile(configurationPropertiesFile, getClassLoader());
  168. if (i != null) {
  169. Properties p = new Properties();
  170. try {
  171. p.load(i);
  172. } catch (IOException ioe) {
  173. throw new ConfigurationException("Unable to read environment properties file " + configurationPropertiesFile,
  174. ioe);
  175. } finally {
  176. Util.close(i);
  177. }
  178. // Apply all properties to the PoolProperties object
  179. for (String propertyName : p.stringPropertyNames()) {
  180. poolProperties.set(propertyName, p.getProperty(propertyName));
  181. }
  182. }
  183. }
  184. public String getKeyMapper() {
  185. return keyMapper;
  186. }
  187. public void setKeyMapper(String keyMapper) {
  188. this.keyMapper = keyMapper;
  189. }
  190. public boolean isAutoCreateKeyspace() {
  191. return autoCreateKeyspace;
  192. }
  193. public void setAutoCreateKeyspace(boolean autoCreateKeyspace) {
  194. this.autoCreateKeyspace = autoCreateKeyspace;
  195. }
  196. public void setReadConsistencyLevel(ConsistencyLevel readConsistencyLevel) {
  197. this.readConsistencyLevel = readConsistencyLevel.toString();
  198. }
  199. public void setWriteConsistencyLevel(ConsistencyLevel writeConsistencyLevel) {
  200. this.writeConsistencyLevel = writeConsistencyLevel.toString();
  201. }
  202. }