import org.yaz4j.util.Unstable;
/**
- *
+ * Represents an asynchronous connection, all methods of this class
+ * (e.g connect, search) are non-blocking.
+ *
+ * Note that async support is missing for scan and extended services at this point.
+ *
* @author jakub
*/
@Unstable
SearchHandler sh;
RecordHandler rh;
+ /**
+ * Invoked immediately in response to the search request.
+ *
+ * Allows to read things the hit count and facets. Records should be read
+ * and processed in the record handler.
+ */
public interface SearchHandler {
public void handle(ResultSet rs);
}
+ /**
+ * Invoked for every retrieved record.
+ */
public interface RecordHandler {
public void handle(Record r);
}
+ /**
+ * Invoked for any protocol or connection level error.
+ */
public interface ErrorHandler {
public void handle(ZoomException e);
}
return null;
}
+ /**
+ * Register a hander for the search response.
+ * @param sh search response handler
+ * @return
+ */
public AsyncConnection onSearch(SearchHandler sh) {
this.sh = sh;
return this;
}
+ /**
+ * Register a handler for each retrieved record.
+ * @param rh record handler
+ * @return
+ */
public AsyncConnection onRecord(RecordHandler rh) {
this.rh = rh;
return this;
}
+ /**
+ * Register a handler for a connection level errors.
+ * @param eh error handler
+ * @return
+ */
public AsyncConnection onError(ErrorHandler eh) {
this.eh = eh;
return this;
}
+ /**
+ * Register a handler for record level errors (e.g decoding).
+ * @param reh record error handler
+ * @return
+ */
public AsyncConnection onRecordError(ErrorHandler reh) {
this.reh = reh;
return this;
import org.yaz4j.util.Unstable;
/**
- *
+ * Allows to group and execute asynchronous connections within an event loop.
+ *
* @author jakub
*/
@Unstable
public class AsyncConnections {
private List<AsyncConnection> conns = new ArrayList<AsyncConnection>();
+ /**
+ * Include async connection in the event loop processing.
+ * @param conn
+ */
public void add(AsyncConnection conn) {
conns.add(conn);
}
+ /**
+ * List all included connections.
+ * @return
+ */
public List<AsyncConnection> getConnections() {
return conns;
}
+ /**
+ * Start the event loop, which effectively executes and processes all
+ * async connections.
+ */
public void start() {
SWIGTYPE_p_p_ZOOM_connection_p c_conns = new_zoomConnectionArray(conns.size());
try {
--- /dev/null
+/*
+ * Copyright (c) 1995-2013, Index Data
+ * All rights reserved.
+ * See the file LICENSE for details.
+ */
+/**
+ * Asynchronous ZOOOM API for developing non-blocking, multi-target applications.
+ *
+ * This package is highly experimental: classes and interfaces
+ * may be marked as @Unstable. Don't be surprised by breaking changes to those
+ * types.
+ *
+ * For background:
+ * @see <a href="http://www.indexdata.com/yaz/doc/zoom.events.html">ZOOM-API</a>
+ */
+package org.yaz4j.async;