Remove implicit conversion because of side effect

This commit is contained in:
Lee moon soo 2015-04-11 11:15:05 +09:00
parent 34fa298151
commit 04d7175968
5 changed files with 54 additions and 22 deletions

View file

@ -464,16 +464,6 @@ public class SparkInterpreter extends Interpreter {
}
}
}
// add some implicit conversion
intp.interpret("implicit def watcherConversion(watcher: (Object, Object) => Unit):"
+ "org.apache.zeppelin.display.AngularObjectWatcher = {"
+ " new org.apache.zeppelin.display.AngularObjectWatcher() {"
+ " def watch(before:Object, after:Object) = {"
+ " watcher(before, after)"
+ " }"
+ " }"
+ "}");
}
private List<File> currentClassPath() {

View file

@ -46,6 +46,7 @@ import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.spark.dep.DependencyResolver;
import scala.Tuple2;
import scala.Unit;
import scala.collection.Iterable;
/**
@ -502,6 +503,32 @@ public class ZeppelinContext extends HashMap<String, Object> {
}
}
public void angularWatch(String name,
final scala.Function2<Object, Object, Unit> func) {
AngularObjectWatcher w = new AngularObjectWatcher(getInterpreterContext()) {
@Override
public void watch(Object oldObject, Object newObject,
InterpreterContext context) {
func.apply(newObject, newObject);
}
};
angularWatch(name, w);
}
public void angularWatch(
String name,
final scala.Function3<Object, Object, InterpreterContext, Unit> func) {
AngularObjectWatcher w = new AngularObjectWatcher(getInterpreterContext()) {
@Override
public void watch(Object oldObject, Object newObject,
InterpreterContext context) {
func.apply(oldObject, newObject, context);
}
};
angularWatch(name, w);
}
public void angularUnwatch(String name, AngularObjectWatcher w) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
if (registry.get(name) != null) {

View file

@ -17,9 +17,21 @@
package org.apache.zeppelin.display;
import org.apache.zeppelin.interpreter.InterpreterContext;
/**
*
*/
public interface AngularObjectWatcher {
public void watch(Object oldObject, Object newObject);
public abstract class AngularObjectWatcher {
private InterpreterContext context;
public AngularObjectWatcher(InterpreterContext context) {
this.context = context;
}
void watch(Object oldObject, Object newObject) {
watch(oldObject, newObject, context);
}
public abstract void watch(Object oldObject, Object newObject, InterpreterContext context);
}

View file

@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.junit.Test;
public class AngularObjectTest {
@ -61,9 +62,9 @@ public class AngularObjectTest {
}
});
ao.addWatcher(new AngularObjectWatcher() {
ao.addWatcher(new AngularObjectWatcher(null) {
@Override
public void watch(Object oldObject, Object newObject) {
public void watch(Object oldObject, Object newObject, InterpreterContext context) {
onWatch.incrementAndGet();
}
});

View file

@ -29,7 +29,7 @@ import org.apache.zeppelin.interpreter.InterpreterPropertyBuilder;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
public class MockInterpreterAngular extends Interpreter implements AngularObjectWatcher {
public class MockInterpreterAngular extends Interpreter {
static {
Interpreter.register(
"angularTest",
@ -72,7 +72,15 @@ public class MockInterpreterAngular extends Interpreter implements AngularObject
if (cmd.equals("add")) {
registry.add(name, value);
registry.get(name).addWatcher(this);
registry.get(name).addWatcher(new AngularObjectWatcher(null) {
@Override
public void watch(Object oldObject, Object newObject,
InterpreterContext context) {
numWatch.incrementAndGet();
}
});
} else if (cmd.equalsIgnoreCase("update")) {
registry.get(name).set(value);
} else if (cmd.equals("remove")) {
@ -106,10 +114,4 @@ public class MockInterpreterAngular extends Interpreter implements AngularObject
public List<String> completion(String buf, int cursor) {
return null;
}
@Override
public void watch(Object oldObject, Object newObject) {
numWatch.incrementAndGet();
}
}