11/**
22 * Copyright (c) 2013 - 2016 YCSB Contributors. All rights reserved.
3- *
3+ * <p>
44 * Licensed under the Apache License, Version 2.0 (the "License"); you
55 * may not use this file except in compliance with the License. You
66 * may obtain a copy of the License at
7- *
7+ * <p>
88 * http://www.apache.org/licenses/LICENSE-2.0
9- *
9+ * <p>
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1717
1818package com .yahoo .ycsb .db ;
1919
20- import com .gemstone .gemfire .cache .Cache ;
21- import com .gemstone .gemfire .cache .CacheFactory ;
22- import com .gemstone .gemfire .cache .GemFireCache ;
23- import com .gemstone .gemfire .cache .Region ;
24- import com .gemstone .gemfire .cache .RegionExistsException ;
25- import com .gemstone .gemfire .cache .RegionFactory ;
26- import com .gemstone .gemfire .cache .RegionShortcut ;
20+ import com .gemstone .gemfire .cache .*;
2721import com .gemstone .gemfire .cache .client .ClientCache ;
2822import com .gemstone .gemfire .cache .client .ClientCacheFactory ;
2923import com .gemstone .gemfire .cache .client .ClientRegionFactory ;
3024import com .gemstone .gemfire .cache .client .ClientRegionShortcut ;
3125import com .gemstone .gemfire .internal .admin .remote .DistributionLocatorId ;
32- import com .yahoo .ycsb .ByteArrayByteIterator ;
33- import com .yahoo .ycsb .ByteIterator ;
34- import com .yahoo .ycsb .DB ;
35- import com .yahoo .ycsb .DBException ;
36- import com .yahoo .ycsb .Status ;
37-
38- import java .util .HashMap ;
39- import java .util .Map ;
40- import java .util .Properties ;
41- import java .util .Set ;
42- import java .util .Vector ;
26+ import com .yahoo .ycsb .*;
27+
28+ import java .util .*;
4329
4430/**
45- * Apache Geode (incubating) client for the YCSB benchmark.<br />
31+ * Apache Geode (incubating) client for the YCSB benchmark.<br />
4632 * <p>By default acts as a Geode client and tries to connect
4733 * to Geode cache server running on localhost with default
4834 * cache server port. Hostname and port of a Geode cacheServer
4935 * can be provided using <code>geode.serverport=port</code> and <code>
5036 * geode.serverhost=host</code> properties on YCSB command line.
5137 * A locator may also be used for discovering a cacheServer
5238 * by using the property <code>geode.locator=host[port]</code></p>
53- *
39+ *
5440 * <p>To run this client in a peer-to-peer topology with other Geode
5541 * nodes, use the property <code>geode.topology=p2p</code>. Running
5642 * in p2p mode will enable embedded caching in this client.</p>
57- *
43+ *
5844 * <p>YCSB by default does its operations against "usertable". When running
5945 * as a client this is a <code>ClientRegionShortcut.PROXY</code> region,
6046 * when running in p2p mode it is a <code>RegionShortcut.PARTITION</code>
6147 * region. A cache.xml defining "usertable" region can be placed in the
6248 * working directory to override these region definitions.</p>
63- *
49+ *
6450 */
6551public class GeodeClient extends DB {
66-
67- /** property name of the port where Geode server is listening for connections */
52+ /** property name of the port where Geode server is listening for connections. */
6853 private static final String SERVERPORT_PROPERTY_NAME = "geode.serverport" ;
6954
70- /** property name of the host where Geode server is running */
55+ /** property name of the host where Geode server is running. */
7156 private static final String SERVERHOST_PROPERTY_NAME = "geode.serverhost" ;
7257
73- /** default value of {@link #SERVERHOST_PROPERTY_NAME} */
58+ /** default value of {@link #SERVERHOST_PROPERTY_NAME}. */
7459 private static final String SERVERHOST_PROPERTY_DEFAULT = "localhost" ;
7560
7661 /** property name to specify a Geode locator. This property can be used in both
7762 * client server and p2p topology */
7863 private static final String LOCATOR_PROPERTY_NAME = "geode.locator" ;
7964
80- /** property name to specify Geode topology */
65+ /** property name to specify Geode topology. */
8166 private static final String TOPOLOGY_PROPERTY_NAME = "geode.topology" ;
8267
8368 /** value of {@value #TOPOLOGY_PROPERTY_NAME} when peer to peer topology should be used.
@@ -86,12 +71,9 @@ public class GeodeClient extends DB {
8671
8772 private GemFireCache cache ;
8873
89- /**
90- * true if ycsb client runs as a client to a
91- * Geode cache server
92- */
74+ /** true if ycsb client runs as a client to a Geode cache server. */
9375 private boolean isClient ;
94-
76+
9577 @ Override
9678 public void init () throws DBException {
9779 Properties props = getProperties ();
@@ -108,7 +90,7 @@ public void init() throws DBException {
10890 }
10991 serverHost = props .getProperty (SERVERHOST_PROPERTY_NAME , SERVERHOST_PROPERTY_DEFAULT );
11092 locatorStr = props .getProperty (LOCATOR_PROPERTY_NAME );
111-
93+
11294 String topology = props .getProperty (TOPOLOGY_PROPERTY_NAME );
11395 if (topology != null && topology .equals (TOPOLOGY_P2P_VALUE )) {
11496 CacheFactory cf = new CacheFactory ();
@@ -133,10 +115,10 @@ public void init() throws DBException {
133115 }
134116 cache = ccf .create ();
135117 }
136-
118+
137119 @ Override
138120 public Status read (String table , String key , Set <String > fields ,
139- HashMap <String , ByteIterator > result ) {
121+ HashMap <String , ByteIterator > result ) {
140122 Region <String , Map <String , byte []>> r = getRegion (table );
141123 Map <String , byte []> val = r .get (key );
142124 if (val != null ) {
@@ -156,7 +138,7 @@ public Status read(String table, String key, Set<String> fields,
156138
157139 @ Override
158140 public Status scan (String table , String startkey , int recordcount ,
159- Set <String > fields , Vector <HashMap <String , ByteIterator >> result ) {
141+ Set <String > fields , Vector <HashMap <String , ByteIterator >> result ) {
160142 // Geode does not support scan
161143 return Status .ERROR ;
162144 }
@@ -179,23 +161,24 @@ public Status delete(String table, String key) {
179161 return Status .OK ;
180162 }
181163
182- private Map <String , byte []> convertToBytearrayMap (Map <String ,ByteIterator > values ) {
164+ private Map <String , byte []> convertToBytearrayMap (Map <String , ByteIterator > values ) {
183165 Map <String , byte []> retVal = new HashMap <String , byte []>();
184166 for (Map .Entry <String , ByteIterator > entry : values .entrySet ()) {
185167 retVal .put (entry .getKey (), entry .getValue ().toArray ());
186168 }
187169 return retVal ;
188170 }
189-
171+
190172 private Region <String , Map <String , byte []>> getRegion (String table ) {
191173 Region <String , Map <String , byte []>> r = cache .getRegion (table );
192174 if (r == null ) {
193175 try {
194176 if (isClient ) {
195- ClientRegionFactory <String , Map <String , byte []>> crf = ((ClientCache ) cache ).createClientRegionFactory (ClientRegionShortcut .PROXY );
177+ ClientRegionFactory <String , Map <String , byte []>> crf =
178+ ((ClientCache ) cache ).createClientRegionFactory (ClientRegionShortcut .PROXY );
196179 r = crf .create (table );
197180 } else {
198- RegionFactory <String , Map <String , byte []>> rf = ((Cache )cache ).createRegionFactory (RegionShortcut .PARTITION );
181+ RegionFactory <String , Map <String , byte []>> rf = ((Cache ) cache ).createRegionFactory (RegionShortcut .PARTITION );
199182 r = rf .create (table );
200183 }
201184 } catch (RegionExistsException e ) {
@@ -205,5 +188,4 @@ private Region<String, Map<String, byte[]>> getRegion(String table) {
205188 }
206189 return r ;
207190 }
208-
209- }
191+ }
0 commit comments