@Timed public QueuedRequestId enqueueRequest(BaragonRequest request, InternalRequestStates state) throws NodeExistsException { final long start = System.currentTimeMillis(); final String queuedRequestPath = String.format(REQUEST_ENQUEUE_FORMAT, request.getLoadBalancerService().getServiceId(), request.getLoadBalancerRequestId()); final String requestPath = String.format(REQUEST_FORMAT, request.getLoadBalancerRequestId()); final String requestStatePath = String.format(REQUEST_STATE_FORMAT, request.getLoadBalancerRequestId()); try { if (!nodeExists(REQUESTS_FORMAT)) { createNode(REQUESTS_FORMAT); } if (!nodeExists(REQUEST_QUEUE_FORMAT)) { createNode(REQUEST_QUEUE_FORMAT); } byte[] requestBytes = objectMapper.writeValueAsBytes(request); byte[] stateBytes = objectMapper.writeValueAsBytes(state); Collection<CuratorTransactionResult> results = curatorFramework.inTransaction() .create().forPath(requestPath, requestBytes).and() .create().forPath(requestStatePath, stateBytes).and() .create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(queuedRequestPath) .and().commit(); log(OperationType.WRITE, Optional.of(3), Optional.of(requestBytes.length + stateBytes.length), start, String.format("Transaction Paths [%s + %s + %s]", requestPath, requestStatePath, queuedRequestPath)); return QueuedRequestId.fromString(ZKPaths.getNodeFromPath(Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(org.apache.curator.framework.api.transaction.OperationType.CREATE, queuedRequestPath)) .getResultPath())); } catch (NodeExistsException nee) { throw nee; } catch (Exception e) { throw new RuntimeException(e); } }