Class CreateBuilderImpl
- java.lang.Object
-
- org.apache.curator.framework.imps.CreateBuilderImpl
-
- All Implemented Interfaces:
ACLable<BackgroundPathAndBytesable<java.lang.String>>,ACLBackgroundPathAndBytesable<java.lang.String>,ACLCreateModeBackgroundPathAndBytesable<java.lang.String>,Backgroundable<ErrorListenerPathAndBytesable<java.lang.String>>,BackgroundPathAndBytesable<java.lang.String>,Compressible<CreateBackgroundModeStatACLable>,CreateBuilder,CreateBuilder2,CreateBuilderMain,CreateModable<ACLBackgroundPathAndBytesable<java.lang.String>>,ErrorListenerPathAndBytesable<java.lang.String>,ParentACLable<BackgroundPathAndBytesable<java.lang.String>>,PathAndBytesable<java.lang.String>,Statable<CreateProtectACLCreateModePathAndBytesable<java.lang.String>>
public class CreateBuilderImpl extends java.lang.Object implements CreateBuilder, CreateBuilder2, ErrorListenerPathAndBytesable<java.lang.String>
-
-
Constructor Summary
Constructors Constructor Description CreateBuilderImpl(CuratorFrameworkImpl client, org.apache.zookeeper.CreateMode createMode, Backgrounding backgrounding, boolean createParentsIfNeeded, boolean createParentsAsContainers, boolean doProtected, boolean compress, boolean setDataIfExists, java.util.List<org.apache.zookeeper.data.ACL> aclList, org.apache.zookeeper.data.Stat storingStat, long ttl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CreateBackgroundModeStatACLablecompressed()Cause the data to be compressed using the configured compression providerProtectACLCreateModeStatPathAndBytesable<java.lang.String>creatingParentContainersIfNeeded()Causes any parent nodes to get created usingCreateMode.CONTAINERif they haven't already been.ProtectACLCreateModeStatPathAndBytesable<java.lang.String>creatingParentsIfNeeded()Causes any parent nodes to get created if they haven't already beenjava.lang.StringforPath(java.lang.String path)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[])).java.lang.StringforPath(java.lang.String givenPath, byte[] data)Commit the currently building operation using the given path and dataErrorListenerPathAndBytesable<java.lang.String>inBackground()Perform the action in the backgroundErrorListenerPathAndBytesable<java.lang.String>inBackground(java.lang.Object context)Perform the action in the backgroundErrorListenerPathAndBytesable<java.lang.String>inBackground(BackgroundCallback callback)Perform the action in the backgroundErrorListenerPathAndBytesable<java.lang.String>inBackground(BackgroundCallback callback, java.lang.Object context)Perform the action in the backgroundErrorListenerPathAndBytesable<java.lang.String>inBackground(BackgroundCallback callback, java.lang.Object context, java.util.concurrent.Executor executor)Perform the action in the backgroundErrorListenerPathAndBytesable<java.lang.String>inBackground(BackgroundCallback callback, java.util.concurrent.Executor executor)Perform the action in the backgroundCreateBuilder2orSetData()If the ZNode already exists, Curator will instead call setData()CreateBuilder2orSetData(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)CreateProtectACLCreateModePathAndBytesable<java.lang.String>storingStatIn(org.apache.zookeeper.data.Stat stat)Have the operation fill the provided stat objectACLBackgroundPathAndBytesable<java.lang.String>withACL(java.util.List<org.apache.zookeeper.data.ACL> aclList)Set an ACL list (default isZooDefs.Ids.OPEN_ACL_UNSAFE)ACLBackgroundPathAndBytesable<java.lang.String>withACL(java.util.List<org.apache.zookeeper.data.ACL> aclList, boolean applyToParents)Set an ACL list (default isZooDefs.Ids.OPEN_ACL_UNSAFE).ACLBackgroundPathAndBytesable<java.lang.String>withMode(org.apache.zookeeper.CreateMode mode)Set a create mode - the default isCreateMode.PERSISTENTACLPathAndBytesable<java.lang.String>withProtectedEphemeralSequential()ACLCreateModeStatBackgroundPathAndBytesable<java.lang.String>withProtection()Hat-tip to https://github.com/sbridges for pointing this outCreateBuilderMainwithTtl(long ttl)Specify a TTL when mode isCreateMode.PERSISTENT_WITH_TTLorCreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL.PathAndBytesable<java.lang.String>withUnhandledErrorListener(UnhandledErrorListener listener)Set an error listener for this background operation.
-
-
-
Constructor Detail
-
CreateBuilderImpl
public CreateBuilderImpl(CuratorFrameworkImpl client, org.apache.zookeeper.CreateMode createMode, Backgrounding backgrounding, boolean createParentsIfNeeded, boolean createParentsAsContainers, boolean doProtected, boolean compress, boolean setDataIfExists, java.util.List<org.apache.zookeeper.data.ACL> aclList, org.apache.zookeeper.data.Stat storingStat, long ttl)
-
-
Method Detail
-
setSetDataIfExistsVersion
public void setSetDataIfExistsVersion(int version)
-
orSetData
public CreateBuilder2 orSetData()
Description copied from interface:CreateBuilderIf the ZNode already exists, Curator will instead call setData()- Specified by:
orSetDatain interfaceCreateBuilder
-
orSetData
public CreateBuilder2 orSetData(int version)
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()
-
withTtl
public CreateBuilderMain withTtl(long ttl)
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
public CreateBackgroundModeStatACLable compressed()
Description copied from interface:CompressibleCause the data to be compressed using the configured compression provider- Specified by:
compressedin interfaceCompressible<CreateBackgroundModeStatACLable>- Returns:
- this
-
withACL
public ACLBackgroundPathAndBytesable<java.lang.String> withACL(java.util.List<org.apache.zookeeper.data.ACL> aclList)
Description copied from interface:ACLableSet an ACL list (default isZooDefs.Ids.OPEN_ACL_UNSAFE)- Specified by:
withACLin interfaceACLable<BackgroundPathAndBytesable<java.lang.String>>- Parameters:
aclList- the ACL list to use- Returns:
- this
-
withACL
public ACLBackgroundPathAndBytesable<java.lang.String> withACL(java.util.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<java.lang.String>>- Parameters:
aclList- the ACL list to useapplyToParents- if true, then the aclList is applied to the created parents.- Returns:
- this
-
creatingParentContainersIfNeeded
public ProtectACLCreateModeStatPathAndBytesable<java.lang.String> 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
public ProtectACLCreateModeStatPathAndBytesable<java.lang.String> 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
public ACLCreateModeStatBackgroundPathAndBytesable<java.lang.String> 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 GUID. If node creation fails the normal retry mechanism will occur. On the retry, the parent path is first searched for a node that has the GUID in it. If that node is found, it is assumed to be the lost node that was successfully created on the first try and is returned to the caller.
- Specified by:
withProtectionin interfaceCreateBuilderMain- Returns:
- this
-
withProtectedEphemeralSequential
public ACLPathAndBytesable<java.lang.String> withProtectedEphemeralSequential()
- Specified by:
withProtectedEphemeralSequentialin interfaceCreateBuilderMain- Returns:
- this
-
withMode
public ACLBackgroundPathAndBytesable<java.lang.String> withMode(org.apache.zookeeper.CreateMode mode)
Description copied from interface:CreateModableSet a create mode - the default isCreateMode.PERSISTENT- Specified by:
withModein interfaceCreateModable<ACLBackgroundPathAndBytesable<java.lang.String>>- Parameters:
mode- new create mode- Returns:
- this
-
inBackground
public ErrorListenerPathAndBytesable<java.lang.String> inBackground(BackgroundCallback callback, java.lang.Object context)
Description copied from interface:BackgroundablePerform the action in the background- Specified by:
inBackgroundin interfaceBackgroundable<ErrorListenerPathAndBytesable<java.lang.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<java.lang.String> inBackground(BackgroundCallback callback, java.lang.Object context, java.util.concurrent.Executor executor)
Description copied from interface:BackgroundablePerform the action in the background- Specified by:
inBackgroundin interfaceBackgroundable<ErrorListenerPathAndBytesable<java.lang.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
public ErrorListenerPathAndBytesable<java.lang.String> inBackground(BackgroundCallback callback)
Description copied from interface:BackgroundablePerform the action in the background- Specified by:
inBackgroundin interfaceBackgroundable<ErrorListenerPathAndBytesable<java.lang.String>>- Parameters:
callback- a functor that will get called when the operation has completed- Returns:
- this
-
inBackground
public ErrorListenerPathAndBytesable<java.lang.String> inBackground(BackgroundCallback callback, java.util.concurrent.Executor executor)
Description copied from interface:BackgroundablePerform the action in the background- Specified by:
inBackgroundin interfaceBackgroundable<ErrorListenerPathAndBytesable<java.lang.String>>- Parameters:
callback- a functor that will get called when the operation has completedexecutor- executor to use for the background call- Returns:
- this
-
inBackground
public ErrorListenerPathAndBytesable<java.lang.String> inBackground()
Description copied from interface:BackgroundablePerform the action in the background- Specified by:
inBackgroundin interfaceBackgroundable<ErrorListenerPathAndBytesable<java.lang.String>>- Returns:
- this
-
inBackground
public ErrorListenerPathAndBytesable<java.lang.String> inBackground(java.lang.Object context)
Description copied from interface:BackgroundablePerform the action in the background- Specified by:
inBackgroundin interfaceBackgroundable<ErrorListenerPathAndBytesable<java.lang.String>>- Parameters:
context- context object - will be available from the event sent to the listener- Returns:
- this
-
withUnhandledErrorListener
public PathAndBytesable<java.lang.String> withUnhandledErrorListener(UnhandledErrorListener listener)
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<java.lang.String>- Parameters:
listener- the listener- Returns:
- this for chaining
-
forPath
public java.lang.String forPath(java.lang.String path) throws java.lang.ExceptionDescription 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<java.lang.String>- Parameters:
path- the path- Returns:
- operation result if any
- Throws:
java.lang.Exception- errors
-
forPath
public java.lang.String forPath(java.lang.String givenPath, byte[] data) throws java.lang.ExceptionDescription copied from interface:PathAndBytesableCommit the currently building operation using the given path and data- Specified by:
forPathin interfacePathAndBytesable<java.lang.String>- Parameters:
givenPath- the pathdata- the data- Returns:
- operation result if any
- Throws:
java.lang.Exception- errors
-
performBackgroundOperation
public void performBackgroundOperation(org.apache.curator.framework.imps.OperationAndData<org.apache.curator.framework.imps.PathAndBytes> operationAndData) throws java.lang.Exception- Throws:
java.lang.Exception
-
storingStatIn
public CreateProtectACLCreateModePathAndBytesable<java.lang.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<java.lang.String>>- Parameters:
stat- the stat to have filled in- Returns:
- this
-
-