Ingest Result Handlers

When you ingest a document using the Add, Replace, Remove or Update methods, the ingest command is placed in a queue and the method returns immediately. ConnectorLib Java takes care of batching, sending the commands, and dealing with any transitory problems communicating with the target.

As a result, the Add, Replace, Remove and Update methods never fail, even if there is a problem ingesting a document. To find out whether each document was ingested successfully, you can register an Ingest result handler:

       task.getIngester().addResultHandler(
                 resultHandlerObject,
                 "handlerMethodName");

The result handler is called whenever a document is successfully ingested or when ingestion fails for a document. A simple result handler is shown here:

public static class IngestResultHandler
{
     private final SynchronizeTask task;

     public IngestResultHandler(SynchronizeTask task)
     {
          this.task = task;
     }

     public void handler(DocInfo docInfo, Ingester.TaskType type, boolean success)
     {
          if (success)
          { 
               task.getLog().writeln(Log.NORMAL, "Document "
                       + docInfo.getDoc().getReference()
                       + " ingest " + type + " succeeded!");
          } 
          else
          { 
               task.getLog().writeln(Log.ERROR, "Ingestion failed for "
                       + docInfo.getDoc().getReference());
          }
     }
}

Ingest result handlers are useful when you want to update state information only when documents are ingested successfully. An example of a connector using an ingest result handler for this purpose is included in Make an Incremental Synchronize Action.