if (resultMessage == null) {
throw new IOException(String.format("Message received response timeoutConnection (%s s)", this.timeoutConnection));
}
if (resultMessage instanceof ScriptResponseMessage) {
final ScriptResponseMessage msg = (ScriptResponseMessage) resultMessage;
// when rexster returns an iterable it's read out of the unpacker as a single object much like a single
// vertex coming back from rexster. basically, this is the difference between g.v(1) and g.v(1).map.
// the latter returns an iterable essentially putting a list inside of the results list here on the
// client side. the idea here is to normalize all results to a list on the client side, and therefore,
// iterables like those from g.v(1).map need to be unrolled into the results list. Prefer this to
// doing it on the server, because the server should return what is asked of it, in case other clients
// want to process this differently.
final List<T> results = new ArrayList<T>();
if (msg.Results.get() instanceof Iterable) {
final Iterator<T> itty = ((Iterable) msg.Results.get()).iterator();
while(itty.hasNext()) {
results.add(itty.next());
}
} else {
results.add((T)msg.Results.get());
}
return results;
} else if (resultMessage instanceof ScriptResponseMessage) {
final ScriptResponseMessage msg = (ScriptResponseMessage) resultMessage;
final List<T> results = new ArrayList<T>();
for (String line : (String[]) msg.Results.get()) {
results.add((T) line);
}
return results;