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
ConstructorsConstructorDescriptionCreateBuilderImpl(CuratorFrameworkBase 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.CONTAINERif 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()voidperformBackgroundOperation(org.apache.curator.framework.imps.OperationAndData<org.apache.curator.framework.imps.PathAndBytes> operationAndData) voidsetSetDataIfExistsVersion(int version) storingStatIn(org.apache.zookeeper.data.Stat stat) Have the operation fill the provided stat objectCause the data to be uncompressed, even if theCuratorFrameworkhas compressionEnabledSet 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.PERSISTENTHat-tip to https://github.com/sbridges for pointing this outwithTtl(long ttl) Specify a TTL when mode isCreateMode.PERSISTENT_WITH_TTLorCreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL.Set an error listener for this background operation.
-
Constructor Details
-
CreateBuilderImpl
public CreateBuilderImpl(CuratorFrameworkBase 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:CreateBuilderIf the ZNode already exists, Curator will instead call setData()- Specified by:
orSetDatain interfaceCreateBuilder
-
orSetData
Description copied from interface:CreateBuilderIf the ZNode already exists, Curator will instead call setData()- Specified by:
orSetDatain interfaceCreateBuilder- Parameters:
version- the version to use forCuratorFramework.setData()
-
idempotent
Description copied from interface:IdempotentableIf 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:
idempotentin interfaceIdempotentable<CreateBuilder2>- Returns:
- this:
-
withTtl
Description copied from interface:CreateBuilderSpecify a TTL when mode isCreateMode.PERSISTENT_WITH_TTLorCreateMode.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:
withTtlin interfaceCreateBuilder- Specified by:
withTtlin interfaceCreateBuilder2- Parameters:
ttl- the ttl- Returns:
- this for chaining
-
compressed
Description copied from interface:CompressibleCause the data to be compressed using the configured compression provider- Specified by:
compressedin interfaceCompressible<CreateBackgroundModeStatACLable>- Returns:
- this
-
uncompressed
Description copied from interface:CompressibleCause the data to be uncompressed, even if theCuratorFrameworkhas compressionEnabled- Specified by:
uncompressedin interfaceCompressible<CreateBackgroundModeStatACLable>- Returns:
- this
-
withACL
Description copied from interface:ACLableSet an ACL list (default isZooDefs.Ids.OPEN_ACL_UNSAFE)- Specified by:
withACLin 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:ParentACLableSet 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:
withACLin 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:CreateBuilderMainCauses any parent nodes to get created usingCreateMode.CONTAINERif 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:
creatingParentContainersIfNeededin interfaceCreateBuilderMain- Returns:
- this
-
creatingParentsIfNeeded
Description copied from interface:CreateBuilderMainCauses any parent nodes to get created if they haven't already been- Specified by:
creatingParentsIfNeededin interfaceCreateBuilderMain- Returns:
- this
-
withProtection
Description copied from interface:CreateBuilderMainHat-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:
withProtectionin interfaceCreateBuilderMain- Returns:
- this
-
withProtectedEphemeralSequential
- Specified by:
withProtectedEphemeralSequentialin interfaceCreateBuilderMain- Returns:
- this
-
withMode
Description copied from interface:CreateModableSet a create mode - the default isCreateMode.PERSISTENT- Specified by:
withModein interfaceCreateModable<ACLBackgroundPathAndBytesable<String>>- Parameters:
mode- new create mode- Returns:
- this
-
inBackground
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) Description copied from interface:BackgroundablePerform the action in the background- Specified by:
inBackgroundin 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:BackgroundablePerform the action in the background- Specified by:
inBackgroundin 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:BackgroundablePerform the action in the background- Specified by:
inBackgroundin 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:BackgroundablePerform the action in the background- Specified by:
inBackgroundin 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:BackgroundablePerform the action in the background- Specified by:
inBackgroundin interfaceBackgroundable<ErrorListenerPathAndBytesable<String>>- Returns:
- this
-
inBackground
Description copied from interface:BackgroundablePerform the action in the background- Specified by:
inBackgroundin interfaceBackgroundable<ErrorListenerPathAndBytesable<String>>- Parameters:
context- context object - will be available from the event sent to the listener- Returns:
- this
-
withUnhandledErrorListener
Description copied from interface:ErrorListenerPathAndBytesableSet 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:
withUnhandledErrorListenerin interfaceErrorListenerPathAndBytesable<String>- Parameters:
listener- the listener- Returns:
- this for chaining
-
forPath
Description copied from interface:PathAndBytesableCommit 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:
forPathin interfacePathAndBytesable<String>- Parameters:
path- the path- Returns:
- operation result if any
- Throws:
Exception- errors
-
forPath
Description copied from interface:PathAndBytesableCommit the currently building operation using the given path and data- Specified by:
forPathin 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:StatableHave the operation fill the provided stat object- Specified by:
storingStatInin interfaceStatable<CreateProtectACLCreateModePathAndBytesable<String>>- Parameters:
stat- the stat to have filled in- Returns:
- this
-