diff --git a/geode/pom.xml b/geode/pom.xml
index fa36bbd5..6d614cdf 100644
--- a/geode/pom.xml
+++ b/geode/pom.xml
@@ -1,50 +1,74 @@
4.0.0
com.yahoo.ycsb
binding-parent
0.8.0-SNAPSHOT
../binding-parent
geode-binding
Geode DB Binding
jar
false
org.apache.geode
gemfire-core
${geode.version}
com.yahoo.ycsb
core
${project.version}
provided
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.15
+
+ true
+ ../checkstyle.xml
+ true
+ true
+
+
+
+ validate
+ validate
+
+ checkstyle
+
+
+
+
+
+
diff --git a/geode/src/main/java/com/yahoo/ycsb/db/GeodeClient.java b/geode/src/main/java/com/yahoo/ycsb/db/GeodeClient.java
index cdbfc961..f6bcc01a 100644
--- a/geode/src/main/java/com/yahoo/ycsb/db/GeodeClient.java
+++ b/geode/src/main/java/com/yahoo/ycsb/db/GeodeClient.java
@@ -1,209 +1,191 @@
/**
* Copyright (c) 2013 - 2016 YCSB Contributors. All rights reserved.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.yahoo.ycsb.db;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.GemFireCache;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionExistsException;
-import com.gemstone.gemfire.cache.RegionFactory;
-import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.*;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.ClientRegionFactory;
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
import com.gemstone.gemfire.internal.admin.remote.DistributionLocatorId;
-import com.yahoo.ycsb.ByteArrayByteIterator;
-import com.yahoo.ycsb.ByteIterator;
-import com.yahoo.ycsb.DB;
-import com.yahoo.ycsb.DBException;
-import com.yahoo.ycsb.Status;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.Vector;
+import com.yahoo.ycsb.*;
+
+import java.util.*;
/**
- * Apache Geode (incubating) client for the YCSB benchmark.
+ * Apache Geode (incubating) client for the YCSB benchmark.
*
By default acts as a Geode client and tries to connect
* to Geode cache server running on localhost with default
* cache server port. Hostname and port of a Geode cacheServer
* can be provided using geode.serverport=port
and
* geode.serverhost=host
properties on YCSB command line.
* A locator may also be used for discovering a cacheServer
* by using the property geode.locator=host[port]
- *
+ *
* To run this client in a peer-to-peer topology with other Geode
* nodes, use the property geode.topology=p2p
. Running
* in p2p mode will enable embedded caching in this client.
- *
+ *
* YCSB by default does its operations against "usertable". When running
* as a client this is a ClientRegionShortcut.PROXY
region,
* when running in p2p mode it is a RegionShortcut.PARTITION
* region. A cache.xml defining "usertable" region can be placed in the
* working directory to override these region definitions.
- *
+ *
*/
public class GeodeClient extends DB {
-
- /** property name of the port where Geode server is listening for connections */
+ /** property name of the port where Geode server is listening for connections. */
private static final String SERVERPORT_PROPERTY_NAME = "geode.serverport";
- /** property name of the host where Geode server is running */
+ /** property name of the host where Geode server is running. */
private static final String SERVERHOST_PROPERTY_NAME = "geode.serverhost";
- /** default value of {@link #SERVERHOST_PROPERTY_NAME} */
+ /** default value of {@link #SERVERHOST_PROPERTY_NAME}. */
private static final String SERVERHOST_PROPERTY_DEFAULT = "localhost";
/** property name to specify a Geode locator. This property can be used in both
* client server and p2p topology */
private static final String LOCATOR_PROPERTY_NAME = "geode.locator";
- /** property name to specify Geode topology */
+ /** property name to specify Geode topology. */
private static final String TOPOLOGY_PROPERTY_NAME = "geode.topology";
/** value of {@value #TOPOLOGY_PROPERTY_NAME} when peer to peer topology should be used.
* (client-server topology is default) */
private static final String TOPOLOGY_P2P_VALUE = "p2p";
private GemFireCache cache;
- /**
- * true if ycsb client runs as a client to a
- * Geode cache server
- */
+ /** true if ycsb client runs as a client to a Geode cache server. */
private boolean isClient;
-
+
@Override
public void init() throws DBException {
Properties props = getProperties();
// hostName where Geode cacheServer is running
String serverHost = null;
// port of Geode cacheServer
int serverPort = 0;
String locatorStr = null;
if (props != null && !props.isEmpty()) {
String serverPortStr = props.getProperty(SERVERPORT_PROPERTY_NAME);
if (serverPortStr != null) {
serverPort = Integer.parseInt(serverPortStr);
}
serverHost = props.getProperty(SERVERHOST_PROPERTY_NAME, SERVERHOST_PROPERTY_DEFAULT);
locatorStr = props.getProperty(LOCATOR_PROPERTY_NAME);
-
+
String topology = props.getProperty(TOPOLOGY_PROPERTY_NAME);
if (topology != null && topology.equals(TOPOLOGY_P2P_VALUE)) {
CacheFactory cf = new CacheFactory();
if (locatorStr != null) {
cf.set("locators", locatorStr);
}
cache = cf.create();
isClient = false;
return;
}
}
isClient = true;
DistributionLocatorId locator = null;
if (locatorStr != null) {
locator = new DistributionLocatorId(locatorStr);
}
ClientCacheFactory ccf = new ClientCacheFactory();
if (serverPort != 0) {
ccf.addPoolServer(serverHost, serverPort);
} else if (locator != null) {
ccf.addPoolLocator(locator.getHost().getCanonicalHostName(), locator.getPort());
}
cache = ccf.create();
}
-
+
@Override
public Status read(String table, String key, Set fields,
- HashMap result) {
+ HashMap result) {
Region> r = getRegion(table);
Map val = r.get(key);
if (val != null) {
if (fields == null) {
for (Map.Entry entry : val.entrySet()) {
result.put(entry.getKey(), new ByteArrayByteIterator(entry.getValue()));
}
} else {
for (String field : fields) {
result.put(field, new ByteArrayByteIterator(val.get(field)));
}
}
return Status.OK;
}
return Status.ERROR;
}
@Override
public Status scan(String table, String startkey, int recordcount,
- Set fields, Vector> result) {
+ Set fields, Vector> result) {
// Geode does not support scan
return Status.ERROR;
}
@Override
public Status update(String table, String key, HashMap values) {
getRegion(table).put(key, convertToBytearrayMap(values));
return Status.OK;
}
@Override
public Status insert(String table, String key, HashMap values) {
getRegion(table).put(key, convertToBytearrayMap(values));
return Status.OK;
}
@Override
public Status delete(String table, String key) {
getRegion(table).destroy(key);
return Status.OK;
}
- private Map convertToBytearrayMap(Map values) {
+ private Map convertToBytearrayMap(Map values) {
Map retVal = new HashMap();
for (Map.Entry entry : values.entrySet()) {
retVal.put(entry.getKey(), entry.getValue().toArray());
}
return retVal;
}
-
+
private Region> getRegion(String table) {
Region> r = cache.getRegion(table);
if (r == null) {
try {
if (isClient) {
- ClientRegionFactory> crf = ((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY);
+ ClientRegionFactory> crf =
+ ((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY);
r = crf.create(table);
} else {
- RegionFactory> rf = ((Cache)cache).createRegionFactory(RegionShortcut.PARTITION);
+ RegionFactory> rf = ((Cache) cache).createRegionFactory(RegionShortcut.PARTITION);
r = rf.create(table);
}
} catch (RegionExistsException e) {
// another thread created the region
r = cache.getRegion(table);
}
}
return r;
}
-
-}
+}
\ No newline at end of file
diff --git a/geode/src/main/java/com/yahoo/ycsb/db/package-info.java b/geode/src/main/java/com/yahoo/ycsb/db/package-info.java
new file mode 100644
index 00000000..1b6db476
--- /dev/null
+++ b/geode/src/main/java/com/yahoo/ycsb/db/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2014-2016, Yahoo!, Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you
+ * may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License. See accompanying
+ * LICENSE file.
+ */
+
+/**
+ * YCSB binding for Apache Geode (incubating).
+ */
+package com.yahoo.ycsb.db;
\ No newline at end of file