try {
IScannerStateManager.ScanStatus status = null;
if (arg instanceof IScannerStateManager.ScanStatus) {
status = (IScannerStateManager.ScanStatus) arg;
}
DocumentScanner scanner = null;
if (o instanceof DocumentScanner) {
scanner = (DocumentScanner) o;
} else {
System.out
.println("Observable object was not a DocumentScanner. It was a " + (o == null ? "null" : o.getClass().getName()));
}
if (status != null) {
// System.out.println("DEBUG: Received update with status " + status.name());
switch (status) {
case NEW:
break;
case RUNNING:
// System.out.println("DEBUG: branched to running status...");
if (scanner != null) {
if (scanner.isTrackTokenLocation()) {
Map tokenLocationMap = scanner.getTokenLocationMap();
int tlsize = tokenLocationMap.size();
if (tlsize >= 1024) {
// System.out.println("Processed " + scanner.getDocCount() + " documents so far, " + scanner.getItemCount()
// + " items and " + scanner.getTokenCount());
synchronized (tokenLocationMap) {
saveTokenLocationMap(scanner.getStateManagerKey(), tokenLocationMap, scanner);
tokenLocationMap.clear();
}
}
} else {
// System.out.println("TokenLocation not being tracked by scanner");
}
if (scanner.isTrackNameLocation()) {
Map nameLocationMap = scanner.getNameLocationMap();
int nlsize = nameLocationMap.size();
if (nlsize >= 128) {
synchronized (nameLocationMap) {
saveTokenLocationMap(scanner.getStateManagerKey(), nameLocationMap, scanner);
nameLocationMap.clear();
}
}
}
} else {
System.out.println("Scanner is null from notifications");
}
break;
case COMPLETE:
// System.out.println("DEBUG: branched to complete status...");
if (scanner != null) {
if (scanner.isTrackTokenLocation()) {
Map tokenLocationMap = scanner.getTokenLocationMap();
synchronized (tokenLocationMap) {
saveTokenLocationMap(scanner.getStateManagerKey(), tokenLocationMap, scanner);
tokenLocationMap.clear();
}
// System.out.println("Completed " + scanner.getDocCount() + " documents at completion, " + scanner.getItemCount()
// + " items and " + scanner.getTokenCount());
} else {
// System.out.println("TokenLocation not being tracked by scanner");
}
if (scanner.isTrackNameLocation()) {
Map nameLocationMap = scanner.getNameLocationMap();
synchronized (nameLocationMap) {
saveNameLocationMap(scanner.getStateManagerKey(), nameLocationMap, scanner);
nameLocationMap.clear();
}
}
} else {
System.out.println("ALERT! Scanner was null??");