use of com.quorum.tessera.threading.CancellableCountDownLatch in project tessera by ConsenSys.
the class AsyncBatchPrivacyGroupPublisher method publishPrivacyGroup.
@Override
public void publishPrivacyGroup(byte[] data, List<PublicKey> recipientKeys) {
if (recipientKeys.size() == 0) {
return;
}
final CancellableCountDownLatch latch = countDownLatchFactory.create(recipientKeys.size());
recipientKeys.forEach(key -> executor.execute(() -> {
try {
publisher.publishPrivacyGroup(data, key);
latch.countDown();
} catch (RuntimeException e) {
LOGGER.info("Unable to publish privacy group: {}", e.getMessage());
latch.cancelWithException(e);
}
}));
try {
latch.await();
} catch (InterruptedException e) {
throw new PrivacyGroupPublishException(e.getMessage());
}
}
use of com.quorum.tessera.threading.CancellableCountDownLatch 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);
}
}
Aggregations