Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More robust java bindings for the hyperdex client

All bindings (except group_del) are implemented, but not fully tested.

Signed-off-by: Nick Tolomiczenko <nick.tolomiczenko@gmail.com>
  • Loading branch information...
commit cfb5b8a588d14739fc5b652787c2a675d07c64e9 1 parent 0a7ebec
@neikos neikos authored
View
BIN  hyperclient/java/examples/HyperTest.class
Binary file not shown
View
114 hyperclient/java/examples/HyperTest.java
@@ -0,0 +1,114 @@
+import hyperclient.*;
+import java.util.*;
+
+public class HyperTest
+{
+ public static void main(String[] args) throws Exception
+ {
+ HashMap<String,Object> values = new HashMap<String,Object>();
+
+ HyperClient c = new HyperClient("127.0.0.1",1234);
+
+ values.put("first","Nick");
+ values.put("last","Tolomiczenko");
+ values.put("phone",4165551024L);
+
+ System.out.println("ntolomic put: " + c.put("phonebook","ntolomic",values));
+
+ values.put("first","George");
+ values.put("last","Tolomiczenko");
+ values.put("phone",4165551025L);
+
+ System.out.println("gtolomic put: " + c.put("phonebook","gtolomic",values));
+
+ values.put("first","Paul");
+ values.put("last","Tolomiczenko");
+ values.put("phone",4165551026L);
+
+ System.out.println("ptolomic put: " + c.put("phonebook","ptolomic",values));
+
+ System.out.println("\nAbout retrieve key ntolomic:\n");
+
+ Map row = c.get("phonebook","ntolomic");
+
+ System.out.println("Got back: " + row);
+
+ System.out.println("\nSearching for last name of 'Tolomiczenko':\n");
+
+ // We'll use the same 'values' map for our search predicate
+
+ // This leaves us with only the last name entry
+ values.remove("first");
+ values.remove("phone");
+
+ Search s = c.search("phonebook",values);
+
+ while(s.hasNext())
+ {
+ System.out.println(s.next());
+ }
+
+ // Now add a range stipulation on the phone number: [4165551024,4165551026)
+ values.put("phone",
+ new AbstractMap.SimpleEntry<Long,Long>(4165551024L,4165551026L));
+
+ System.out.println("\nSearching for last name of 'Tolomiczenko'\n\n AND\n\nphone number in the range [4165551024,4165551026):\n");
+
+ // Do the search again
+ s = c.search("phonebook",values);
+
+ while(s.hasNext())
+ {
+ System.out.println(s.next());
+ }
+
+ // Stipulate the range with a List of size 2 instead.
+ // In particular, use in Vector.
+ Vector<Long> vrange = new Vector<Long>(2);
+ vrange.add(4165551024L); vrange.add(4165551026L);
+ values.put("phone",vrange);
+
+ System.out.println("\nDo the search again using a List of size 2 for the range stipulation:\n");
+ // Do the search again
+ s = c.search("phonebook",values);
+
+ while(s.hasNext())
+ {
+ System.out.println(s.next());
+ }
+
+ // Now do an async_put, which should work by definition.
+ //
+ values.put("first","Stavroula");
+ values.put("phone",4165551027L);
+
+ Deferred d = c.async_put("phonebook","stolomic",values);;
+
+ System.out.println("\nJust called async_put:\n");
+ System.out.println("\nAbout to call waitFor():\n");
+
+ System.out.println(d.waitFor());
+
+ values.remove("first"); values.remove("phone");
+
+ // Do the search again
+ s = c.search("phonebook",values);
+
+ while(s.hasNext())
+ {
+ System.out.println(s.next());
+ }
+
+ System.out.println("\nAbout delete ntolomic:\n");
+
+ System.out.println("result: " + c.del("phonebook","ntolomic"));
+
+ // Do the search again
+ s = c.search("phonebook",values);
+
+ while(s.hasNext())
+ {
+ System.out.println(s.next());
+ }
+ }
+}
View
4 hyperclient/java/examples/README.txt
@@ -0,0 +1,4 @@
+INSTRUCTIONS:
+
+. source_me
+javac HyperTest.java
View
2  hyperclient/java/examples/source_me
@@ -0,0 +1,2 @@
+export CLASSPATH=.:../../../hyperclient-0.5.dev.jar
+export LD_LIBRARY_PATH=../../../.libs
View
1  hyperclient/java/extra_src/Search.java
@@ -262,7 +262,6 @@ public boolean hasNext() throws HyperClientException
while ( ! finished && backlogged.size() == 0 )
{
client.loop();
- System.out.println("hasNext(): status = " + status());
}
return backlogged.size() > 0;
View
2  hyperclient/java/gen_code/op_list.txt
@@ -1,4 +1,6 @@
+get
put
+del
atomic_add
atomic_sub
atomic_mul
View
12 hyperclient/java/javaclient.cc
@@ -38,9 +38,6 @@
#include <limits.h>
-#include <iostream>
-#include <sstream>
-
#include <cstdlib>
HyperClient :: HyperClient(const char* coordinator, in_port_t port)
@@ -118,16 +115,13 @@ HyperClient :: alloc_attrs(size_t attrs_sz)
void
HyperClient :: destroy_attrs(hyperclient_attribute *attrs, size_t attrs_sz)
{
- std::cout << "About to destroy_attrs" << std::endl;
for (size_t i=0; i<attrs_sz; i++)
{
if (attrs[i].attr) free((void*)(attrs[i].attr));
if (attrs[i].value) free((void*)(attrs[i].value));
}
- std::cout << "Freed members" << std::endl;
free(attrs);
- std::cout << "Freed attrs" << std::endl;
}
hyperclient_map_attribute*
@@ -140,7 +134,6 @@ HyperClient :: alloc_map_attrs(size_t attrs_sz)
void
HyperClient :: destroy_map_attrs(hyperclient_map_attribute *attrs, size_t attrs_sz)
{
- std::cout << "About to destroy_map_attrs" << std::endl;
for (size_t i=0; i<attrs_sz; i++)
{
if (attrs[i].attr) free((void*)(attrs[i].attr));
@@ -148,9 +141,7 @@ HyperClient :: destroy_map_attrs(hyperclient_map_attribute *attrs, size_t attrs_
if (attrs[i].value) free((void*)(attrs[i].value));
}
- std::cout << "Freed map members" << std::endl;
free(attrs);
- std::cout << "Freed map attrs" << std::endl;
}
hyperclient_range_query*
@@ -163,15 +154,12 @@ HyperClient :: alloc_range_queries(size_t rqs_sz)
void
HyperClient :: destroy_range_queries(hyperclient_range_query *rqs, size_t rqs_sz)
{
- std::cout << "About to destroy_range_queries" << std::endl;
for (size_t i=0; i<rqs_sz; i++)
{
if (rqs[i].attr) free((void*)(rqs[i].attr));
}
- std::cout << "Freed range query members" << std::endl;
free(rqs);
- std::cout << "Freed range queries" << std::endl;
}
int
View
6 hyperclient/java/proxies/HyperClient.i
@@ -580,10 +580,10 @@
return ((Boolean)(d.waitFor())).booleanValue();
}
- public boolean delete(String space, String key) throws HyperClientException,
+ public boolean del(String space, String key) throws HyperClientException,
ValueError
{
- Deferred d = (DeferredDelete)(async_delete(space, key));
+ Deferred d = (DeferredDelete)(async_del(space, key));
return ((Boolean)(d.waitFor())).booleanValue();
}
@@ -900,7 +900,7 @@
return new DeferredCondPut(this, space, key, condition, value);
}
- public Deferred async_delete(String space, String key) throws HyperClientException
+ public Deferred async_del(String space, String key) throws HyperClientException
{
return new DeferredDelete(this, space, key);
}
View
6 ycsb/hyperclient/HyperClientYCSB.java
@@ -170,7 +170,7 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
*/
public int update(String table, String key, HashMap<String,ByteIterator> values)
{
- Map res = new HashMap<String,Object>();
+ Map<String,Object> res = new HashMap<String,Object>();
convert_from_java(values, res);
if (m_scannable)
@@ -222,7 +222,7 @@ public int delete(String table, String key)
{
try
{
- boolean ret = m_client.delete(table, key);
+ boolean ret = m_client.del(table, key);
return ret?0:1;
}
catch(Exception e)
@@ -248,7 +248,7 @@ private void convert_to_java(Set<String> fields, Map interres, HashMap<String,By
}
}
- private void convert_from_java(HashMap<String,ByteIterator> result, Map interres)
+ private void convert_from_java(HashMap<String,ByteIterator> result, Map<String,Object> interres)
{
Map<String, ByteIterator> r = result;
for (Map.Entry<String, ByteIterator> entry : r.entrySet())
Please sign in to comment.
Something went wrong with that request. Please try again.