Skip to content

Commit

Permalink
First steps into proper java bindings and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Mast committed Feb 21, 2015
1 parent 3adc314 commit 073a718
Show file tree
Hide file tree
Showing 15 changed files with 1,378 additions and 221 deletions.
87 changes: 74 additions & 13 deletions bindings/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ def CTYPEOF(x):
else:
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

def generate_client_prototype(x):
if x.form is bindings.MicrotransactionCall:
return ''
Expand Down Expand Up @@ -160,15 +190,9 @@ def generate_microtransaction_definition(x):
if not (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'))
elif x.form == bindings.Iterator:
func += 'Java_org_hyperdex_client_Client_{0}(JNIEnv* env, jobject obj'.format(x.name.replace('_', '_1'))
elif x.form == bindings.MicrotransactionCall:
func += 'Java_org_hyperdex_client_Client_{0}(JNIEnv* env, jobject obj'.format(x.name.replace('_', '_1'))
else:
assert False
func = 'JNIEXPORT HYPERDEX_API jint JNICALL\n'
func += 'Java_org_hyperdex_client_Client_{0}(JNIEnv* env, jobject obj'.format(x.name.replace('_', '_1'))

for arg in x.args_in:
func += ', ' + CTYPEOF(arg) + ' ' + arg.__name__.lower()
func += ')\n{\n'
Expand All @@ -187,10 +211,9 @@ def generate_client_definition(x):
func += 'Java_org_hyperdex_client_Client_async_1{0}(JNIEnv* env, jobject obj'.format(x.name.replace('_', '_1'))
elif x.form == bindings.Iterator:
func += 'Java_org_hyperdex_client_Client_{0}(JNIEnv* env, jobject obj'.format(x.name.replace('_', '_1'))
elif x.form == bindings.MicrotransactionCall:
func += 'Java_org_hyperdex_client_Client_{0}(JNIEnv* env, jobject obj'.format(x.name.replace('_', '_1'))
else:
assert False
raise RuntimeError('Unknown function type ' + str(x.form))

for arg in x.args_in:
func += ', ' + CTYPEOF(arg) + ' ' + arg.__name__.lower()
func += ')\n{\n'
Expand Down Expand Up @@ -286,10 +309,18 @@ def generate_client_java():
fout.write('\n'.join([generate_client_prototype(c) for c in bindings.Client]))
fout.write('}\n')
fout.flush()
fout = open(os.path.join(BASE, 'bindings/java/org/hyperdex/client/Microtransaction.java'), 'w')
fout.write(bindings.copyright('*', '2015'))
fout.write(bindings.java.MICROTRANSACTION_HEAD)
fout.write('\n'.join([generate_microtransaction_prototype(c) for c in bindings.Client]))
fout.write('}\n')
fout.flush()
os.system('cd bindings/java && javac -cp . org/hyperdex/client/Client.java')
os.system('cd bindings/java && javah -cp . org.hyperdex.client.Client')
os.system('cd bindings/java && javah -cp . org.hyperdex.client.Client')
os.system('cd bindings/java && javah -cp . org.hyperdex.client.Client')
os.system('cd bindings/java && javac -cp . org/hyperdex/client/Microtransaction.java')
os.system('cd bindings/java && javah -cp . org.hyperdex.client.Microtransaction')
os.system('cd bindings/java && javah -cp . org.hyperdex.client.Deferred')
os.system('cd bindings/java && javah -cp . org.hyperdex.client.GreaterEqual')
os.system('cd bindings/java && javah -cp . org.hyperdex.client.GreaterThan')
Expand All @@ -307,17 +338,42 @@ def generate_client_java():
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 = 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]))

def generate_client_doc():
fout = open(os.path.join(BASE, 'doc/java/client/ops.tex'), 'w')
fout.write(bindings.copyright('%', '2014'))
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 __name__ == '__main__':
generate_client_java()
generate_client_doc()

MICROTRANSACTION_HEAD = '''
/* This file is generated by bindings/java.py */
package org.hyperdex.client;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
public class Microtransaction
{
protected Microtransaction(Client client, String space)
{
this._create(client, space);
}
private native void _create(Client client, String space);
'''

JAVA_HEAD = '''
/* This file is generated by bindings/java.py */
Expand Down Expand Up @@ -362,6 +418,11 @@ def generate_client_doc():
super.finalize();
}
}
public Microtransaction initMicrotransaction(String space)
{
return new Microtransaction(this, space);
}
public synchronized void destroy()
{
Expand Down
5 changes: 5 additions & 0 deletions bindings/java/org/hyperdex/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ protected void finalize() throws Throwable
super.finalize();
}
}

public Microtransaction initMicrotransaction(String space)
{
return new Microtransaction(this, space);
}

public synchronized void destroy()
{
Expand Down
186 changes: 186 additions & 0 deletions bindings/java/org/hyperdex/client/Microtransaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/* Copyright (c) 2015, Cornell University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of HyperDex nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/* This file is generated by bindings/java.py */

package org.hyperdex.client;

import java.util.List;
import java.util.Map;
import java.util.HashMap;

public class Microtransaction
{
protected Microtransaction(Client client, String space)
{
this._create(client, space);
}

private native void _create(Client client, String space);




public native Iterator uxact_put(Microtransaction microtransaction, Map<String, Object> attributes);









public native Iterator uxact_atomic_add(Microtransaction microtransaction, Map<String, Object> attributes);




public native Iterator uxact_atomic_sub(Microtransaction microtransaction, Map<String, Object> attributes);




public native Iterator uxact_atomic_mul(Microtransaction microtransaction, Map<String, Object> attributes);




public native Iterator uxact_atomic_div(Microtransaction microtransaction, Map<String, Object> attributes);







public native Iterator uxact_atomic_and(Microtransaction microtransaction, Map<String, Object> attributes);




public native Iterator uxact_atomic_or(Microtransaction microtransaction, Map<String, Object> attributes);













public native Iterator uxact_string_prepend(Microtransaction microtransaction, Map<String, Object> attributes);




public native Iterator uxact_string_append(Microtransaction microtransaction, Map<String, Object> attributes);




public native Iterator uxact_list_lpush(Microtransaction microtransaction, Map<String, Object> attributes);




public native Iterator uxact_list_rpush(Microtransaction microtransaction, Map<String, Object> attributes);
















public native Iterator uxact_document_rename(Microtransaction microtransaction, Map<String, Object> attributes);




public native Iterator uxact_document_unset(Microtransaction microtransaction, Map<String, Object> attributes);
















































}
2 changes: 1 addition & 1 deletion bindings/java/org_hyperdex_client_Client.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2013, Cornell University
/* Copyright (c) 2013-2015, Cornell University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
Loading

0 comments on commit 073a718

Please sign in to comment.