Search in sources :

Example 11 with RemoteInterpreterEvent

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent in project zeppelin by apache.

the class RemoteInterpreterEventClient method readResource.

@Override
public Object readResource(ResourceId resourceId) {
    logger.debug("Request Read Resource {} from ZeppelinServer", resourceId.getName());
    synchronized (getResourceResponse) {
        // wait for previous response consumed
        while (getResourceResponse.containsKey(resourceId)) {
            try {
                getResourceResponse.wait();
            } catch (InterruptedException e) {
                logger.warn(e.getMessage(), e);
            }
        }
        // send request
        Gson gson = new Gson();
        sendEvent(new RemoteInterpreterEvent(RemoteInterpreterEventType.RESOURCE_GET, gson.toJson(resourceId)));
        // wait for response
        while (!getResourceResponse.containsKey(resourceId)) {
            try {
                getResourceResponse.wait();
            } catch (InterruptedException e) {
                logger.warn(e.getMessage(), e);
            }
        }
        Object o = getResourceResponse.remove(resourceId);
        getResourceResponse.notifyAll();
        return o;
    }
}
Also used : RemoteInterpreterEvent(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent) Gson(com.google.gson.Gson) AngularObject(org.apache.zeppelin.display.AngularObject)

Example 12 with RemoteInterpreterEvent

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent in project zeppelin by apache.

the class RemoteInterpreterEventClient method invokeMethod.

/**
   * Invoke method and save result in resourcePool as another resource
   * @param resourceId
   * @param methodName
   * @param paramTypes
   * @param params
   * @return
   */
@Override
public Object invokeMethod(ResourceId resourceId, String methodName, Class[] paramTypes, Object[] params) {
    logger.debug("Request Invoke method {} of Resource {}", methodName, resourceId.getName());
    InvokeResourceMethodEventMessage invokeMethod = new InvokeResourceMethodEventMessage(resourceId, methodName, paramTypes, params, null);
    synchronized (getInvokeResponse) {
        // wait for previous response consumed
        while (getInvokeResponse.containsKey(invokeMethod)) {
            try {
                getInvokeResponse.wait();
            } catch (InterruptedException e) {
                logger.warn(e.getMessage(), e);
            }
        }
        // send request
        Gson gson = new Gson();
        sendEvent(new RemoteInterpreterEvent(RemoteInterpreterEventType.RESOURCE_INVOKE_METHOD, gson.toJson(invokeMethod)));
        // wait for response
        while (!getInvokeResponse.containsKey(invokeMethod)) {
            try {
                getInvokeResponse.wait();
            } catch (InterruptedException e) {
                logger.warn(e.getMessage(), e);
            }
        }
        Object o = getInvokeResponse.remove(invokeMethod);
        getInvokeResponse.notifyAll();
        return o;
    }
}
Also used : RemoteInterpreterEvent(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent) Gson(com.google.gson.Gson) AngularObject(org.apache.zeppelin.display.AngularObject)

Aggregations

RemoteInterpreterEvent (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent)12 HashMap (java.util.HashMap)7 AngularObject (org.apache.zeppelin.display.AngularObject)6 Gson (com.google.gson.Gson)2 RemoteZeppelinServerResource (org.apache.zeppelin.interpreter.RemoteZeppelinServerResource)2 TypeToken (com.google.gson.reflect.TypeToken)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 TException (org.apache.thrift.TException)1 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)1 InterpreterContextRunner (org.apache.zeppelin.interpreter.InterpreterContextRunner)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 RemoteInterpreterEventType (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventType)1 Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)1 ResourceId (org.apache.zeppelin.resource.ResourceId)1 ResourceSet (org.apache.zeppelin.resource.ResourceSet)1