Skip to content

Commit

Permalink
Restore java code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Mast committed Feb 23, 2015
1 parent 5e0d18a commit 48ddc78
Show file tree
Hide file tree
Showing 8 changed files with 533 additions and 1,850 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ EXTRA_DIST += bindings/java/org/hyperdex/ycsb/HyperDex.java
EXTRA_DIST += test/java/.exists

# Client
noinst_HEADERS += bindings/java/client-util.h
noinst_HEADERS += bindings/java/org_hyperdex_client_Client.h
noinst_HEADERS += bindings/java/org_hyperdex_client_Deferred.h
noinst_HEADERS += bindings/java/org_hyperdex_client_GreaterEqual.h
Expand Down
41 changes: 31 additions & 10 deletions bindings/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def CTYPEOF(x):
raise RuntimeError('Unknown type: ' + str(x))

def generate_microtransaction_prototype(x):
return ' public native Integer {0}(Map<String,Object> attrs) throws HyperDexClientException;\n'.format(x.name)
return ' public native int {0}(Map<String,Object> attrs) throws HyperDexClientException;\n'.format(x.name.replace("uxact_", ""))

def generate_client_prototype(x):
args_list = ', '.join([JTYPEOF(arg) + ' ' + arg.__name__.lower() for arg in x.args_in])
Expand Down Expand Up @@ -158,15 +158,27 @@ def generate_workers(xs):

def generate_microtransaction_definition(x):
func = 'JNIEXPORT HYPERDEX_API jint JNICALL\n'
func += 'Java_org_hyperdex_client_Microtransaction_{0}(JNIEnv* env '.format(x.name.replace('_', '_1'))
func += 'Java_org_hyperdex_client_Microtransaction_{0}(JNIEnv* env '.format(x.name.replace('uxact_', '').replace('_', '_1'))

for arg in x.args_in:
func += ', ' + CTYPEOF(arg) + ' ' + arg.__name__.lower()
func += ')\n{\n'
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'

# Function Body
func += ' jobject client;\n'
func += ' struct hyperdex_client* client_ptr;\n'
func += ' struct hyperdex_client_microtransaction* uxact;\n'
func += ' const struct hyperdex_client_attribute *_attrs;\n'
func += ' struct hyperdex_ds_arena *arena;\n'
func += ' size_t _attrs_sz;\n\n'
func += ' client = hyperdex_uxact_get_client(env, microtransaction);\n'
func += ' client_ptr = hyperdex_uxact_get_client_ptr(env, microtransaction);\n'
func += ' uxact = hyperdex_uxact_get_uxact_ptr(env, microtransaction);\n'
func += ' arena = hyperdex_uxact_get_arena_ptr(env, microtransaction);\n'
func += ' hyperdex_java_client_convert_attributes(env, client, arena, attributes, &_attrs, &_attrs_sz);\n'
func += ' return (jint)hyperdex_client_{0}(client_ptr, uxact, _attrs, _attrs_sz);\n'.format(x.name)

func += '}\n'
return func

def generate_client_definition(x):
Expand Down Expand Up @@ -276,7 +288,7 @@ def generate_client_java():
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'.join([generate_microtransaction_prototype(c) for c in bindings.Client if c.form is bindings.MicrotransactionCall]))
fout.write('}\n')
fout.flush()
os.system('cd bindings/java && javac -cp . org/hyperdex/client/Client.java')
Expand Down Expand Up @@ -305,7 +317,6 @@ def generate_client_java():
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 if c.form is bindings.MicrotransactionCall]))

def generate_client_doc():
Expand All @@ -332,11 +343,21 @@ def generate_client_doc():
{
protected Microtransaction(Client client, String space)
{
this._create(client, space);
this.client = client;
this._create(space);
}
private native void _create(Client client, String space);
private Client client;
private long uxact_ptr;
private long status_ptr;
private native void _create(String space);
private native void _destroy();
/* cached IDs */
private static native void initialize();
private static native void terminate();
'''

JAVA_HEAD = '''
Expand Down
50 changes: 50 additions & 0 deletions bindings/java/client-util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* 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.
*/

#ifndef JAVA_UTIL_H
#define JAVA_UTIL_H

#include <jni.h>

/* HyperDex */
#include <hyperdex/client.h>
#include <hyperdex/datastructures.h>

const char*
hyperdex_java_client_convert_cstring(JNIEnv* env,
struct hyperdex_ds_arena* arena,
jobject str);

int
hyperdex_java_client_convert_attributes(JNIEnv* env, jobject client,
struct hyperdex_ds_arena* arena,
jobject x,
const struct hyperdex_client_attribute** _attrs,
size_t* _attrs_sz);

#endif
Loading

0 comments on commit 48ddc78

Please sign in to comment.