Permalink
Browse files

ISPN-2225 Configuration API and XML parser for the HBase CacheStore

  • Loading branch information...
tristantarrant authored and galderz committed Sep 20, 2012
1 parent 089812e commit 1f688398fde47ca96f3372f07e5c0929e551e034
@@ -108,7 +108,7 @@ public void start() throws CacheLoaderException {
Map<String, String> props = new HashMap<String, String>();
props.put("hbase.zookeeper.quorum", config.hbaseZookeeperQuorum);
- props.put("hbase.zookeeper.property.clientPort", config.hbaseZookeeperPropertyClientPort);
+ props.put("hbase.zookeeper.property.clientPort", Integer.toString(config.hbaseZookeeperPropertyClientPort));
hbf = new HBaseFacade(props);
} catch (Exception e) {
throw new ConfigurationException(e);
@@ -41,7 +41,7 @@
/**
* @configRef desc="The HBase zookeeper client port."
*/
- String hbaseZookeeperPropertyClientPort = "2181";
+ int hbaseZookeeperPropertyClientPort = 2181;
/**
* @configRef desc="The HBase table for storing the cache entries"
@@ -94,19 +94,19 @@ public HBaseCacheStoreConfig() {
setCacheLoaderClassName(HBaseCacheStore.class.getName());
}
- public String getHbaseRootDir() {
+ public String getHbaseZookeeperQuorum() {
return hbaseZookeeperQuorum;
}
public void setHbaseZookeeperQuorum(String hbaseZookeeperQuorum) {
this.hbaseZookeeperQuorum = hbaseZookeeperQuorum;
}
- public String getHbaseZookeeperPropertyClientPort() {
+ public int getHbaseZookeeperPropertyClientPort() {
return hbaseZookeeperPropertyClientPort;
}
- public void setHbaseZookeeperPropertyClientPort(String hbaseZookeeperPropertyClientPort) {
+ public void setHbaseZookeeperPropertyClientPort(int hbaseZookeeperPropertyClientPort) {
this.hbaseZookeeperPropertyClientPort = hbaseZookeeperPropertyClientPort;
}
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.infinispan.loaders.hbase.configuration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.infinispan.loaders.hbase.HBaseCacheStore;
+
+/**
+ * Enumerates the attributes used by the {@link HBaseCacheStore} configuration
+ *
+ * @author Tristan Tarrant
+ * @since 5.2
+ */
+public enum Attribute {
+ // must be first
+ UNKNOWN(null),
+ AUTO_CREATE_TABLE("autoCreateTable"),
+ ENTRY_COLUMN_FAMILY("entryColumnFamily"),
+ ENTRY_TABLE("entryTable"),
+ ENTRY_VALUE_FIELD("entryValueField"),
+ EXPIRATION_COLUMN_FAMILY("expirationColumnFamily"),
+ EXPIRATION_TABLE("expirationTable"),
+ EXPIRATION_VALUE_FIELD("expirationValueField"),
+ HBASE_ZOOKEEPER_QUORUM_HOST("hbaseZookeeperQuorumHost"),
+ HBASE_ZOOKEEPER_CLIENT_PORT("hbaseZookeeperClientPort"),
+ KEY_MAPPER("keyMapper"),
+ SHARED_TABLE("sharedTable"),
+ ;
+
+ private final String name;
+
+ private Attribute(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName() {
+ return name;
+ }
+
+ private static final Map<String, Attribute> attributes;
+
+ static {
+ final Map<String, Attribute> map = new HashMap<String, Attribute>(64);
+ for (Attribute attribute : values()) {
+ final String name = attribute.getLocalName();
+ if (name != null) {
+ map.put(name, attribute);
+ }
+ }
+ attributes = map;
+ }
+
+ public static Attribute forName(final String localName) {
+ final Attribute attribute = attributes.get(localName);
+ return attribute == null ? UNKNOWN : attribute;
+ }
+}
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.loaders.hbase.configuration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.infinispan.loaders.hbase.HBaseCacheStore;
+
+/**
+ * An enumeration of all the recognized XML element local names for the {@link HBaseCacheStore}
+ *
+ * @author Tristan Tarrant
+ * @since 5.2
+ */
+public enum Element {
+ // must be first
+ UNKNOWN(null),
+
+ HBASE_STORE("hbaseStore"),
+ ;
+
+ private final String name;
+
+ Element(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName() {
+ return name;
+ }
+
+ private static final Map<String, Element> MAP;
+
+ static {
+ final Map<String, Element> map = new HashMap<String, Element>(8);
+ for (Element element : values()) {
+ final String name = element.getLocalName();
+ if (name != null) {
+ map.put(name, element);
+ }
+ }
+ MAP = map;
+ }
+
+ public static Element forName(final String localName) {
+ final Element element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+}
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.infinispan.loaders.hbase.configuration;
+
+import org.infinispan.configuration.BuiltBy;
+import org.infinispan.configuration.cache.AbstractStoreConfiguration;
+import org.infinispan.configuration.cache.AsyncStoreConfiguration;
+import org.infinispan.configuration.cache.LegacyConfigurationAdaptor;
+import org.infinispan.configuration.cache.LegacyLoaderAdapter;
+import org.infinispan.configuration.cache.SingletonStoreConfiguration;
+import org.infinispan.loaders.hbase.HBaseCacheStoreConfig;
+import org.infinispan.util.TypedProperties;
+
+@BuiltBy(HBaseCacheStoreConfigurationBuilder.class)
+public class HBaseCacheStoreConfiguration extends AbstractStoreConfiguration implements LegacyLoaderAdapter<HBaseCacheStoreConfig> {
+
+ private final boolean autoCreateTable;
+ private final String entryColumnFamily;
+ private final String entryTable;
+ private final String entryValueField;
+ private final String expirationColumnFamily;
+ private final String expirationTable;
+ private final String expirationValueField;
+ private final String hbaseZookeeperQuorumHost;
+ private final int hbaseZookeeperClientPort;
+ private final String keyMapper;
+ private final boolean sharedTable;
+
+ public HBaseCacheStoreConfiguration(boolean autoCreateTable, String entryColumnFamily, String entryTable, String entryValueField, String expirationColumnFamily,
+ String expirationTable, String expirationValueField, String hbaseZookeeperQuorumHost, int hbaseZookeeperClientPort, String keyMapper, boolean sharedTable,
+ boolean purgeOnStartup, boolean purgeSynchronously, int purgerThreads, boolean fetchPersistentState, boolean ignoreModifications, TypedProperties properties,
+ AsyncStoreConfiguration asyncStoreConfiguration, SingletonStoreConfiguration singletonStoreConfiguration) {
+ super(purgeOnStartup, purgeSynchronously, purgerThreads, fetchPersistentState, ignoreModifications, properties, asyncStoreConfiguration, singletonStoreConfiguration);
+ this.autoCreateTable = autoCreateTable;
+ this.entryColumnFamily = entryColumnFamily;
+ this.entryTable = entryTable;
+ this.entryValueField = entryValueField;
+ this.expirationColumnFamily = expirationColumnFamily;
+ this.expirationTable = expirationTable;
+ this.expirationValueField = expirationValueField;
+ this.hbaseZookeeperQuorumHost = hbaseZookeeperQuorumHost;
+ this.hbaseZookeeperClientPort = hbaseZookeeperClientPort;
+ this.keyMapper = keyMapper;
+ this.sharedTable = sharedTable;
+ }
+
+ public boolean autoCreateTable() {
+ return autoCreateTable;
+ }
+
+ public String entryColumnFamily() {
+ return entryColumnFamily;
+ }
+
+ public String entryTable() {
+ return entryTable;
+ }
+
+ public String entryValueField() {
+ return entryValueField;
+ }
+
+ public String expirationColumnFamily() {
+ return expirationColumnFamily;
+ }
+
+ public String expirationTable() {
+ return expirationTable;
+ }
+
+ public String expirationValueField() {
+ return expirationValueField;
+ }
+
+ public String hbaseZookeeperQuorumHost() {
+ return hbaseZookeeperQuorumHost;
+ }
+
+ public int hbaseZookeeperClientPort() {
+ return hbaseZookeeperClientPort;
+ }
+
+ public String keyMapper() {
+ return keyMapper;
+ }
+
+ public boolean sharedTable() {
+ return sharedTable;
+ }
+
+ @Override
+ public HBaseCacheStoreConfig adapt() {
+ HBaseCacheStoreConfig config = new HBaseCacheStoreConfig();
+
+ LegacyConfigurationAdaptor.adapt(this, config);
+
+ config.setAutoCreateTable(autoCreateTable);
+ config.setEntryColumnFamily(entryColumnFamily);
+ config.setEntryTable(entryTable);
+ config.setEntryValueField(entryValueField);
+ config.setExpirationColumnFamily(expirationColumnFamily);
+ config.setExpirationTable(expirationTable);
+ config.setExpirationValueField(expirationValueField);
+ config.setHbaseZookeeperPropertyClientPort(hbaseZookeeperClientPort);
+ config.setHbaseZookeeperQuorum(hbaseZookeeperQuorumHost);
+ config.setKeyMapper(keyMapper);
+ config.setSharedTable(sharedTable);
+
+ return config;
+ }
+
+}
Oops, something went wrong.

0 comments on commit 1f68839

Please sign in to comment.