FetchedDatum fd = new FetchedDatum(entry);
// Get the fetch status that we hang on the end of the tuple,
// after all of the FetchedDatum fields.
Object result = entry.getObject(_fieldPos);
StatusDatum status;
// Note: Here we share the payload of the FetchedDatum with the
// StatusDatum we're about to emit, but since we let go after we
// emit, there shouldn't be an issue with this sharing.
if (result instanceof String) {
UrlStatus urlStatus = UrlStatus.valueOf((String)result);
if (urlStatus == UrlStatus.FETCHED) {
status = new StatusDatum(fd.getUrl(), fd.getHeaders(), fd.getHostAddress(), fd.getPayload());
} else {
status = new StatusDatum(fd.getUrl(), urlStatus, fd.getPayload());
}
} else if (result instanceof BaseFetchException) {
status = new StatusDatum(fd.getUrl(), (BaseFetchException)result, fd.getPayload());
} else {
throw new RuntimeException("Unknown type for fetch status field: " + result.getClass());
}
funcCall.getOutputCollector().add(BixoPlatform.clone(status.getTuple(), process));
}