Search in sources :

Example 1 with AngularObjectWatcher

use of org.apache.zeppelin.display.AngularObjectWatcher in project zeppelin by apache.

the class ZeppelinContext method angularWatch.

private void angularWatch(String name, String noteId, 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, noteId, w);
}
Also used : AngularObjectWatcher(org.apache.zeppelin.display.AngularObjectWatcher) AngularObject(org.apache.zeppelin.display.AngularObject) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext)

Example 2 with AngularObjectWatcher

use of org.apache.zeppelin.display.AngularObjectWatcher in project zeppelin by apache.

the class MockInterpreterAngular method interpret.

@Override
public InterpreterResult interpret(String st, InterpreterContext context) {
    String[] stmt = st.split(" ");
    String cmd = stmt[0];
    String name = null;
    if (stmt.length >= 2) {
        name = stmt[1];
    }
    String value = null;
    if (stmt.length == 3) {
        value = stmt[2];
    }
    AngularObjectRegistry registry = context.getAngularObjectRegistry();
    if (cmd.equals("add")) {
        registry.add(name, value, context.getNoteId(), null);
        registry.get(name, context.getNoteId(), null).addWatcher(new AngularObjectWatcher(null) {

            @Override
            public void watch(Object oldObject, Object newObject, InterpreterContext context) {
                numWatch.incrementAndGet();
            }
        });
    } else if (cmd.equalsIgnoreCase("update")) {
        registry.get(name, context.getNoteId(), null).set(value);
    } else if (cmd.equals("remove")) {
        registry.remove(name, context.getNoteId(), null);
    }
    try {
        // wait for watcher executed
        Thread.sleep(500);
    } catch (InterruptedException e) {
        logger.error("Exception in MockInterpreterAngular while interpret Thread.sleep", e);
    }
    String msg = registry.getAll(context.getNoteId(), null).size() + " " + Integer.toString(numWatch.get());
    return new InterpreterResult(Code.SUCCESS, msg);
}
Also used : AngularObjectWatcher(org.apache.zeppelin.display.AngularObjectWatcher) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 3 with AngularObjectWatcher

use of org.apache.zeppelin.display.AngularObjectWatcher in project zeppelin by apache.

the class ZeppelinContext method angularWatch.

private void angularWatch(String name, String noteId, 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, noteId, w);
}
Also used : AngularObjectWatcher(org.apache.zeppelin.display.AngularObjectWatcher) AngularObject(org.apache.zeppelin.display.AngularObject) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext)

Aggregations

AngularObjectWatcher (org.apache.zeppelin.display.AngularObjectWatcher)3 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)3 AngularObject (org.apache.zeppelin.display.AngularObject)2 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1