Java Code Examples for org.apache.zookeeper.CreateMode#PERSISTENT_SEQUENTIAL

The following examples show how to use org.apache.zookeeper.CreateMode#PERSISTENT_SEQUENTIAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FailureRetryZKClient.java    From twill with Apache License 2.0 6 votes vote down vote up
@Override
public OperationFuture<String> create(final String path, @Nullable final byte[] data, final CreateMode createMode,
                                      final boolean createParent, final Iterable<ACL> acl) {
  // No retry for any SEQUENTIAL node, as some algorithms depends on only one sequential node being created.
  if (createMode == CreateMode.PERSISTENT_SEQUENTIAL || createMode == CreateMode.EPHEMERAL_SEQUENTIAL) {
    return super.create(path, data, createMode, createParent, acl);
  }

  final SettableOperationFuture<String> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.create(path, data, createMode, createParent, acl),
                      new OperationFutureCallback<String>(OperationType.CREATE, System.currentTimeMillis(),
                                                          path, result, new Supplier<OperationFuture<String>>() {
                        @Override
                        public OperationFuture<String> get() {
                          return FailureRetryZKClient.super.create(path, data, createMode, createParent, acl);
                        }
                      }));
  return result;
}
 
Example 2
Source File: SimDistribStateManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private Node createNode(Node parentNode, CreateMode mode, StringBuilder fullChildPath, String baseChildName, byte[] data, boolean attachToParent) throws IOException {
  String nodeName = baseChildName;
  if ((parentNode.mode == CreateMode.EPHEMERAL || parentNode.mode == CreateMode.EPHEMERAL_SEQUENTIAL) &&
      (mode == CreateMode.EPHEMERAL || mode == CreateMode.EPHEMERAL_SEQUENTIAL)) {
    throw new IOException("NoChildrenEphemerals for " + parentNode.path);
  }
  if (CreateMode.PERSISTENT_SEQUENTIAL == mode || CreateMode.EPHEMERAL_SEQUENTIAL == mode) {
    nodeName = nodeName + String.format(Locale.ROOT, "%010d", parentNode.seq);
    parentNode.seq++;
  }

  fullChildPath.append(nodeName);
  String owner = mode == CreateMode.EPHEMERAL || mode == CreateMode.EPHEMERAL_SEQUENTIAL ? id : "0";
  Node child = new Node(parentNode, nodeName, fullChildPath.toString(), data, mode, owner);

  if (attachToParent) {
    parentNode.setChild(nodeName, child);
  }
  return child;
}
 
Example 3
Source File: AccessOption.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to get zookeeper create mode from options
 * @param options bitmask representing mode; least significant set flag is selected
 * @return zookeeper create mode
 */
public static CreateMode getMode(int options) {
  if ((options & PERSISTENT) > 0) {
    return CreateMode.PERSISTENT;
  } else if ((options & EPHEMERAL) > 0) {
    return CreateMode.EPHEMERAL;
  } else if ((options & PERSISTENT_SEQUENTIAL) > 0) {
    return CreateMode.PERSISTENT_SEQUENTIAL;
  } else if ((options & EPHEMERAL_SEQUENTIAL) > 0) {
    return CreateMode.EPHEMERAL_SEQUENTIAL;
  }

  return null;
}
 
Example 4
Source File: RegistryImpl.java    From Scribengin with GNU Affero General Public License v3.0 5 votes vote down vote up
static CreateMode toCreateMode(NodeCreateMode mode) {
  if(mode == NodeCreateMode.PERSISTENT) return CreateMode.PERSISTENT ;
  else if(mode == NodeCreateMode.PERSISTENT_SEQUENTIAL) return CreateMode.PERSISTENT_SEQUENTIAL ;
  else if(mode == NodeCreateMode.EPHEMERAL) return CreateMode.EPHEMERAL ;
  else if(mode == NodeCreateMode.EPHEMERAL_SEQUENTIAL) return CreateMode.EPHEMERAL_SEQUENTIAL ;
  throw new RuntimeException("Mode " + mode + " is not supported") ;
}
 
Example 5
Source File: PersistentEphemeralNodeTest.java    From curator-extensions with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testNonPersistentSequentialMode() throws Exception {
    new PersistentEphemeralNode(newCurator(), PATH, DATA, CreateMode.PERSISTENT_SEQUENTIAL);
}