Search in sources :

Example 1 with ServerResponseHandler

use of org.bboxdb.network.client.response.ServerResponseHandler in project bboxdb by jnidzwetzki.

the class BBoxDBConnection method handleResultPackage.

/**
 * Handle the next result package
 * @param packageHeader
 * @throws PackageEncodeException
 */
public void handleResultPackage(final ByteBuffer encodedPackage) throws PackageEncodeException {
    final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromResponsePackage(encodedPackage);
    final short packageType = NetworkPackageDecoder.getPackageTypeFromResponse(encodedPackage);
    NetworkOperationFuture future = null;
    synchronized (pendingCalls) {
        future = pendingCalls.get(Short.valueOf(sequenceNumber));
    }
    if (!serverResponseHandler.containsKey(packageType)) {
        logger.error("Unknown respose package type: {}", packageType);
        removeFutureAndReleaseSequencenumber(sequenceNumber);
        if (future != null) {
            future.setFailedState();
            future.fireCompleteEvent();
        }
    } else {
        final ServerResponseHandler handler = serverResponseHandler.get(packageType);
        final boolean removeFuture = handler.handleServerResult(this, encodedPackage, future);
        // Remove pending call
        if (removeFuture) {
            removeFutureAndReleaseSequencenumber(sequenceNumber);
        }
    }
}
Also used : ServerResponseHandler(org.bboxdb.network.client.response.ServerResponseHandler) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture)

Aggregations

NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)1 ServerResponseHandler (org.bboxdb.network.client.response.ServerResponseHandler)1