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.*;
10 import org.yaz4j.util.Unstable;
17 public class AsyncConnection extends Connection {
18 private ResultSet lastResultSet;
20 //make sure error is only handled once
21 boolean errorHandled = false;
26 public interface SearchHandler {
27 public void handle(ResultSet rs);
30 public interface RecordHandler {
31 public void handle(Record r);
34 public interface ErrorHandler {
35 public void handle(ZoomException e);
38 public AsyncConnection(String host, int port) {
40 ZOOM_connection_option_set(zoomConnection, "async", "1");
45 public ResultSet search(Query query) throws ZoomException {
47 lastResultSet = super.search(query);
51 public AsyncConnection onSearch(SearchHandler sh) {
56 public AsyncConnection onRecord(RecordHandler rh) {
61 public AsyncConnection onError(ErrorHandler eh) {
66 public AsyncConnection onRecordError(ErrorHandler reh) {
71 //actuall handler, pkg-private
76 if (sh != null) sh.handle(lastResultSet);
80 //TODO clone the record to detach it from the result set
82 if (rh != null) rh.handle(lastResultSet.getRecord(lastResultSet.asyncRecordOffset));
83 } catch (ZoomException ex) {
84 if (reh != null) reh.handle(ex);
86 lastResultSet.asyncRecordOffset++;
93 ZoomException err = ExceptionUtil.getError(zoomConnection, host, port);