use of org.bboxdb.storage.entity.PagedTransferableEntity in project bboxdb by jnidzwetzki.
the class PageEndHandler method handleServerResult.
/**
* Handle the end of a page
* @return
*/
@Override
public boolean handleServerResult(final BBoxDBConnection bBoxDBConnection, final ByteBuffer encodedPackage, final NetworkOperationFuture future) throws PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Handle page end package");
}
final PageEndResponse result = PageEndResponse.decodePackage(encodedPackage);
final short sequenceNumber = result.getSequenceNumber();
final List<PagedTransferableEntity> resultList = bBoxDBConnection.getResultBuffer().remove(sequenceNumber);
// Collect tuples of the next page in new list
bBoxDBConnection.getResultBuffer().put(sequenceNumber, new ArrayList<>());
if (future == null) {
logger.warn("Got handleMultiTupleEnd and pendingCall is empty");
return true;
}
if (resultList == null) {
logger.warn("Got handleMultiTupleEnd and resultList is empty (package {})", sequenceNumber);
future.setFailedState();
future.fireCompleteEvent();
return true;
}
ResponseHandlerHelper.castAndSetFutureResult(future, resultList, false);
return true;
}
use of org.bboxdb.storage.entity.PagedTransferableEntity in project bboxdb by jnidzwetzki.
the class MultipleTupleEndHandler method handleServerResult.
@Override
public boolean handleServerResult(final BBoxDBConnection bBoxDBConnection, final ByteBuffer encodedPackage, final NetworkOperationFuture future) throws PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Handle multiple tuple end package");
}
final MultipleTupleEndResponse result = MultipleTupleEndResponse.decodePackage(encodedPackage);
final short sequenceNumber = result.getSequenceNumber();
final Map<Short, List<PagedTransferableEntity>> resultBuffer = bBoxDBConnection.getResultBuffer();
final List<PagedTransferableEntity> resultList = resultBuffer.remove(sequenceNumber);
if (future == null) {
logger.error("Got handleMultiTupleEnd and future is null (package {}) ", sequenceNumber);
return true;
}
if (resultList == null) {
logger.error("Got handleMultiTupleEnd and resultList is empty (package {})", sequenceNumber);
future.setFailedState();
future.fireCompleteEvent();
return true;
}
ResponseHandlerHelper.castAndSetFutureResult(future, resultList, true);
return true;
}
use of org.bboxdb.storage.entity.PagedTransferableEntity in project bboxdb by jnidzwetzki.
the class ResponseHandlerHelper method castAndSetFutureResult.
/**
* Cast the content on the result list according to the future type
* @param future
* @param resultList
* @param completeResult
* @throws PackageEncodeException
*/
public static void castAndSetFutureResult(final NetworkOperationFuture future, final List<PagedTransferableEntity> resultList, final boolean completeResult) throws PackageEncodeException {
if (resultList.isEmpty()) {
future.setCompleteResult(completeResult);
future.setOperationResult(new ArrayList<>());
future.fireCompleteEvent();
return;
}
final PagedTransferableEntity firstElement = resultList.get(0);
if (firstElement instanceof Tuple) {
final List<Tuple> tupleList = new ArrayList<>();
for (final PagedTransferableEntity entity : resultList) {
tupleList.add((Tuple) entity);
}
future.setCompleteResult(completeResult);
future.setOperationResult(tupleList);
future.fireCompleteEvent();
} else if (firstElement instanceof JoinedTuple) {
final List<JoinedTuple> tupleList = new ArrayList<>();
for (final PagedTransferableEntity entity : resultList) {
tupleList.add((JoinedTuple) entity);
}
future.setCompleteResult(completeResult);
future.setOperationResult(tupleList);
future.fireCompleteEvent();
} else {
throw new PackageEncodeException("Unknown future type: " + firstElement);
}
}
use of org.bboxdb.storage.entity.PagedTransferableEntity in project bboxdb by jnidzwetzki.
the class TupleHandler method handleServerResult.
/**
* Handle a single tuple as result
* @return
*/
@Override
public boolean handleServerResult(final BBoxDBConnection bBoxDBConnection, final ByteBuffer encodedPackage, final NetworkOperationFuture future) throws PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Handle tuple package");
}
final TupleResponse singleTupleResponse = TupleResponse.decodePackage(encodedPackage);
final short sequenceNumber = singleTupleResponse.getSequenceNumber();
// Tuple is part of a multi tuple result
final Map<Short, List<PagedTransferableEntity>> resultBuffer = bBoxDBConnection.getResultBuffer();
if (resultBuffer.containsKey(sequenceNumber)) {
final List<PagedTransferableEntity> packageResult = resultBuffer.get(sequenceNumber);
packageResult.add(singleTupleResponse.getTuple());
// tuple result or a multiple tuple result
return false;
}
// Single tuple is returned
if (future != null) {
future.setOperationResult(Arrays.asList(singleTupleResponse.getTuple()));
future.fireCompleteEvent();
}
return true;
}
Aggregations