Exemplo n.º 1
0
 @Override
 protected void doStop() throws Exception {
   if (connectionManager != null) {
     // It releases the zookeeper connection when calling the shutdown method
     connectionManager.shutdown();
   }
 }
Exemplo n.º 2
0
  public void process(Exchange exchange) throws Exception {

    ZooKeeper connection = zkm.getConnection();
    ProductionContext context = new ProductionContext(connection, exchange);

    String operation =
        exchange.getIn().getHeader(ZooKeeperMessage.ZOOKEEPER_OPERATION, String.class);
    boolean isDelete = ZK_OPERATION_DELETE.equals(operation);

    if (ExchangeHelper.isOutCapable(exchange)) {
      if (isDelete) {
        if (log.isDebugEnabled()) {
          log.debug(format("Deleting znode '%s', waiting for confirmation", context.node));
        }

        OperationResult result = synchronouslyDelete(context);
        if (configuration.listChildren()) {
          result = listChildren(context);
        }
        updateExchangeWithResult(context, result);
      } else {
        if (log.isDebugEnabled()) {
          log.debug(format("Storing data to znode '%s', waiting for confirmation", context.node));
        }

        OperationResult result = synchronouslySetData(context);
        if (configuration.listChildren()) {
          result = listChildren(context);
        }
        updateExchangeWithResult(context, result);
      }
    } else {
      if (isDelete) {
        asynchronouslyDeleteNode(connection, context);
      } else {
        asynchronouslySetDataOnNode(connection, context);
      }
    }
  }