Java Code Examples for org.apache.zookeeper.CreateMode#isEphemeral()

The following examples show how to use org.apache.zookeeper.CreateMode#isEphemeral() . 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: ProtectedMode.java    From curator with Apache License 2.0 6 votes vote down vote up
/**
 * Validate the found protected-mode node based on the set session ID, etc.
 *
 * @param client current client
 * @param createMode create mode in use
 * @param foundNode the found node
 * @return either the found node or null - client should always use the returned value
 * @throws Exception errors
 */
String validateFoundNode(CuratorFrameworkImpl client, CreateMode createMode, String foundNode) throws Exception
{
    if ( doProtected() && createMode.isEphemeral() )
    {
        long clientSessionId = client.getZooKeeper().getSessionId();
        if ( this.sessionId != clientSessionId )
        {
            log.info("Session has changed during protected mode with ephemeral. old: {} new: {}", this.sessionId, clientSessionId);
            if ( foundNode != null )
            {
                log.info("Deleted old session's found node: {}", foundNode);
                client.getFailedDeleteManager().executeGuaranteedOperationInBackground(foundNode);
                foundNode = null;
            }
            this.sessionId = clientSessionId;
        }
    }
    return foundNode;
}
 
Example 2
Source File: Schema.java    From curator with Apache License 2.0 6 votes vote down vote up
/**
 * Validate that this schema's create mode setting matches and that the data is valid
 *
 * @param mode CreateMode being used
 * @param path the znode full path
 * @param data data being set
 * @param acl the creation acls
 * @throws SchemaViolation if schema's create mode setting does not match or data is invalid
 */
public void validateCreate(CreateMode mode, String path, byte[] data, List<ACL> acl)
{
    if ( mode.isEphemeral() && (ephemeral == Allowance.CANNOT) )
    {
        throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Cannot be ephemeral");
    }

    if ( !mode.isEphemeral() && (ephemeral == Allowance.MUST) )
    {
        throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Must be ephemeral");
    }

    if ( mode.isSequential() && (sequential == Allowance.CANNOT) )
    {
        throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Cannot be sequential");
    }

    if ( !mode.isSequential() && (sequential == Allowance.MUST) )
    {
        throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Must be sequential");
    }

    validateGeneral(path, data, acl);
}
 
Example 3
Source File: ProtectedMode.java    From curator with Apache License 2.0 5 votes vote down vote up
/**
 * Record the current session ID if needed
 *
 * @param client current client
 * @param createMode create mode in use
 * @throws Exception errors
 */
void checkSetSessionId(CuratorFrameworkImpl client, CreateMode createMode) throws Exception
{
    if ( doProtected() && (sessionId == 0) && createMode.isEphemeral() )
    {
        sessionId = client.getZooKeeper().getSessionId();
    }
}
 
Example 4
Source File: SharedZkClientFactory.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Since ZkConnection session is shared in this HelixZkClient, do not create ephemeral node using a SharedZKClient.
 */
@Override
public String create(final String path, Object datat, final List<ACL> acl,
    final CreateMode mode) {
  if (mode.isEphemeral()) {
    throw new UnsupportedOperationException(
        "Create ephemeral nodes using " + SharedZkClient.class.getSimpleName()
            + " is not supported.");
  }
  return super.create(path, datat, acl, mode);
}
 
Example 5
Source File: FederatedZkClient.java    From helix with Apache License 2.0 5 votes vote down vote up
private String create(final String path, final Object dataObject, final List<ACL> acl,
    final CreateMode mode, final String expectedSessionId) {
  if (mode.isEphemeral()) {
    throwUnsupportedOperationException();
  }

  // Create mode is not session-aware, so the node does not have to be created
  // by the expectedSessionId.
  return getZkClient(path).create(path, dataObject, acl, mode);
}