public boolean publishBarrierState(String state, String leaseId) {
    try {
      if (leaseId == null) {
        return false;
      }
      byte[] data = SamzaObjectMapper.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsBytes(state);
      byte[] pageData = Arrays.copyOf(data, (int) BARRIER_STATE_BLOCK_SIZE);
      InputStream is = new ByteArrayInputStream(pageData);

      //uploadPages is only successful when the AccessCondition provided has an active and valid lease ID. It fails otherwise.
      blob.uploadPages(is, JOB_MODEL_BLOCK_SIZE, BARRIER_STATE_BLOCK_SIZE, AccessCondition.generateLeaseCondition(leaseId), null, null);
      LOG.info("Uploaded barrier state {} to blob", state);
      return true;
    } catch (StorageException | IOException e) {
      LOG.error("Barrier state " + state + " publish failed", e);
      return false;
    }
  }
Writes the barrier state to the blob.
Write is successful only if the lease ID passed is valid and the processor holds the lease.
Called only by the leader.
@param state Barrier state to be published to the blob.
@param leaseId LeaseID of the valid lease that the processor holds on the blob. Null if there is no lease.
@return true if write to the blob is successful, false if leaseID is null or an Azure storage service error or IO exception occurred.
samza-azure/src/main/java/org/apache/samza/util/BlobUtils.java