2 * Copyright (c) 1995-2015, Index Data
4 * See the file LICENSE for details.
8 import org.yaz4j.exception.ZoomException;
9 import static org.yaz4j.jni.yaz4jlib.*;
15 public class AsyncConnection extends Connection {
16 private ResultSet lastResultSet;
18 //make sure error is only handled once
19 boolean errorHandled = false;
24 public interface SearchHandler {
25 public void handle(ResultSet rs);
28 public interface RecordHandler {
29 public void handle(Record r);
32 public interface ErrorHandler {
33 public void handle(ZoomException e);
36 public AsyncConnection(String host, int port) {
38 ZOOM_connection_option_set(zoomConnection, "async", "1");
43 public ResultSet search(Query query) throws ZoomException {
45 lastResultSet = super.search(query);
49 public AsyncConnection onSearch(SearchHandler sh) {
54 public AsyncConnection onRecord(RecordHandler rh) {
59 public AsyncConnection onError(ErrorHandler eh) {
64 public AsyncConnection onRecordError(ErrorHandler reh) {
69 //actuall handler, pkg-private
74 if (sh != null) sh.handle(lastResultSet);
78 //TODO clone the record to detach it from the result set
80 if (rh != null) rh.handle(lastResultSet.getRecord(lastResultSet.asyncRecordOffset));
81 } catch (ZoomException ex) {
82 if (reh != null) reh.handle(ex);
84 lastResultSet.asyncRecordOffset++;
91 ZoomException err = ExceptionUtil.getError(zoomConnection, host, port);