Search in sources :

Example 1 with BatchPublishPayloadException

use of com.quorum.tessera.transaction.publish.BatchPublishPayloadException in project tessera by ConsenSys.

the class AsyncBatchPayloadPublisher method publishPayload.

/**
 * Asynchronously strips (leaving data intended only for that particular recipient) and publishes
 * the payload to each recipient identified by the provided keys.
 *
 * <p>This method blocks until all pushes return successfully; if a push fails with an exception,
 * the method exits immediately and does not wait for the remaining responses.
 *
 * @param payload the payload object to be stripped and pushed
 * @param recipientKeys list of public keys identifying the target nodes
 */
@Override
public void publishPayload(EncodedPayload payload, List<PublicKey> recipientKeys) {
    if (recipientKeys.size() == 0) {
        return;
    }
    final CancellableCountDownLatch latch = countDownLatchFactory.create(recipientKeys.size());
    recipientKeys.forEach(recipient -> executor.execute(() -> {
        try {
            final EncodedPayload outgoing = EncodedPayload.Builder.forRecipient(payload, recipient).build();
            publisher.publishPayload(outgoing, recipient);
            latch.countDown();
        } catch (RuntimeException e) {
            LOGGER.info("unable to publish payload in batch: {}", e.getMessage());
            latch.cancelWithException(e);
        }
    }));
    try {
        latch.await();
    } catch (InterruptedException e) {
        throw new BatchPublishPayloadException(e);
    }
}
Also used : CancellableCountDownLatch(com.quorum.tessera.threading.CancellableCountDownLatch) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) BatchPublishPayloadException(com.quorum.tessera.transaction.publish.BatchPublishPayloadException)

Aggregations

EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)1 CancellableCountDownLatch (com.quorum.tessera.threading.CancellableCountDownLatch)1 BatchPublishPayloadException (com.quorum.tessera.transaction.publish.BatchPublishPayloadException)1