mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Remove unnecessary type information
This commit is contained in:
parent
88fd6357db
commit
8076098361
2 changed files with 21 additions and 39 deletions
|
|
@ -19,7 +19,6 @@ package org.apache.zeppelin.display;
|
|||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.apache.zeppelin.scheduler.ExecutorFactory;
|
||||
|
|
@ -32,44 +31,17 @@ import org.slf4j.LoggerFactory;
|
|||
* @param <T>
|
||||
*/
|
||||
public class AngularObject<T> {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static enum AngularObjectType {
|
||||
STRING,
|
||||
MAP,
|
||||
FUNCTION
|
||||
};
|
||||
|
||||
private String name;
|
||||
private T object;
|
||||
private transient AngularObjectListener listener;
|
||||
private transient List<AngularObjectWatcher> watchers
|
||||
= new LinkedList<AngularObjectWatcher>();
|
||||
private AngularObjectType type;
|
||||
|
||||
protected AngularObject(String name, T o,
|
||||
AngularObjectListener listener) {
|
||||
this.name = name;
|
||||
this.listener = listener;
|
||||
object = o;
|
||||
type = checkType();
|
||||
}
|
||||
|
||||
public AngularObjectType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public AngularObjectType checkType() {
|
||||
if (object == null) {
|
||||
return AngularObjectType.STRING;
|
||||
} else if (object instanceof Map) {
|
||||
return AngularObjectType.MAP;
|
||||
} else if (object instanceof String) {
|
||||
return AngularObjectType.STRING;
|
||||
}
|
||||
return AngularObjectType.STRING;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import org.apache.thrift.server.TThreadPoolServer;
|
|||
import org.apache.thrift.transport.TServerSocket;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
import org.apache.zeppelin.display.AngularObject;
|
||||
import org.apache.zeppelin.display.AngularObject.AngularObjectType;
|
||||
import org.apache.zeppelin.display.AngularObjectRegistry;
|
||||
import org.apache.zeppelin.display.AngularObjectRegistryListener;
|
||||
import org.apache.zeppelin.display.GUI;
|
||||
|
|
@ -445,16 +444,27 @@ public class RemoteInterpreterServer
|
|||
return;
|
||||
}
|
||||
|
||||
if (ao.getType() == AngularObjectType.STRING) {
|
||||
String value = gson.fromJson(object, String.class);
|
||||
ao.set(value, false);
|
||||
} else if (ao.getType() == AngularObjectType.MAP) {
|
||||
Map<String, Object> value = gson.fromJson(object,
|
||||
new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
ao.set(value, false);
|
||||
} else {
|
||||
logger.error("Update angular object type {} not supported", ao.getType());
|
||||
if (object == null) {
|
||||
ao.set(null, false);
|
||||
return;
|
||||
}
|
||||
|
||||
Object oldObject = ao.get();
|
||||
if (oldObject != null) { // first try with previous object's type
|
||||
Object value;
|
||||
try {
|
||||
value = gson.fromJson(object, oldObject.getClass());
|
||||
ao.set(value, false);
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
// no luck
|
||||
}
|
||||
}
|
||||
|
||||
// Generic java object type for json.
|
||||
Map<String, Object> value = gson.fromJson(object,
|
||||
new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
ao.set(value, false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue