Class CreateBuilderImpl
- All Implemented Interfaces:
ACLable<BackgroundPathAndBytesable<String>>
,ACLBackgroundPathAndBytesable<String>
,ACLCreateModeBackgroundPathAndBytesable<String>
,Backgroundable<ErrorListenerPathAndBytesable<String>>
,BackgroundPathAndBytesable<String>
,Compressible<CreateBackgroundModeStatACLable>
,CreateBuilder
,CreateBuilder2
,CreateBuilderMain
,CreateModable<ACLBackgroundPathAndBytesable<String>>
,ErrorListenerPathAndBytesable<String>
,Idempotentable<CreateBuilder2>
,ParentACLable<BackgroundPathAndBytesable<String>>
,PathAndBytesable<String>
,Statable<CreateProtectACLCreateModePathAndBytesable<String>>
-
Constructor Summary
ConstructorDescriptionCreateBuilderImpl
(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) -
Method Summary
Modifier and TypeMethodDescriptionCause the data to be compressed using the configured compression providerCauses any parent nodes to get created usingCreateMode.CONTAINER
if they haven't already been.Causes any parent nodes to get created if they haven't already beenCommit the currently building operation using the given path and the default data for the client (usually a byte[0] unless changed viaCuratorFrameworkFactory.Builder.defaultData(byte[])
).Commit the currently building operation using the given path and dataIf 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.Perform the action in the backgroundinBackground
(Object context) Perform the action in the backgroundinBackground
(BackgroundCallback callback) Perform the action in the backgroundinBackground
(BackgroundCallback callback, Object context) Perform the action in the backgroundinBackground
(BackgroundCallback callback, Object context, Executor executor) Perform the action in the backgroundinBackground
(BackgroundCallback callback, Executor executor) Perform the action in the backgroundIf the ZNode already exists, Curator will instead call setData()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) storingStatIn
(org.apache.zookeeper.data.Stat stat) Have the operation fill the provided stat objectSet an ACL list (default isZooDefs.Ids.OPEN_ACL_UNSAFE
)Set an ACL list (default isZooDefs.Ids.OPEN_ACL_UNSAFE
).withMode
(org.apache.zookeeper.CreateMode mode) Set a create mode - the default isCreateMode.PERSISTENT
Hat-tip to https://github.com/sbridges for pointing this outwithTtl
(long ttl) Specify a TTL when mode isCreateMode.PERSISTENT_WITH_TTL
orCreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL
.Set an error listener for this background operation.
-
Constructor Details
-
CreateBuilderImpl
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)
-
-
Method Details
-
setSetDataIfExistsVersion
public void setSetDataIfExistsVersion(int version) -
orSetData
Description copied from interface:CreateBuilder
If the ZNode already exists, Curator will instead call setData()- Specified by:
orSetData
in interfaceCreateBuilder
-
orSetData
Description copied from interface:CreateBuilder
If the ZNode already exists, Curator will instead call setData()- Specified by:
orSetData
in interfaceCreateBuilder
- Parameters:
version
- the version to use forCuratorFramework.setData()
-
idempotent
Description copied from interface:Idempotentable
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.- Specified by:
idempotent
in interfaceIdempotentable<CreateBuilder2>
- Returns:
- this:
-
withTtl
Description copied from interface:CreateBuilder
Specify a TTL when mode isCreateMode.PERSISTENT_WITH_TTL
orCreateMode.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.- Specified by:
withTtl
in interfaceCreateBuilder
- Specified by:
withTtl
in interfaceCreateBuilder2
- Parameters:
ttl
- the ttl- Returns:
- this for chaining
-
compressed
Description copied from interface:Compressible
Cause the data to be compressed using the configured compression provider- Specified by:
compressed
in interfaceCompressible<CreateBackgroundModeStatACLable>
- Returns:
- this
-
withACL
Description copied from interface:ACLable
Set an ACL list (default isZooDefs.Ids.OPEN_ACL_UNSAFE
)- Specified by:
withACL
in interfaceACLable<BackgroundPathAndBytesable<String>>
- Parameters:
aclList
- the ACL list to use- Returns:
- this
-
withACL
public ACLBackgroundPathAndBytesable<String> withACL(List<org.apache.zookeeper.data.ACL> aclList, boolean applyToParents) Description copied from interface:ParentACLable
Set an ACL list (default isZooDefs.Ids.OPEN_ACL_UNSAFE
). If applyToParents is true, then the aclList is applied to the created parents. Existing parent nodes are not affected.- Specified by:
withACL
in interfaceParentACLable<BackgroundPathAndBytesable<String>>
- Parameters:
aclList
- the ACL list to useapplyToParents
- if true, then the aclList is applied to the created parents.- Returns:
- this
-
creatingParentContainersIfNeeded
Description copied from interface:CreateBuilderMain
Causes any parent nodes to get created usingCreateMode.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.- Specified by:
creatingParentContainersIfNeeded
in interfaceCreateBuilderMain
- Returns:
- this
-
creatingParentsIfNeeded
Description copied from interface:CreateBuilderMain
Causes any parent nodes to get created if they haven't already been- Specified by:
creatingParentsIfNeeded
in interfaceCreateBuilderMain
- Returns:
- this
-
withProtection
Description copied from interface: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
- "_c_"
- Canonical text representation of a random generated UUID as produced by
UUID.toString()
- '-'
- Specified by:
withProtection
in interfaceCreateBuilderMain
- Returns:
- this
-
withProtectedEphemeralSequential
- Specified by:
withProtectedEphemeralSequential
in interfaceCreateBuilderMain
- Returns:
- this
-
withMode
Description copied from interface:CreateModable
Set a create mode - the default isCreateMode.PERSISTENT
- Specified by:
withMode
in interfaceCreateModable<ACLBackgroundPathAndBytesable<String>>
- Parameters:
mode
- new create mode- Returns:
- this
-
inBackground
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) Description copied from interface:Backgroundable
Perform the action in the background- Specified by:
inBackground
in interfaceBackgroundable<ErrorListenerPathAndBytesable<String>>
- Parameters:
callback
- a functor that will get called when the operation has completedcontext
- context object - will be available from the event sent to the listener- Returns:
- this
-
inBackground
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) Description copied from interface:Backgroundable
Perform the action in the background- Specified by:
inBackground
in interfaceBackgroundable<ErrorListenerPathAndBytesable<String>>
- Parameters:
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 call- Returns:
- this
-
inBackground
Description copied from interface:Backgroundable
Perform the action in the background- Specified by:
inBackground
in interfaceBackgroundable<ErrorListenerPathAndBytesable<String>>
- Parameters:
callback
- a functor that will get called when the operation has completed- Returns:
- this
-
inBackground
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) Description copied from interface:Backgroundable
Perform the action in the background- Specified by:
inBackground
in interfaceBackgroundable<ErrorListenerPathAndBytesable<String>>
- Parameters:
callback
- a functor that will get called when the operation has completedexecutor
- executor to use for the background call- Returns:
- this
-
inBackground
Description copied from interface:Backgroundable
Perform the action in the background- Specified by:
inBackground
in interfaceBackgroundable<ErrorListenerPathAndBytesable<String>>
- Returns:
- this
-
inBackground
Description copied from interface:Backgroundable
Perform the action in the background- Specified by:
inBackground
in interfaceBackgroundable<ErrorListenerPathAndBytesable<String>>
- Parameters:
context
- context object - will be available from the event sent to the listener- Returns:
- this
-
withUnhandledErrorListener
Description copied from interface:ErrorListenerPathAndBytesable
Set an error listener for this background operation. If an exception occurs while processing the call in the background, this listener will be called.- Specified by:
withUnhandledErrorListener
in interfaceErrorListenerPathAndBytesable<String>
- Parameters:
listener
- the listener- Returns:
- this for chaining
-
forPath
Description copied from interface:PathAndBytesable
Commit the currently building operation using the given path and the default data for the client (usually a byte[0] unless changed viaCuratorFrameworkFactory.Builder.defaultData(byte[])
).- Specified by:
forPath
in interfacePathAndBytesable<String>
- Parameters:
path
- the path- Returns:
- operation result if any
- Throws:
Exception
- errors
-
forPath
Description copied from interface:PathAndBytesable
Commit the currently building operation using the given path and data- Specified by:
forPath
in interfacePathAndBytesable<String>
- Parameters:
givenPath
- the pathdata
- the data- Returns:
- operation result if any
- Throws:
Exception
- errors
-
getBackgroundEventType
-
performBackgroundOperation
public void performBackgroundOperation(org.apache.curator.framework.imps.OperationAndData<org.apache.curator.framework.imps.PathAndBytes> operationAndData) throws Exception - Throws:
Exception
-
storingStatIn
public CreateProtectACLCreateModePathAndBytesable<String> storingStatIn(org.apache.zookeeper.data.Stat stat) Description copied from interface:Statable
Have the operation fill the provided stat object- Specified by:
storingStatIn
in interfaceStatable<CreateProtectACLCreateModePathAndBytesable<String>>
- Parameters:
stat
- the stat to have filled in- Returns:
- this
-