Skip to content

Commit

Permalink
Some more Java microtransaction work
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Mast committed Feb 23, 2015
1 parent afbb25b commit 5e0d18a
Show file tree
Hide file tree
Showing 15 changed files with 1,140 additions and 594 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ EXTRA_DIST += bindings/java/org/hyperdex/client/LengthLessEqual.java
EXTRA_DIST += bindings/java/org/hyperdex/client/LessEqual.java
EXTRA_DIST += bindings/java/org/hyperdex/client/LessThan.java
EXTRA_DIST += bindings/java/org/hyperdex/client/Microtransaction.java
EXTRA_DIST += bindings/java/org_hyperdex_client_Microtransaction.definitions.c
EXTRA_DIST += bindings/java/org/hyperdex/client/Operation.java
EXTRA_DIST += bindings/java/org/hyperdex/client/Predicate.java
EXTRA_DIST += bindings/java/org/hyperdex/client/Range.java
Expand All @@ -658,6 +659,7 @@ noinst_HEADERS += bindings/java/org_hyperdex_client_Range.h
noinst_HEADERS += bindings/java/org_hyperdex_client_Regex.h

libhyperdex_client_java_la_SOURCES =
libhyperdex_client_java_la_SOURCES += bindings/java/org_hyperdex_client_Microtransaction.c
libhyperdex_client_java_la_SOURCES += bindings/java/org_hyperdex_client_Client.c
libhyperdex_client_java_la_CPPFLAGS = $(JNI_CPPFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS)
libhyperdex_client_java_la_CFLAGS = $(AM_CFLAGS) $(CFLAGS) -Wmissing-prototypes
Expand Down
62 changes: 13 additions & 49 deletions bindings/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,11 @@ def CTYPEOF(x):
raise RuntimeError('Unknown type: ' + str(x))

def generate_microtransaction_prototype(x):
if x.form is not bindings.MicrotransactionCall:
return ''

args_list = ', '.join([JTYPEOF(arg) + ' ' + arg.__name__.lower() for arg in x.args_in])
if x.form == bindings.AsyncCall:
if x.args_out == (bindings.Status, bindings.Attributes):
ret = 'Map<String, Object>'
elif x.args_out == (bindings.Status, bindings.Description):
ret = 'String'
elif x.args_out == (bindings.Status, bindings.Count):
ret = 'Long'
elif x.args_out == (bindings.Status,):
ret = 'Boolean'
else:
print x.args_out
assert False
proto = ' public native Deferred async_{0}({1}) throws HyperDexClientException;\n'.format(x.name, args_list)
proto += ' public {1} {0}('.format(x.name, ret)
proto += args_list
proto += ') throws HyperDexClientException\n {\n'
args_list = ', '.join([arg.__name__.lower() for arg in x.args_in])
proto += ' return ({2}) async_{0}({1}).waitForIt();\n'.format(x.name, args_list, ret)
proto += ' }\n'
return proto
elif (x.form == bindings.MicrotransactionCall or x.form == bindings.Iterator):
return ' public native Iterator {0}({1});\n'.format(x.name, args_list)
else:
assert False
return ' public native Integer {0}(Map<String,Object> attrs) throws HyperDexClientException;\n'.format(x.name)

def generate_client_prototype(x):
if x.form is bindings.MicrotransactionCall:
return ''

args_list = ', '.join([JTYPEOF(arg) + ' ' + arg.__name__.lower() for arg in x.args_in])
if x.form == bindings.AsyncCall:
if x.form is bindings.AsyncCall:
if x.args_out == (bindings.Status, bindings.Attributes):
ret = 'Map<String, Object>'
elif x.args_out == (bindings.Status, bindings.Description):
Expand All @@ -115,8 +85,8 @@ def generate_client_prototype(x):
elif x.args_out == (bindings.Status,):
ret = 'Boolean'
else:
print x.args_out
assert False
raise RuntimeError('Cannot handle args: ' + str(x.args_out))

