From: Jakub Skoczen Date: Tue, 10 Nov 2015 10:41:00 +0000 (+0100) Subject: Move async API to it's own package X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=d1467c0623a5b34483bf9c79214b9892dc6bc077;p=yaz4j-moved-to-github.git Move async API to it's own package --- diff --git a/src/main/java/org/yaz4j/AsyncConnection.java b/src/main/java/org/yaz4j/AsyncConnection.java deleted file mode 100644 index d8e9d0c..0000000 --- a/src/main/java/org/yaz4j/AsyncConnection.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 1995-2015, Index Data - * All rights reserved. - * See the file LICENSE for details. - */ -package org.yaz4j; - -import org.yaz4j.exception.ZoomException; -import static org.yaz4j.jni.yaz4jlib.*; -import org.yaz4j.util.Unstable; - -/** - * - * @author jakub - */ -@Unstable -public class AsyncConnection extends Connection { - private ResultSet lastResultSet; - ErrorHandler eh; - //make sure error is only handled once - boolean errorHandled = false; - int handledRecordOffset = 0; - ErrorHandler reh; - SearchHandler sh; - RecordHandler rh; - - public interface SearchHandler { - public void handle(ResultSet rs); - } - - public interface RecordHandler { - public void handle(Record r); - } - - public interface ErrorHandler { - public void handle(ZoomException e); - } - - public AsyncConnection(String host, int port) { - super(host, port); - ZOOM_connection_option_set(zoomConnection, "async", "1"); - closed = false; - } - - @Override - public ResultSet search(Query query) throws ZoomException { - errorHandled = false; - lastResultSet = super.search(query); - return null; - } - - public AsyncConnection onSearch(SearchHandler sh) { - this.sh = sh; - return this; - } - - public AsyncConnection onRecord(RecordHandler rh) { - this.rh = rh; - return this; - } - - public AsyncConnection onError(ErrorHandler eh) { - this.eh = eh; - return this; - } - - public AsyncConnection onRecordError(ErrorHandler reh) { - this.reh = reh; - return this; - } - - //actuall handler, pkg-private - - void handleSearch() { - handleError(); - //handle search - if (sh != null) sh.handle(lastResultSet); - } - - void handleRecord() { - //TODO clone the record to detach it from the result set - try { - if (rh != null) rh.handle(lastResultSet.getRecord(handledRecordOffset)); - } catch (ZoomException ex) { - if (reh != null) reh.handle(ex); - } finally { - handledRecordOffset++; - } - } - - void handleError() { - //handle error - if (!errorHandled) { - ZoomException err = getZoomException(); - if (err != null) { - if (eh != null) { - eh.handle(err); - errorHandled = true; - } - } - } - } - -} diff --git a/src/main/java/org/yaz4j/AsyncConnections.java b/src/main/java/org/yaz4j/AsyncConnections.java deleted file mode 100644 index 5eb0c49..0000000 --- a/src/main/java/org/yaz4j/AsyncConnections.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 1995-2015, Index Data - * All rights reserved. - * See the file LICENSE for details. - */ -package org.yaz4j; - -import java.util.ArrayList; -import java.util.List; -import org.yaz4j.jni.SWIGTYPE_p_p_ZOOM_connection_p; -import static org.yaz4j.jni.yaz4jlib.*; -import static java.lang.System.out; -import org.yaz4j.util.Unstable; - -/** - * - * @author jakub - */ -@Unstable -public class AsyncConnections { - private List conns = new ArrayList(); - - public void add(AsyncConnection conn) { - conns.add(conn); - } - - public List getConnections() { - return conns; - } - - public void start() { - SWIGTYPE_p_p_ZOOM_connection_p c_conns = new_zoomConnectionArray(conns.size()); - try { - for (int i=0; i conns = new ArrayList(); + + public void add(AsyncConnection conn) { + conns.add(conn); + } + + public List getConnections() { + return conns; + } + + public void start() { + SWIGTYPE_p_p_ZOOM_connection_p c_conns = new_zoomConnectionArray(conns.size()); + try { + for (int i=0; i