public class CreateBuilderImpl extends Object implements CreateBuilder, CreateBuilder2, ErrorListenerPathAndBytesable<String>
Constructor and Description |
---|
CreateBuilderImpl(CuratorFrameworkImpl client,
org.apache.zookeeper.CreateMode createMode,
Backgrounding backgrounding,
boolean createParentsIfNeeded,
boolean createParentsAsContainers,
boolean doProtected,
boolean compress,
boolean setDataIfExists,
List<org.apache.zookeeper.data.ACL> aclList,
org.apache.zookeeper.data.Stat storingStat,
long ttl) |
Modifier and Type | Method and Description |
---|---|
CreateBackgroundModeStatACLable |
compressed()
Cause the data to be compressed using the configured compression provider
|
ProtectACLCreateModeStatPathAndBytesable<String> |
creatingParentContainersIfNeeded()
Causes any parent nodes to get created using
CreateMode.CONTAINER if they haven't already been. |
ProtectACLCreateModeStatPathAndBytesable<String> |
creatingParentsIfNeeded()
Causes any parent nodes to get created if they haven't already been
|
String |
forPath(String path)
Commit the currently building operation using the given path and the default data
for the client (usually a byte[0] unless changed via
CuratorFrameworkFactory.Builder#defaultData(byte[]) ). |
String |
forPath(String givenPath,
byte[] data)
Commit the currently building operation using the given path and data
|
CreateBuilder2 |
idempotent()
If the first try of this operation gets a transient error, curator will retry
the operation, and treat it as successful so long as the end state of the znode
is the same as if the operation had completed without error on the first try.
|
ErrorListenerPathAndBytesable<String> |
inBackground()
Perform the action in the background
|
ErrorListenerPathAndBytesable<String> |
inBackground(BackgroundCallback callback)
Perform the action in the background
|
ErrorListenerPathAndBytesable<String> |
inBackground(BackgroundCallback callback,
Executor executor)
Perform the action in the background
|
ErrorListenerPathAndBytesable<String> |
inBackground(BackgroundCallback callback,
Object context)
Perform the action in the background
|
ErrorListenerPathAndBytesable<String> |
inBackground(BackgroundCallback callback,
Object context,
Executor executor)
Perform the action in the background
|
ErrorListenerPathAndBytesable<String> |
inBackground(Object context)
Perform the action in the background
|
CreateBuilder2 |
orSetData()
If the ZNode already exists, Curator will instead call setData()
|
CreateBuilder2 |
orSetData(int version)
If the ZNode already exists, Curator will instead call setData()
|
void |
performBackgroundOperation(org.apache.curator.framework.imps.OperationAndData<org.apache.curator.framework.imps.PathAndBytes> operationAndData) |
void |
setSetDataIfExistsVersion(int version) |
CreateProtectACLCreateModePathAndBytesable<String> |
storingStatIn(org.apache.zookeeper.data.Stat stat)
Have the operation fill the provided stat object
|
ACLBackgroundPathAndBytesable<String> |
withACL(List<org.apache.zookeeper.data.ACL> aclList)
Set an ACL list (default is
ZooDefs.Ids#OPEN_ACL_UNSAFE ) |
ACLBackgroundPathAndBytesable<String> |
withACL(List<org.apache.zookeeper.data.ACL> aclList,
boolean applyToParents)
Set an ACL list (default is
ZooDefs.Ids#OPEN_ACL_UNSAFE ). |
ACLBackgroundPathAndBytesable<String> |
withMode(org.apache.zookeeper.CreateMode mode)
Set a create mode - the default is
CreateMode.PERSISTENT |
ACLPathAndBytesable<String> |
withProtectedEphemeralSequential() |
ACLCreateModeStatBackgroundPathAndBytesable<String> |
withProtection()
Hat-tip to https://github.com/sbridges for pointing this out
|
CreateBuilderMain |
withTtl(long ttl)
Specify a TTL when mode is
CreateMode.PERSISTENT_WITH_TTL or
CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL . |
PathAndBytesable<String> |
withUnhandledErrorListener(UnhandledErrorListener listener)
Set an error listener for this background operation.
|
public CreateBuilderImpl(CuratorFrameworkImpl client, org.apache.zookeeper.CreateMode createMode, Backgrounding backgrounding, boolean createParentsIfNeeded, boolean createParentsAsContainers, boolean doProtected, boolean compress, boolean setDataIfExists, List<org.apache.zookeeper.data.ACL> aclList, org.apache.zookeeper.data.Stat storingStat, long ttl)
public void setSetDataIfExistsVersion(int version)
public CreateBuilder2 orSetData()
CreateBuilder
orSetData
in interface CreateBuilder
public CreateBuilder2 orSetData(int version)
CreateBuilder
orSetData
in interface CreateBuilder
version
- the version to use for CuratorFramework.setData()
public CreateBuilder2 idempotent()
Idempotentable
idempotent
in interface Idempotentable<CreateBuilder2>
public CreateBuilderMain withTtl(long ttl)
CreateBuilder
CreateMode.PERSISTENT_WITH_TTL
or
CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL
. If
the znode has not been modified within the given TTL, it will be deleted once it has no
children. The TTL unit is milliseconds and must be greater than 0 and less than or equal to
EphemeralType.MAX_TTL.withTtl
in interface CreateBuilder
withTtl
in interface CreateBuilder2
ttl
- the ttlpublic CreateBackgroundModeStatACLable compressed()
Compressible
compressed
in interface Compressible<CreateBackgroundModeStatACLable>
public ACLBackgroundPathAndBytesable<String> withACL(List<org.apache.zookeeper.data.ACL> aclList)
ACLable
ZooDefs.Ids#OPEN_ACL_UNSAFE
)withACL
in interface ACLable<BackgroundPathAndBytesable<String>>
aclList
- the ACL list to usepublic ACLBackgroundPathAndBytesable<String> withACL(List<org.apache.zookeeper.data.ACL> aclList, boolean applyToParents)
ParentACLable
ZooDefs.Ids#OPEN_ACL_UNSAFE
).
If applyToParents is true, then the aclList is applied to the created parents.
Existing parent nodes are not affected.withACL
in interface ParentACLable<BackgroundPathAndBytesable<String>>
aclList
- the ACL list to useapplyToParents
- if true, then the aclList is applied to the created parents.public ProtectACLCreateModeStatPathAndBytesable<String> creatingParentContainersIfNeeded()
CreateBuilderMain
CreateMode.CONTAINER
if they haven't already been.
IMPORTANT NOTE: container creation is a new feature in recent versions of ZooKeeper.
If the ZooKeeper version you're using does not support containers, the parent nodes
are created as ordinary PERSISTENT nodes.creatingParentContainersIfNeeded
in interface CreateBuilderMain
public ProtectACLCreateModeStatPathAndBytesable<String> creatingParentsIfNeeded()
CreateBuilderMain
creatingParentsIfNeeded
in interface CreateBuilderMain
public ACLCreateModeStatBackgroundPathAndBytesable<String> withProtection()
CreateBuilderMain
Hat-tip to https://github.com/sbridges for pointing this out
It turns out there is an edge case that exists when creating sequential-ephemeral nodes. The creation can succeed on the server, but the server can crash before the created node name is returned to the client. However, the ZK session is still valid so the ephemeral node is not deleted. Thus, there is no way for the client to determine what node was created for them.
Even without sequential-ephemeral, however, the create can succeed on the sever but the client (for various reasons) will not know it.
Putting the create builder into protection mode works around this. The name of the node that is created is prefixed with a 40 characters string that is the concatenation of
UUID.toString()
withProtection
in interface CreateBuilderMain
public ACLPathAndBytesable<String> withProtectedEphemeralSequential()
withProtectedEphemeralSequential
in interface CreateBuilderMain
public ACLBackgroundPathAndBytesable<String> withMode(org.apache.zookeeper.CreateMode mode)
CreateModable
CreateMode.PERSISTENT
withMode
in interface CreateModable<ACLBackgroundPathAndBytesable<String>>
mode
- new create modepublic ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context)
Backgroundable
inBackground
in interface Backgroundable<ErrorListenerPathAndBytesable<String>>
callback
- a functor that will get called when the operation has completedcontext
- context object - will be available from the event sent to the listenerpublic ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor)
Backgroundable
inBackground
in interface Backgroundable<ErrorListenerPathAndBytesable<String>>
callback
- a functor that will get called when the operation has completedcontext
- context object - will be available from the event sent to the listenerexecutor
- executor to use for the background callpublic ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback)
Backgroundable
inBackground
in interface Backgroundable<ErrorListenerPathAndBytesable<String>>
callback
- a functor that will get called when the operation has completedpublic ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor)
Backgroundable
inBackground
in interface Backgroundable<ErrorListenerPathAndBytesable<String>>
callback
- a functor that will get called when the operation has completedexecutor
- executor to use for the background callpublic ErrorListenerPathAndBytesable<String> inBackground()
Backgroundable
inBackground
in interface Backgroundable<ErrorListenerPathAndBytesable<String>>
public ErrorListenerPathAndBytesable<String> inBackground(Object context)
Backgroundable
inBackground
in interface Backgroundable<ErrorListenerPathAndBytesable<String>>
context
- context object - will be available from the event sent to the listenerpublic PathAndBytesable<String> withUnhandledErrorListener(UnhandledErrorListener listener)
ErrorListenerPathAndBytesable
withUnhandledErrorListener
in interface ErrorListenerPathAndBytesable<String>
listener
- the listenerpublic String forPath(String path) throws Exception
PathAndBytesable
CuratorFrameworkFactory.Builder#defaultData(byte[])
).forPath
in interface PathAndBytesable<String>
path
- the pathException
- errorspublic String forPath(String givenPath, byte[] data) throws Exception
PathAndBytesable
forPath
in interface PathAndBytesable<String>
givenPath
- the pathdata
- the dataException
- errorspublic void performBackgroundOperation(org.apache.curator.framework.imps.OperationAndData<org.apache.curator.framework.imps.PathAndBytes> operationAndData) throws Exception
Exception
public CreateProtectACLCreateModePathAndBytesable<String> storingStatIn(org.apache.zookeeper.data.Stat stat)
Statable
storingStatIn
in interface Statable<CreateProtectACLCreateModePathAndBytesable<String>>
stat
- the stat to have filled inCopyright © 2011–2023 The Apache Software Foundation. All rights reserved.