proto = ' public native Deferred async_{0}({1}) throws HyperDexClientException;\n'.format(x.name, args_list)
proto += ' public {1} {0}('.format(x.name, ret)
proto += args_list
Expand All @@ -125,18 +95,18 @@ def generate_client_prototype(x):
proto += ' return ({2}) async_{0}({1}).waitForIt();\n'.format(x.name, args_list, ret)
proto += ' }\n'
return proto
elif (x.form == bindings.MicrotransactionCall or x.form == bindings.Iterator):
elif x.form is bindings.Iterator:
return ' public native Iterator {0}({1});\n'.format(x.name, args_list)
else:
assert False
raise RuntimeError('Unknown function type: ' + str(x.form))

def generate_worker(call, x):
if x.form == bindings.AsyncCall:
cls = 'deferred'
elif x.form == bindings.Iterator:
cls = 'iterator'
else:
assert False
raise RuntimeError('Unknown function type: ' + str(x.form))

fptr = bindings.c.generate_func_ptr(x, 'client')
func = 'JNIEXPORT HYPERDEX_API jobject JNICALL\n'
Expand Down Expand Up @@ -187,25 +157,19 @@ def generate_workers(xs):
calls.add(call)

def generate_microtransaction_definition(x):
if not (x.form is bindings.MicrotransactionCall):
return ''

func = 'JNIEXPORT HYPERDEX_API jint JNICALL\n'
func += 'Java_org_hyperdex_client_Client_{0}(JNIEnv* env, jobject obj'.format(x.name.replace('_', '_1'))
func += 'Java_org_hyperdex_client_Microtransaction_{0}(JNIEnv* env '.format(x.name.replace('_', '_1'))

for arg in x.args_in:
func += ', ' + CTYPEOF(arg) + ' ' + arg.__name__.lower()
func += ')\n{\n'
func += ' return hyperdex_java_client_{0}(env, obj, hyperdex_client_{1}'.format(bindings.call_name(x), x.name)
func += ' return hyperdex_java_uactx_{0}(env, hyperdex_client_{1}'.format(bindings.call_name(x), x.name)
for arg in x.args_in:
func += ', ' + arg.__name__.lower()
func += ');\n}\n'
return func

def generate_client_definition(x):
if x.form is bindings.MicrotransactionCall:
return ''

func = 'JNIEXPORT HYPERDEX_API jobject JNICALL\n'
if x.form == bindings.AsyncCall:
func += 'Java_org_hyperdex_client_Client_async_1{0}(JNIEnv* env, jobject obj'.format(x.name.replace('_', '_1'))
Expand Down Expand Up @@ -306,7 +270,7 @@ def generate_client_java():
fout = open(os.path.join(BASE, 'bindings/java/org/hyperdex/client/Client.java'), 'w')
fout.write(bindings.copyright('*', '2013-2015'))
fout.write(bindings.java.JAVA_HEAD)
fout.write('\n'.join([generate_client_prototype(c) for c in bindings.Client]))
fout.write('\n'.join([generate_client_prototype(c) for c in bindings.Client if c.form is not bindings.MicrotransactionCall]))
fout.write('}\n')
fout.flush()
fout = open(os.path.join(BASE, 'bindings/java/org/hyperdex/client/Microtransaction.java'), 'w')
Expand Down Expand Up @@ -337,19 +301,19 @@ def generate_client_java():
fout.write(bindings.copyright('*', '2013-2015'))
fout.write(bindings.java.DEFINITIONS_HEAD)
fout.write('\n'.join(generate_workers(bindings.Client)))
fout.write('\n'.join([generate_client_definition(c) for c in bindings.Client]))
fout.write('\n'.join([generate_client_definition(c) for c in bindings.Client if c.form is not bindings.MicrotransactionCall]))
fout = open(os.path.join(BASE, 'bindings/java/org_hyperdex_client_Microtransaction.definitions.c'), 'w')
fout.write(bindings.copyright('*', '2015'))
fout.write(bindings.java.DEFINITIONS_HEAD)
fout.write('\n'.join(generate_workers(bindings.Client)))
fout.write('\n'.join([generate_microtransaction_definition(c) for c in bindings.Client]))
fout.write('\n'.join([generate_microtransaction_definition(c) for c in bindings.Client if c.form is bindings.MicrotransactionCall]))

