extend response listener by total result count

This commit is contained in:
Jörg Prante 2017-11-30 17:42:07 +01:00
parent 832c86a73d
commit d8972929bb
6 changed files with 19 additions and 21 deletions

View file

@ -1,5 +1,5 @@
group = org.xbib
name = z3950
version = 1.0.0
version = 1.0.1
xbib-cql.version = 1.1.0

View file

@ -8,5 +8,5 @@ import java.io.IOException;
@FunctionalInterface
public interface ResponseListener {
void onResponse(int status, int recordCount, long elapsedMillis) throws IOException;
void onResponse(int status, int total, int returned, long elapsedMillis) throws IOException;
}

View file

@ -251,9 +251,9 @@ public class ZClient implements AutoCloseable {
logger.log(Level.WARNING, MessageFormat.format("search was not a success [{0}]", query));
} else {
if (responseListener == null) {
responseListener = (status, recordCount, elapsedMillis) -> {
logger.log(Level.INFO, MessageFormat.format("[{0}ms] [{1}] [{2}]",
elapsedMillis, recordCount, query));
responseListener = (status, total, returned, elapsedMillis) -> {
logger.log(Level.INFO, MessageFormat.format("[{0}ms] [{1}] [{2}] [{3}]",
elapsedMillis, total, returned, query));
};
}
if (search.getCount() > 0) {
@ -266,7 +266,7 @@ public class ZClient implements AutoCloseable {
// avoid condition 13 "Present request out-of-range"
length = search.getCount();
}
present.execute(this, offset, length, responseListener, recordListener);
present.execute(this, offset, length, search.getCount(), responseListener, recordListener);
}
}
return search.getCount();
@ -284,9 +284,9 @@ public class ZClient implements AutoCloseable {
logger.log(Level.WARNING, MessageFormat.format("search was not a success [{0}]", query));
} else {
if (responseListener == null) {
responseListener = (status, recordCount, elapsedMillis) -> {
logger.log(Level.INFO, MessageFormat.format("[{0}ms] [{1}] [{2}]",
elapsedMillis, recordCount, query));
responseListener = (status, total, returned, elapsedMillis) -> {
logger.log(Level.INFO, MessageFormat.format("[{0}ms] [{1}] [{2}] [{3}]",
elapsedMillis, total, returned, query));
};
}
if (search.getCount() > 0) {
@ -300,7 +300,7 @@ public class ZClient implements AutoCloseable {
// avoid condition 13 "Present request out-of-range"
length = search.getCount();
}
present.execute(this, offset, length, responseListener, recordListener);
present.execute(this, offset, length, search.getCount(), responseListener, recordListener);
}
}
return search.getCount();

View file

@ -32,7 +32,7 @@ import java.io.IOException;
*/
public class PresentOperation {
public void execute(ZClient client, int offset, int length,
public void execute(ZClient client, int offset, int length, int total,
ResponseListener responseListener, RecordListener recordListener) throws IOException {
String resultSetName = client.getResultSetName();
String elementSetName = client.getElementSetName();
@ -57,7 +57,7 @@ public class PresentOperation {
int nReturned = response.s_numberOfRecordsReturned != null ? response.s_numberOfRecordsReturned.get() : 0;
int status = response.s_presentStatus.value != null ? response.s_presentStatus.value.get() : 0;
if (responseListener != null) {
responseListener.onResponse(status, nReturned, System.currentTimeMillis() - millis);
responseListener.onResponse(status, total, nReturned, System.currentTimeMillis() - millis);
}
if (status == PresentStatus.E_success) {
for (int n = 0; n < nReturned; n++) {

View file

@ -32,7 +32,7 @@ public class SearchTest {
.setPreferredRecordSyntax(preferredRecordSyntax)
.build();
client.executePQF(query, from, length,
(status, recordCount, elapsedMillis) -> logger.log(Level.INFO, "records = " + recordCount),
(status, total, returned, elapsedMillis) -> logger.log(Level.INFO, "total records = " + total),
record -> logger.log(Level.INFO, "found record " + record));
client.close();
} catch (NoRecordsReturnedException | MessageSizeTooSmallException e) {

View file

@ -23,10 +23,9 @@ public class ZClientTest {
try (ZClient client = ZClient.newZClient(serviceName)) {
logger.log(Level.INFO, "executing CQL " + serviceName);
int count = client.executeCQL(query, from, size,
(status, recordCount, elapsedMillis) ->
logger.log(Level.INFO, serviceName + " results = " + recordCount),
record ->
logger.log(Level.INFO, "record = " + record));
(status, total, returned, elapsedMillis) ->
logger.log(Level.INFO, serviceName + " total results = " + total),
record -> logger.log(Level.INFO, "record = " + record));
logger.log(Level.INFO, "returned records = " + count);
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
@ -43,10 +42,9 @@ public class ZClientTest {
try (ZClient client = ZClient.newZClient(serviceName)) {
logger.log(Level.INFO, "executing PQF " + serviceName);
int count = client.executePQF(query, from, size,
(status, recordCount, elapsedMillis) ->
logger.log(Level.INFO, serviceName + " status = " + status + " results = " + recordCount),
record ->
logger.log(Level.INFO, "record = " + record.toString(Charset.forName(client.getEncoding()))));
(status, total, returned, elapsedMillis) ->
logger.log(Level.INFO, serviceName + " status = " + status + " total results = " + total),
record -> logger.log(Level.INFO, "record = " + record.toString(Charset.forName(client.getEncoding()))));
logger.log(Level.INFO, "returned records = " + count);
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);