Permalink
Browse files

Refactoring towards input buffer

  • Loading branch information...
1 parent d41a2ad commit 5375d567480b030cf97521b7183e776728461367 Greg Fodor committed Mar 12, 2012
@@ -0,0 +1,13 @@
+package org.cascading.js;
+
+public enum FieldSet {
+ ARGS(0),
+ GROUP(1),
+ RESULT(2);
+
+ public final int idx;
+
+ FieldSet(final int idx) {
+ this.idx = idx;
+ }
+}
@@ -0,0 +1,16 @@
+package org.cascading.js;
+
+public enum JSType {
+ INT(0),
+ LONG(1),
+ BOOL(2),
+ DOUBLE(3),
+ DATE(4),
+ STRING(5);
+
+ public final int idx;
+
+ JSType(final int idx) {
+ this.idx = idx;
+ }
+}
@@ -47,7 +47,7 @@ public void operate(FlowProcess flowProcess, BufferCall<V8OperationContext> call
ctx.addArgument(next);
if (ctx.isFull()) {
- ctx.flush();
+ ctx.flushToV8();
}
timeSetArg += (System.currentTimeMillis() - t0);
@@ -65,7 +65,7 @@ public void prepare( FlowProcess flowProcess, OperationCall<V8OperationContext>
public void cleanup(cascading.flow.FlowProcess flowProcess, cascading.operation.OperationCall<V8OperationContext> call) {
super.cleanup(flowProcess, call);
call.getContext().closeGroup();
- call.getContext().flush();
+ call.getContext().flushToV8();
System.out.println("Buffer time: " + (System.currentTimeMillis() - t0) + " " + timeInInvoke + " " + timeSetArg + " " + timeSetGroup);
call.getContext().getEnvironment().shutdown();
}
@@ -7,6 +7,7 @@
import cascading.tuple.TupleEntryCollector;
import lu.flier.script.V8Array;
import lu.flier.script.V8Object;
+import org.cascading.js.JSType;
import org.cascading.js.util.Environment;
import javax.script.ScriptException;
@@ -63,11 +64,11 @@ public void prepare( FlowProcess flowProcess, OperationCall<V8OperationContext>
V8Object v8PipeClass = (V8Object)env.extractObject("__v8PipeClass");
env.evaluateScript("delete __v8PipeClass");
- Map<String, V8TupleBuffer.JSType> typeMap = new HashMap<String, V8TupleBuffer.JSType>();
- typeMap.put("word", V8TupleBuffer.JSType.STRING);
- typeMap.put("line", V8TupleBuffer.JSType.STRING);
- typeMap.put("count", V8TupleBuffer.JSType.INT);
- typeMap.put("offset", V8TupleBuffer.JSType.STRING);
+ Map<String, JSType> typeMap = new HashMap<String, JSType>();
+ typeMap.put("word", JSType.STRING);
+ typeMap.put("line", JSType.STRING);
+ typeMap.put("count", JSType.INT);
+ typeMap.put("offset", JSType.STRING);
V8OperationContext ctx = new V8OperationContext(env, v8PipeClass, pipeId, getGroupingFields(),
operationCall.getArgumentFields().subtract(getGroupingFields()), resultFields, typeMap);
@@ -6,13 +6,16 @@
import lu.flier.script.V8Function;
import lu.flier.script.V8Object;
import lu.flier.script.V8ScriptEngine;
+import org.cascading.js.JSType;
import org.cascading.js.util.Environment;
import javax.script.ScriptException;
import java.util.Map;
public class V8OperationContext {
- private V8TupleBuffer tupleBuffer;
+ private V8TupleBuffer outTupleBuffer;
+ private V8TupleBuffer inTupleBuffer;
+
private Environment environment;
private TupleEntryCollector outputEntryCollector;
private V8Function flushToV8;
@@ -21,15 +24,16 @@ public Environment getEnvironment() {
return environment;
}
- public V8OperationContext(Environment environment, V8Object v8PipeClass, int pipeId, Fields groupingFields, Fields argumentFields, Fields resultFields, Map<String, V8TupleBuffer.JSType> typeMap) {
+ public V8OperationContext(Environment environment, V8Object v8PipeClass, int pipeId, Fields groupingFields, Fields argumentFields, Fields resultFields, Map<String, JSType> typeMap) {
this.environment = environment;
V8ScriptEngine eng = environment.getEngine();
- tupleBuffer = new V8TupleBuffer(eng, groupingFields, argumentFields, typeMap);
+ outTupleBuffer = V8TupleBuffer.newOutput(eng, groupingFields, argumentFields, typeMap);
+ inTupleBuffer = V8TupleBuffer.newInput(eng, resultFields, typeMap);
try {
flushToV8 = (V8Function)environment.invokeMethod(v8PipeClass, "get_flush_routine",
- tupleBuffer.getBuffer(), eng.createFunction(this, "flushFromV8"), pipeId);
+ outTupleBuffer.getBuffer(), eng.createFunction(this, "flushFromV8"), pipeId);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (ScriptException e) {
@@ -44,29 +48,29 @@ public void setOutputEntryCollector(TupleEntryCollector out) {
}
public void addArgument(TupleEntry argument) {
- this.tupleBuffer.addArgument(argument);
+ this.outTupleBuffer.addArgument(argument);
}
public void addGroup(TupleEntry group) {
- this.tupleBuffer.addGroup(group);
+ this.outTupleBuffer.addGroup(group);
}
public boolean isFull() {
- return this.tupleBuffer.isFull();
+ return this.outTupleBuffer.isFullForArguments();
}
- public void flush() {
- this.tupleBuffer.fillV8Arrays();
+ public void flushToV8() {
+ this.outTupleBuffer.fillV8Arrays();
flushToV8.invokeVoid();
- this.tupleBuffer.clear();
+ this.outTupleBuffer.clear();
}
public void flushFromV8() {
System.out.println("Flushing from V8");
}
public void closeGroup() {
- this.tupleBuffer.closeGroup();
+ this.outTupleBuffer.closeGroup();
}
}
Oops, something went wrong.

0 comments on commit 5375d56

Please sign in to comment.