def generate_client_doc():
fout = open(os.path.join(BASE, 'doc/java/client/ops.tex'), 'w')
fout.write(bindings.copyright('%', '2014-2015'))
fout.write('\n% This LaTeX file is generated by bindings/java.py\n\n')
fout.write('\n'.join([generate_api_block(c, 'client') for c in bindings.Client
if c.name not in (bindings.DoNotDocument, bindings.MicrotransactionCall)]))
if c.form not in (bindings.DoNotDocument, bindings.MicrotransactionCall)]))

if __name__ == '__main__':
generate_client_java()
Expand Down
3 changes: 2 additions & 1 deletion bindings/java/org/hyperdex/client/ByteString.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public String decode(String encoding)
public String toString(String encoding)
throws UnsupportedEncodingException
{
return decode(encoding);
// Terminating NULL character is redundant in string representation
return decode(encoding).replace("\0", "");
}

public static String toString(byte[] bytes, String encoding)
Expand Down
13 changes: 0 additions & 13 deletions bindings/java/org/hyperdex/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public Boolean put(String spacename, Object key, Map<String, Object> attributes)
return (Boolean) async_put(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_put(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_put(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand Down Expand Up @@ -180,7 +179,6 @@ public Boolean atomic_add(String spacename, Object key, Map<String, Object> attr
return (Boolean) async_atomic_add(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_atomic_add(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_atomic_add(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand All @@ -199,7 +197,6 @@ public Boolean atomic_sub(String spacename, Object key, Map<String, Object> attr
return (Boolean) async_atomic_sub(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_atomic_sub(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_atomic_sub(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand All @@ -218,7 +215,6 @@ public Boolean atomic_mul(String spacename, Object key, Map<String, Object> attr
return (Boolean) async_atomic_mul(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_atomic_mul(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_atomic_mul(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand All @@ -237,7 +233,6 @@ public Boolean atomic_div(String spacename, Object key, Map<String, Object> attr
return (Boolean) async_atomic_div(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_atomic_div(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_atomic_div(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand Down Expand Up @@ -274,7 +269,6 @@ public Boolean atomic_and(String spacename, Object key, Map<String, Object> attr
return (Boolean) async_atomic_and(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_atomic_and(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_atomic_and(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand All @@ -293,7 +287,6 @@ public Boolean atomic_or(String spacename, Object key, Map<String, Object> attri
return (Boolean) async_atomic_or(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_atomic_or(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_atomic_or(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand Down Expand Up @@ -366,7 +359,6 @@ public Boolean string_prepend(String spacename, Object key, Map<String, Object>
return (Boolean) async_string_prepend(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_string_prepend(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_string_prepend(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand All @@ -385,7 +377,6 @@ public Boolean string_append(String spacename, Object key, Map<String, Object> a
return (Boolean) async_string_append(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_string_append(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_string_append(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand All @@ -404,7 +395,6 @@ public Boolean list_lpush(String spacename, Object key, Map<String, Object> attr
return (Boolean) async_list_lpush(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_list_lpush(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_list_lpush(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand All @@ -423,7 +413,6 @@ public Boolean list_rpush(String spacename, Object key, Map<String, Object> attr
return (Boolean) async_list_rpush(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_list_rpush(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_list_rpush(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand Down Expand Up @@ -514,7 +503,6 @@ public Boolean document_rename(String spacename, Object key, Map<String, Object>
return (Boolean) async_document_rename(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_document_rename(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_document_rename(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand All @@ -533,7 +521,6 @@ public Boolean document_unset(String spacename, Object key, Map<String, Object>
return (Boolean) async_document_unset(spacename, key, attributes).waitForIt();
}


public native Deferred async_cond_document_unset(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException;
public Boolean cond_document_unset(String spacename, Object key, Map<String, Object> predicates, Map<String, Object> attributes) throws HyperDexClientException
{
Expand Down
Loading

0 comments on commit 5e0d18a

Please sign in to comment.