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;
}
}
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;
}
}
Aggregations