Commit 1d2dddc0 by 刘宇峰

框架完善-dubbo保持与公司版本一致,elasticjob与公司版本一致

1 parent 53b2c69a
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<curator.version>4.2.0</curator.version> <curator.version>2.12.0</curator.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
...@@ -44,11 +44,6 @@ ...@@ -44,11 +44,6 @@
<artifactId>curator-client</artifactId> <artifactId>curator-client</artifactId>
<version>${curator.version}</version> <version>${curator.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>${curator.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<curator.version>4.2.0</curator.version> <curator.version>2.12.0</curator.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
...@@ -88,11 +88,6 @@ ...@@ -88,11 +88,6 @@
<artifactId>curator-client</artifactId> <artifactId>curator-client</artifactId>
<version>${curator.version}</version> <version>${curator.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>${curator.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -28,10 +28,10 @@ ...@@ -28,10 +28,10 @@
<!-- <groupId>com.glsx</groupId>--> <!-- <groupId>com.glsx</groupId>-->
<!-- <artifactId>rest-admin-sleuth</artifactId>--> <!-- <artifactId>rest-admin-sleuth</artifactId>-->
<!-- </dependency>--> <!-- </dependency>-->
<dependency> <!-- <dependency>-->
<groupId>com.glsx</groupId> <!-- <groupId>com.glsx</groupId>-->
<artifactId>rest-admin-monitor</artifactId> <!-- <artifactId>rest-admin-monitor</artifactId>-->
</dependency> <!-- </dependency>-->
<dependency> <dependency>
<groupId>com.glsx</groupId> <groupId>com.glsx</groupId>
<artifactId>rest-admin-gateway-client</artifactId> <artifactId>rest-admin-gateway-client</artifactId>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<artifactId>rest-admin-dubbo</artifactId> <artifactId>rest-admin-dubbo</artifactId>
<properties> <properties>
<curator.version>4.2.0</curator.version> <curator.version>2.12.0</curator.version>
<dubbo.version>2.7.7</dubbo.version> <dubbo.version>2.7.7</dubbo.version>
<zookeeper.version>3.4.6</zookeeper.version> <zookeeper.version>3.4.6</zookeeper.version>
</properties> </properties>
......
package com.glsx.plat.dubbo.config; package com.glsx.plat.dubbo.config;
import static com.alibaba.spring.util.PropertySourcesUtils.getSubProperties; import com.alibaba.spring.context.config.ConfigurationBeanBinder;
import static org.apache.dubbo.spring.boot.util.DubboUtils.*;
import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE;
import java.util.Map;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.core.env.AbstractEnvironment; import org.springframework.core.env.*;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertyResolver;
import com.alibaba.spring.context.config.ConfigurationBeanBinder; import java.util.Map;
import static com.alibaba.spring.util.PropertySourcesUtils.getSubProperties;
import static org.apache.dubbo.spring.boot.util.DubboUtils.*;
import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE;
/** /**
* Dubbo Relaxed Binding Auto-{@link Configuration} for Spring Boot 2.0 * Dubbo Relaxed Binding Auto-{@link Configuration} for Spring Boot 2.0
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<artifactId>rest-admin-elasticjob</artifactId> <artifactId>rest-admin-elasticjob</artifactId>
<properties> <properties>
<curator.version>4.2.0</curator.version> <curator.version>2.12.0</curator.version>
<zookeeper.version>3.4.6</zookeeper.version> <zookeeper.version>3.4.6</zookeeper.version>
</properties> </properties>
...@@ -36,12 +36,16 @@ ...@@ -36,12 +36,16 @@
<dependency> <dependency>
<groupId>org.apache.curator</groupId> <groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId> <artifactId>curator-framework</artifactId>
<version>${curator.version}</version> <exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.curator</groupId> <groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId> <artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.apache.zookeeper</groupId> <groupId>org.apache.zookeeper</groupId>
......
package org.apache.curator.framework.api; //package org.apache.curator.framework.api;
//
/** ///**
* Licensed to the Apache Software Foundation (ASF) under one // * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file // * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information // * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file // * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the // * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance // * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at // * with the License. You may obtain a copy of the License at
* <p> // * <p>
* http://www.apache.org/licenses/LICENSE-2.0 // * http://www.apache.org/licenses/LICENSE-2.0
* <p> // * <p>
* Unless required by applicable law or agreed to in writing, // * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an // * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the // * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations // * specific language governing permissions and limitations
* under the License. // * under the License.
*/ // */
//
import org.apache.zookeeper.CreateMode; //import org.apache.zookeeper.CreateMode;
//
public interface CreateBuilderMain extends //public interface CreateBuilderMain extends
BackgroundPathAndBytesable<String>, // BackgroundPathAndBytesable<String>,
CreateModable<ACLBackgroundPathAndBytesable<String>>, // CreateModable<ACLBackgroundPathAndBytesable<String>>,
ACLCreateModeBackgroundPathAndBytesable<String>, // ACLCreateModeBackgroundPathAndBytesable<String>,
Compressible<CreateBackgroundModeStatACLable>, // Compressible<CreateBackgroundModeStatACLable>,
Statable<CreateProtectACLCreateModePathAndBytesable<String>> { // Statable<CreateProtectACLCreateModePathAndBytesable<String>> {
/** // /**
* Causes any parent nodes to get created if they haven't already been // * Causes any parent nodes to get created if they haven't already been
* // *
* @return this // * @return this
*/ // */
public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded();
// public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded(); // public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded();
//
/** //// public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded();
* Causes any parent nodes to get created using {@link 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 // * Causes any parent nodes to get created using {@link CreateMode#CONTAINER} if they haven't already been.
* are created as ordinary PERSISTENT nodes. // * 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
* @return this // * are created as ordinary PERSISTENT nodes.
*/ // *
public ProtectACLCreateModeStatPathAndBytesable<String> creatingParentContainersIfNeeded(); // * @return this
// */
/** // public ProtectACLCreateModeStatPathAndBytesable<String> creatingParentContainersIfNeeded();
* @return this //
* @deprecated this has been generalized to support all create modes. Instead, use: // /**
* <pre> // * @return this
* client.create().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)... // * @deprecated this has been generalized to support all create modes. Instead, use:
* </pre> // * <pre>
*/ // * client.create().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)...
@Deprecated // * </pre>
public ACLPathAndBytesable<String> withProtectedEphemeralSequential(); // */
// @Deprecated
/** // public ACLPathAndBytesable<String> withProtectedEphemeralSequential();
* <p> //
* Hat-tip to https://github.com/sbridges for pointing this out // /**
* </p> // * <p>
* // * Hat-tip to https://github.com/sbridges for pointing this out
* <p> // * </p>
* 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 // * <p>
* the created node name is returned to the client. However, the ZK session is still // * It turns out there is an edge case that exists when creating sequential-ephemeral
* valid so the ephemeral node is not deleted. Thus, there is no way for the client to // * nodes. The creation can succeed on the server, but the server can crash before
* determine what node was created for them. // * the created node name is returned to the client. However, the ZK session is still
* </p> // * valid so the ephemeral node is not deleted. Thus, there is no way for the client to
* // * determine what node was created for them.
* <p> // * </p>
* Even without sequential-ephemeral, however, the create can succeed on the sever // *
* but the client (for various reasons) will not know it. // * <p>
* </p> // * Even without sequential-ephemeral, however, the create can succeed on the sever
* // * but the client (for various reasons) will not know it.
* <p> // * </p>
* 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 // * <p>
* the normal retry mechanism will occur. On the retry, the parent path is first searched // * Putting the create builder into protection mode works around this.
* for a node that has the GUID in it. If that node is found, it is assumed to be the lost // * The name of the node that is created is prefixed with a GUID. If node creation fails
* node that was successfully created on the first try and is returned to the caller. // * the normal retry mechanism will occur. On the retry, the parent path is first searched
* </p> // * 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.
* @return this // * </p>
*/ // *
public ACLCreateModeStatBackgroundPathAndBytesable<String> withProtection(); // * @return this
} // */
// public ACLCreateModeStatBackgroundPathAndBytesable<String> withProtection();
//}
//
/** ///**
* Licensed to the Apache Software Foundation (ASF) under one // * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file // * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information // * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file // * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the // * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance // * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at // * with the License. You may obtain a copy of the License at
* <p> // * <p>
* http://www.apache.org/licenses/LICENSE-2.0 // * http://www.apache.org/licenses/LICENSE-2.0
* <p> // * <p>
* Unless required by applicable law or agreed to in writing, // * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an // * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the // * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations // * specific language governing permissions and limitations
* under the License. // * under the License.
*/ // */
//
package org.apache.curator.framework.imps; //package org.apache.curator.framework.imps;
//
import com.google.common.annotations.VisibleForTesting; //import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; //import com.google.common.base.Preconditions;
import com.google.common.base.Predicate; //import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; //import com.google.common.collect.Iterables;
import org.apache.curator.RetryLoop; //import org.apache.curator.RetryLoop;
import org.apache.curator.drivers.OperationTrace; //import org.apache.curator.drivers.OperationTrace;
import org.apache.curator.framework.api.*; //import org.apache.curator.framework.api.*;
import org.apache.curator.framework.api.transaction.OperationType; //import org.apache.curator.framework.api.transaction.OperationType;
import org.apache.curator.framework.api.transaction.TransactionCreateBuilder; //import org.apache.curator.framework.api.transaction.TransactionCreateBuilder;
import org.apache.curator.framework.api.transaction.TransactionCreateBuilder2; //import org.apache.curator.framework.api.transaction.TransactionCreateBuilder2;
import org.apache.curator.utils.InternalACLProvider; //import org.apache.curator.utils.InternalACLProvider;
import org.apache.curator.utils.ThreadUtils; //import org.apache.curator.utils.ThreadUtils;
import org.apache.curator.utils.ZKPaths; //import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.AsyncCallback; //import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode; //import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException; //import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.Op; //import org.apache.zookeeper.Op;
import org.apache.zookeeper.data.ACL; //import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Stat; //import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.server.DataTree; //import org.apache.zookeeper.server.DataTree;
import org.slf4j.Logger; //import org.slf4j.Logger;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
//
import java.util.List; //import java.util.List;
import java.util.concurrent.Callable; //import java.util.concurrent.Callable;
import java.util.concurrent.Executor; //import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean; //import java.util.concurrent.atomic.AtomicBoolean;
//
public class CreateBuilderImpl implements CreateBuilder, CreateBuilder2, BackgroundOperation<PathAndBytes>, ErrorListenerPathAndBytesable<String> { //public class CreateBuilderImpl implements CreateBuilder, CreateBuilder2, BackgroundOperation<PathAndBytes>, ErrorListenerPathAndBytesable<String> {
private final Logger log = LoggerFactory.getLogger(getClass()); // private final Logger log = LoggerFactory.getLogger(getClass());
private final CuratorFrameworkImpl client; // private final CuratorFrameworkImpl client;
private final ProtectedMode protectedMode = new ProtectedMode(); // private final ProtectedMode protectedMode = new ProtectedMode();
private CreateMode createMode; // private CreateMode createMode;
private Backgrounding backgrounding; // private Backgrounding backgrounding;
private boolean createParentsIfNeeded; // private boolean createParentsIfNeeded;
private boolean createParentsAsContainers; // private boolean createParentsAsContainers;
private boolean compress; // private boolean compress;
private boolean setDataIfExists; // private boolean setDataIfExists;
private int setDataIfExistsVersion = -1; // private int setDataIfExistsVersion = -1;
private ACLing acling; // private ACLing acling;
private Stat storingStat; // private Stat storingStat;
private long ttl; // private long ttl;
//
@VisibleForTesting // @VisibleForTesting
boolean failNextCreateForTesting = false; // boolean failNextCreateForTesting = false;
//
@VisibleForTesting // @VisibleForTesting
static final String PROTECTED_PREFIX = "_c_"; // static final String PROTECTED_PREFIX = "_c_";
//
CreateBuilderImpl(CuratorFrameworkImpl client) { // CreateBuilderImpl(CuratorFrameworkImpl client) {
this.client = client; // this.client = client;
createMode = CreateMode.PERSISTENT; // createMode = CreateMode.PERSISTENT;
backgrounding = new Backgrounding(); // backgrounding = new Backgrounding();
acling = new ACLing(client.getAclProvider()); // acling = new ACLing(client.getAclProvider());
createParentsIfNeeded = false; // createParentsIfNeeded = false;
createParentsAsContainers = false; // createParentsAsContainers = false;
compress = false; // compress = false;
setDataIfExists = false; // setDataIfExists = false;
storingStat = null; // storingStat = null;
ttl = -1; // ttl = -1;
} // }
//
public CreateBuilderImpl(CuratorFrameworkImpl client, CreateMode createMode, Backgrounding backgrounding, boolean createParentsIfNeeded, boolean createParentsAsContainers, boolean doProtected, boolean compress, boolean setDataIfExists, List<ACL> aclList, Stat storingStat, long ttl) { // public CreateBuilderImpl(CuratorFrameworkImpl client, CreateMode createMode, Backgrounding backgrounding, boolean createParentsIfNeeded, boolean createParentsAsContainers, boolean doProtected, boolean compress, boolean setDataIfExists, List<ACL> aclList, Stat storingStat, long ttl) {
this.client = client; // this.client = client;
this.createMode = createMode; // this.createMode = createMode;
this.backgrounding = backgrounding; // this.backgrounding = backgrounding;
this.createParentsIfNeeded = createParentsIfNeeded; // this.createParentsIfNeeded = createParentsIfNeeded;
this.createParentsAsContainers = createParentsAsContainers; // this.createParentsAsContainers = createParentsAsContainers;
this.compress = compress; // this.compress = compress;
this.setDataIfExists = setDataIfExists; // this.setDataIfExists = setDataIfExists;
this.acling = new ACLing(client.getAclProvider(), aclList); // this.acling = new ACLing(client.getAclProvider(), aclList);
this.storingStat = storingStat; // this.storingStat = storingStat;
this.ttl = ttl; // this.ttl = ttl;
if (doProtected) { // if (doProtected) {
protectedMode.setProtectedMode(); // protectedMode.setProtectedMode();
} // }
} // }
//
public void setSetDataIfExistsVersion(int version) { // public void setSetDataIfExistsVersion(int version) {
this.setDataIfExistsVersion = version; // this.setDataIfExistsVersion = version;
} // }
//
@Override // @Override
public CreateBuilder2 orSetData() { // public CreateBuilder2 orSetData() {
return orSetData(-1); // return orSetData(-1);
} // }
//
@Override // @Override
public CreateBuilder2 orSetData(int version) { // public CreateBuilder2 orSetData(int version) {
setDataIfExists = true; // setDataIfExists = true;
setDataIfExistsVersion = version; // setDataIfExistsVersion = version;
return this; // return this;
} // }
//
@Override // @Override
public CreateBuilderMain withTtl(long ttl) { // public CreateBuilderMain withTtl(long ttl) {
Preconditions.checkState(!client.isZk34CompatibilityMode(), "TTLs are not support when running in ZooKeeper 3.4 compatibility mode"); // Preconditions.checkState(!client.isZk34CompatibilityMode(), "TTLs are not support when running in ZooKeeper 3.4 compatibility mode");
this.ttl = ttl; // this.ttl = ttl;
return this; // return this;
} // }
//
<T> TransactionCreateBuilder<T> asTransactionCreateBuilder(final T context, final CuratorMultiTransactionRecord transaction) { // <T> TransactionCreateBuilder<T> asTransactionCreateBuilder(final T context, final CuratorMultiTransactionRecord transaction) {
return new TransactionCreateBuilder<T>() { // return new TransactionCreateBuilder<T>() {
@Override // @Override
public PathAndBytesable<T> withACL(List<ACL> aclList) { // public PathAndBytesable<T> withACL(List<ACL> aclList) {
return withACL(aclList, false); // return withACL(aclList, false);
} // }
//
@Override // @Override
public PathAndBytesable<T> withACL(List<ACL> aclList, boolean applyToParents) { // public PathAndBytesable<T> withACL(List<ACL> aclList, boolean applyToParents) {
CreateBuilderImpl.this.withACL(aclList, applyToParents); // CreateBuilderImpl.this.withACL(aclList, applyToParents);
return this; // return this;
} // }
//
@Override // @Override
public TransactionCreateBuilder2<T> withTtl(long ttl) { // public TransactionCreateBuilder2<T> withTtl(long ttl) {
CreateBuilderImpl.this.withTtl(ttl); // CreateBuilderImpl.this.withTtl(ttl);
return this; // return this;
} // }
//
@Override // @Override
public ACLPathAndBytesable<T> withMode(CreateMode mode) { // public ACLPathAndBytesable<T> withMode(CreateMode mode) {
CreateBuilderImpl.this.withMode(mode); // CreateBuilderImpl.this.withMode(mode);
return this; // return this;
} // }
//
@Override // @Override
public ACLCreateModePathAndBytesable<T> compressed() { // public ACLCreateModePathAndBytesable<T> compressed() {
CreateBuilderImpl.this.compressed(); // CreateBuilderImpl.this.compressed();
return this; // return this;
} // }
//
@Override // @Override
public T forPath(String path) throws Exception { // public T forPath(String path) throws Exception {
return forPath(path, client.getDefaultData()); // return forPath(path, client.getDefaultData());
} // }
//
@Override // @Override
public T forPath(String path, byte[] data) throws Exception { // public T forPath(String path, byte[] data) throws Exception {
if (compress) { // if (compress) {
data = client.getCompressionProvider().compress(path, data); // data = client.getCompressionProvider().compress(path, data);
} // }
//
String fixedPath = client.fixForNamespace(path); // String fixedPath = client.fixForNamespace(path);
if (client.isZk34CompatibilityMode()) { // if (client.isZk34CompatibilityMode()) {
transaction.add(Op.create(fixedPath, data, acling.getAclList(path), createMode), OperationType.CREATE, path); // transaction.add(Op.create(fixedPath, data, acling.getAclList(path), createMode), OperationType.CREATE, path);
} else { // } else {
transaction.add(Op.create(fixedPath, data, acling.getAclList(path), createMode), OperationType.CREATE, path); // transaction.add(Op.create(fixedPath, data, acling.getAclList(path), createMode), OperationType.CREATE, path);
} // }
return context; // return context;
} // }
}; // };
} // }
//
@Override // @Override
public CreateBackgroundModeStatACLable compressed() { // public CreateBackgroundModeStatACLable compressed() {
compress = true; // compress = true;
return new CreateBackgroundModeStatACLable() { // return new CreateBackgroundModeStatACLable() {
@Override // @Override
public CreateBackgroundModeACLable storingStatIn(Stat stat) { // public CreateBackgroundModeACLable storingStatIn(Stat stat) {
storingStat = stat; // storingStat = stat;
return asCreateBackgroundModeACLable(); // return asCreateBackgroundModeACLable();
} // }
//
@Override // @Override
public ACLCreateModePathAndBytesable<String> creatingParentsIfNeeded() { // public ACLCreateModePathAndBytesable<String> creatingParentsIfNeeded() {
createParentsIfNeeded = true; // createParentsIfNeeded = true;
return asACLCreateModePathAndBytesable(); // return asACLCreateModePathAndBytesable();
} // }
//
@Override // @Override
public ACLCreateModePathAndBytesable<String> creatingParentContainersIfNeeded() { // public ACLCreateModePathAndBytesable<String> creatingParentContainersIfNeeded() {
setCreateParentsAsContainers(); // setCreateParentsAsContainers();
return creatingParentsIfNeeded(); // return creatingParentsIfNeeded();
} // }
//
@Override // @Override
public ACLPathAndBytesable<String> withProtectedEphemeralSequential() { // public ACLPathAndBytesable<String> withProtectedEphemeralSequential() {
return CreateBuilderImpl.this.withProtectedEphemeralSequential(); // return CreateBuilderImpl.this.withProtectedEphemeralSequential();
} // }
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) {
return CreateBuilderImpl.this.withACL(aclList); // return CreateBuilderImpl.this.withACL(aclList);
} // }
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
return CreateBuilderImpl.this.withACL(aclList, applyToParents); // return CreateBuilderImpl.this.withACL(aclList, applyToParents);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) {
return CreateBuilderImpl.this.inBackground(callback, context); // return CreateBuilderImpl.this.inBackground(callback, context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, context, executor); // return CreateBuilderImpl.this.inBackground(callback, context, executor);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground() { // public ErrorListenerPathAndBytesable<String> inBackground() {
return CreateBuilderImpl.this.inBackground(); // return CreateBuilderImpl.this.inBackground();
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(Object context) {
return CreateBuilderImpl.this.inBackground(context); // return CreateBuilderImpl.this.inBackground(context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) {
return CreateBuilderImpl.this.inBackground(callback); // return CreateBuilderImpl.this.inBackground(callback);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, executor); // return CreateBuilderImpl.this.inBackground(callback, executor);
} // }
//
@Override // @Override
public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) { // public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) {
return CreateBuilderImpl.this.withMode(mode); // return CreateBuilderImpl.this.withMode(mode);
} // }
//
@Override // @Override
public String forPath(String path, byte[] data) throws Exception { // public String forPath(String path, byte[] data) throws Exception {
return CreateBuilderImpl.this.forPath(path, data); // return CreateBuilderImpl.this.forPath(path, data);
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return CreateBuilderImpl.this.forPath(path); // return CreateBuilderImpl.this.forPath(path);
} // }
}; // };
} // }
//
@Override // @Override
public ACLBackgroundPathAndBytesable<String> withACL(List<ACL> aclList) { // public ACLBackgroundPathAndBytesable<String> withACL(List<ACL> aclList) {
return withACL(aclList, false); // return withACL(aclList, false);
} // }
//
@Override // @Override
public ACLBackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public ACLBackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
acling = new ACLing(client.getAclProvider(), aclList, applyToParents); // acling = new ACLing(client.getAclProvider(), aclList, applyToParents);
return new ACLBackgroundPathAndBytesable<String>() { // return new ACLBackgroundPathAndBytesable<String>() {
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) {
return CreateBuilderImpl.this.withACL(aclList); // return CreateBuilderImpl.this.withACL(aclList);
} // }
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
return CreateBuilderImpl.this.withACL(aclList, applyToParents); // return CreateBuilderImpl.this.withACL(aclList, applyToParents);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground() { // public ErrorListenerPathAndBytesable<String> inBackground() {
return CreateBuilderImpl.this.inBackground(); // return CreateBuilderImpl.this.inBackground();
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) {
return CreateBuilderImpl.this.inBackground(callback, context); // return CreateBuilderImpl.this.inBackground(callback, context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, context, executor); // return CreateBuilderImpl.this.inBackground(callback, context, executor);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(Object context) {
return CreateBuilderImpl.this.inBackground(context); // return CreateBuilderImpl.this.inBackground(context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) {
return CreateBuilderImpl.this.inBackground(callback); // return CreateBuilderImpl.this.inBackground(callback);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, executor); // return CreateBuilderImpl.this.inBackground(callback, executor);
} // }
//
@Override // @Override
public String forPath(String path, byte[] data) throws Exception { // public String forPath(String path, byte[] data) throws Exception {
return CreateBuilderImpl.this.forPath(path, data); // return CreateBuilderImpl.this.forPath(path, data);
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return CreateBuilderImpl.this.forPath(path); // return CreateBuilderImpl.this.forPath(path);
} // }
}; // };
} // }
//
@Override // @Override
public ProtectACLCreateModeStatPathAndBytesable<String> creatingParentContainersIfNeeded() { // public ProtectACLCreateModeStatPathAndBytesable<String> creatingParentContainersIfNeeded() {
setCreateParentsAsContainers(); // setCreateParentsAsContainers();
return creatingParentsIfNeeded(); // return creatingParentsIfNeeded();
} // }
//
private void setCreateParentsAsContainers() { // private void setCreateParentsAsContainers() {
if (client.useContainerParentsIfAvailable()) { // if (client.useContainerParentsIfAvailable()) {
createParentsAsContainers = true; // createParentsAsContainers = true;
} // }
} // }
//
@Override // @Override
public ProtectACLCreateModeStatPathAndBytesable<String> creatingParentsIfNeeded() { // public ProtectACLCreateModeStatPathAndBytesable<String> creatingParentsIfNeeded() {
createParentsIfNeeded = true; // createParentsIfNeeded = true;
return new ProtectACLCreateModeStatPathAndBytesable<String>() { // return new ProtectACLCreateModeStatPathAndBytesable<String>() {
@Override // @Override
public ACLCreateModeBackgroundPathAndBytesable<String> withProtection() { // public ACLCreateModeBackgroundPathAndBytesable<String> withProtection() {
return CreateBuilderImpl.this.withProtection(); // return CreateBuilderImpl.this.withProtection();
} // }
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) {
return withACL(aclList, false); // return withACL(aclList, false);
} // }
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
return CreateBuilderImpl.this.withACL(aclList, applyToParents); // return CreateBuilderImpl.this.withACL(aclList, applyToParents);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground() { // public ErrorListenerPathAndBytesable<String> inBackground() {
return CreateBuilderImpl.this.inBackground(); // return CreateBuilderImpl.this.inBackground();
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(Object context) {
return CreateBuilderImpl.this.inBackground(context); // return CreateBuilderImpl.this.inBackground(context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) {
return CreateBuilderImpl.this.inBackground(callback); // return CreateBuilderImpl.this.inBackground(callback);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) {
return CreateBuilderImpl.this.inBackground(callback, context); // return CreateBuilderImpl.this.inBackground(callback, context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, executor); // return CreateBuilderImpl.this.inBackground(callback, executor);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, context, executor); // return CreateBuilderImpl.this.inBackground(callback, context, executor);
} // }
//
@Override // @Override
public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) { // public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) {
return CreateBuilderImpl.this.withMode(mode); // return CreateBuilderImpl.this.withMode(mode);
} // }
//
@Override // @Override
public String forPath(String path, byte[] data) throws Exception { // public String forPath(String path, byte[] data) throws Exception {
return CreateBuilderImpl.this.forPath(path, data); // return CreateBuilderImpl.this.forPath(path, data);
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return CreateBuilderImpl.this.forPath(path); // return CreateBuilderImpl.this.forPath(path);
} // }
//
@Override // @Override
public ACLBackgroundPathAndBytesable<String> storingStatIn(Stat stat) { // public ACLBackgroundPathAndBytesable<String> storingStatIn(Stat stat) {
storingStat = stat; // storingStat = stat;
return CreateBuilderImpl.this; // return CreateBuilderImpl.this;
} // }
}; // };
} // }
//
@Override // @Override
public ACLCreateModeStatBackgroundPathAndBytesable<String> withProtection() { // public ACLCreateModeStatBackgroundPathAndBytesable<String> withProtection() {
protectedMode.setProtectedMode(); // protectedMode.setProtectedMode();
return asACLCreateModeStatBackgroundPathAndBytesable(); // return asACLCreateModeStatBackgroundPathAndBytesable();
} // }
//
@Override // @Override
public ACLPathAndBytesable<String> withProtectedEphemeralSequential() { // public ACLPathAndBytesable<String> withProtectedEphemeralSequential() {
protectedMode.setProtectedMode(); // protectedMode.setProtectedMode();
createMode = CreateMode.EPHEMERAL_SEQUENTIAL; // createMode = CreateMode.EPHEMERAL_SEQUENTIAL;
//
return new ACLPathAndBytesable<String>() { // return new ACLPathAndBytesable<String>() {
@Override // @Override
public PathAndBytesable<String> withACL(List<ACL> aclList) { // public PathAndBytesable<String> withACL(List<ACL> aclList) {
return CreateBuilderImpl.this.withACL(aclList); // return CreateBuilderImpl.this.withACL(aclList);
} // }
//
@Override // @Override
public PathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public PathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
return CreateBuilderImpl.this.withACL(aclList, applyToParents); // return CreateBuilderImpl.this.withACL(aclList, applyToParents);
} // }
//
@Override // @Override
public String forPath(String path, byte[] data) throws Exception { // public String forPath(String path, byte[] data) throws Exception {
return CreateBuilderImpl.this.forPath(path, data); // return CreateBuilderImpl.this.forPath(path, data);
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return CreateBuilderImpl.this.forPath(path); // return CreateBuilderImpl.this.forPath(path);
} // }
}; // };
} // }
//
@Override // @Override
public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) { // public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) {
createMode = mode; // createMode = mode;
return this; // return this;
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) {
backgrounding = new Backgrounding(callback, context); // backgrounding = new Backgrounding(callback, context);
return this; // return this;
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) {
backgrounding = new Backgrounding(client, callback, context, executor); // backgrounding = new Backgrounding(client, callback, context, executor);
return this; // return this;
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) {
backgrounding = new Backgrounding(callback); // backgrounding = new Backgrounding(callback);
return this; // return this;
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) {
backgrounding = new Backgrounding(client, callback, executor); // backgrounding = new Backgrounding(client, callback, executor);
return this; // return this;
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground() { // public ErrorListenerPathAndBytesable<String> inBackground() {
backgrounding = new Backgrounding(true); // backgrounding = new Backgrounding(true);
return this; // return this;
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(Object context) {
backgrounding = new Backgrounding(context); // backgrounding = new Backgrounding(context);
return this; // return this;
} // }
//
@Override // @Override
public PathAndBytesable<String> withUnhandledErrorListener(UnhandledErrorListener listener) { // public PathAndBytesable<String> withUnhandledErrorListener(UnhandledErrorListener listener) {
backgrounding = new Backgrounding(backgrounding, listener); // backgrounding = new Backgrounding(backgrounding, listener);
return this; // return this;
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return forPath(path, client.getDefaultData()); // return forPath(path, client.getDefaultData());
} // }
//
@Override // @Override
public String forPath(final String givenPath, byte[] data) throws Exception { // public String forPath(final String givenPath, byte[] data) throws Exception {
if (compress) { // if (compress) {
data = client.getCompressionProvider().compress(givenPath, data); // data = client.getCompressionProvider().compress(givenPath, data);
} // }
//
final String adjustedPath = adjustPath(client.fixForNamespace(givenPath, createMode.isSequential())); // final String adjustedPath = adjustPath(client.fixForNamespace(givenPath, createMode.isSequential()));
List<ACL> aclList = acling.getAclList(adjustedPath); // List<ACL> aclList = acling.getAclList(adjustedPath);
client.getSchemaSet().getSchema(givenPath).validateCreate(createMode, givenPath, data, aclList); // client.getSchemaSet().getSchema(givenPath).validateCreate(createMode, givenPath, data, aclList);
//
String returnPath = null; // String returnPath = null;
if (backgrounding.inBackground()) { // if (backgrounding.inBackground()) {
pathInBackground(adjustedPath, data, givenPath); // pathInBackground(adjustedPath, data, givenPath);
} else { // } else {
String path = protectedPathInForeground(adjustedPath, data, aclList); // String path = protectedPathInForeground(adjustedPath, data, aclList);
returnPath = client.unfixForNamespace(path); // returnPath = client.unfixForNamespace(path);
} // }
return returnPath; // return returnPath;
} // }
//
private String protectedPathInForeground(String adjustedPath, byte[] data, List<ACL> aclList) throws Exception { // private String protectedPathInForeground(String adjustedPath, byte[] data, List<ACL> aclList) throws Exception {
try { // try {
return pathInForeground(adjustedPath, data, aclList); // return pathInForeground(adjustedPath, data, aclList);
} catch (Exception e) { // } catch (Exception e) {
ThreadUtils.checkInterrupted(e); // ThreadUtils.checkInterrupted(e);
if ((e instanceof KeeperException.ConnectionLossException || // if ((e instanceof KeeperException.ConnectionLossException ||
!(e instanceof KeeperException)) && protectedMode.doProtected()) { // !(e instanceof KeeperException)) && protectedMode.doProtected()) {
/* // /*
* CURATOR-45 + CURATOR-79: we don't know if the create operation was successful or not, // * CURATOR-45 + CURATOR-79: we don't know if the create operation was successful or not,
* register the znode to be sure it is deleted later. // * register the znode to be sure it is deleted later.
*/ // */
new FindAndDeleteProtectedNodeInBackground(client, ZKPaths.getPathAndNode(adjustedPath).getPath(), protectedMode.protectedId()).execute(); // new FindAndDeleteProtectedNodeInBackground(client, ZKPaths.getPathAndNode(adjustedPath).getPath(), protectedMode.protectedId()).execute();
/* // /*
* The current UUID is scheduled to be deleted, it is not safe to use it again. // * The current UUID is scheduled to be deleted, it is not safe to use it again.
* If this builder is used again later create a new UUID // * If this builder is used again later create a new UUID
*/ // */
protectedMode.resetProtectedId(); // protectedMode.resetProtectedId();
} // }
//
throw e; // throw e;
} // }
} // }
//
@Override // @Override
public void performBackgroundOperation(final OperationAndData<PathAndBytes> operationAndData) throws Exception { // public void performBackgroundOperation(final OperationAndData<PathAndBytes> operationAndData) throws Exception {
try { // try {
final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-Background"); // final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-Background");
final byte[] data = operationAndData.getData().getData(); // final byte[] data = operationAndData.getData().getData();
//
final CompatibleCreateCallback mainCallback = new CompatibleCreateCallback() { // final CompatibleCreateCallback mainCallback = new CompatibleCreateCallback() {
@Override // @Override
public void processResult(int rc, String path, Object ctx, String name, Stat stat) { // public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
trace.setReturnCode(rc).setRequestBytesLength(data).setPath(path).commit(); // trace.setReturnCode(rc).setRequestBytesLength(data).setPath(path).commit();
//
if ((stat != null) && (storingStat != null)) { // if ((stat != null) && (storingStat != null)) {
DataTree.copyStat(stat, storingStat); // DataTree.copyStat(stat, storingStat);
} // }
//
if ((rc == KeeperException.Code.NONODE.intValue()) && createParentsIfNeeded) { // if ((rc == KeeperException.Code.NONODE.intValue()) && createParentsIfNeeded) {
backgroundCreateParentsThenNode(client, operationAndData, operationAndData.getData().getPath(), backgrounding, acling.getACLProviderForParents(), createParentsAsContainers); // backgroundCreateParentsThenNode(client, operationAndData, operationAndData.getData().getPath(), backgrounding, acling.getACLProviderForParents(), createParentsAsContainers);
} else if ((rc == KeeperException.Code.NODEEXISTS.intValue()) && setDataIfExists) { // } else if ((rc == KeeperException.Code.NODEEXISTS.intValue()) && setDataIfExists) {
backgroundSetData(client, operationAndData, operationAndData.getData().getPath(), backgrounding); // backgroundSetData(client, operationAndData, operationAndData.getData().getPath(), backgrounding);
} else { // } else {
sendBackgroundResponse(rc, path, ctx, name, stat, operationAndData); // sendBackgroundResponse(rc, path, ctx, name, stat, operationAndData);
} // }
} // }
}; // };
//
if (client.isZk34CompatibilityMode()) { // if (client.isZk34CompatibilityMode()) {
AsyncCallback.StringCallback stringCallback = new AsyncCallback.StringCallback() { // AsyncCallback.StringCallback stringCallback = new AsyncCallback.StringCallback() {
@Override // @Override
public void processResult(int rc, String path, Object ctx, String name) { // public void processResult(int rc, String path, Object ctx, String name) {
mainCallback.processResult(rc, path, ctx, name, null); // mainCallback.processResult(rc, path, ctx, name, null);
} // }
}; // };
client.getZooKeeper().create // client.getZooKeeper().create
( // (
operationAndData.getData().getPath(), // operationAndData.getData().getPath(),
data, // data,
acling.getAclList(operationAndData.getData().getPath()), // acling.getAclList(operationAndData.getData().getPath()),
createMode, // createMode,
stringCallback, // stringCallback,
backgrounding.getContext() // backgrounding.getContext()
); // );
} else { // } else {
CreateZK35.create // CreateZK35.create
( // (
client.getZooKeeper(), // client.getZooKeeper(),
operationAndData.getData().getPath(), // operationAndData.getData().getPath(),
data, // data,
acling.getAclList(operationAndData.getData().getPath()), // acling.getAclList(operationAndData.getData().getPath()),
createMode, // createMode,
mainCallback, // mainCallback,
backgrounding.getContext(), // backgrounding.getContext(),
ttl // ttl
); // );
} // }
} catch (Throwable e) { // } catch (Throwable e) {
backgrounding.checkError(e, null); // backgrounding.checkError(e, null);
} // }
} // }
//
@Override // @Override
public CreateProtectACLCreateModePathAndBytesable<String> storingStatIn(Stat stat) { // public CreateProtectACLCreateModePathAndBytesable<String> storingStatIn(Stat stat) {
storingStat = stat; // storingStat = stat;
//
return new CreateProtectACLCreateModePathAndBytesable<String>() { // return new CreateProtectACLCreateModePathAndBytesable<String>() {
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) {
return CreateBuilderImpl.this.withACL(aclList); // return CreateBuilderImpl.this.withACL(aclList);
} // }
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
return CreateBuilderImpl.this.withACL(aclList, applyToParents); // return CreateBuilderImpl.this.withACL(aclList, applyToParents);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground() { // public ErrorListenerPathAndBytesable<String> inBackground() {
return CreateBuilderImpl.this.inBackground(); // return CreateBuilderImpl.this.inBackground();
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(Object context) {
return CreateBuilderImpl.this.inBackground(context); // return CreateBuilderImpl.this.inBackground(context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) {
return CreateBuilderImpl.this.inBackground(callback); // return CreateBuilderImpl.this.inBackground(callback);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) {
return CreateBuilderImpl.this.inBackground(callback, context); // return CreateBuilderImpl.this.inBackground(callback, context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, executor); // return CreateBuilderImpl.this.inBackground(callback, executor);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context,
Executor executor) { // Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, context, executor); // return CreateBuilderImpl.this.inBackground(callback, context, executor);
} // }
//
@Override // @Override
public String forPath(String path, byte[] data) throws Exception { // public String forPath(String path, byte[] data) throws Exception {
return CreateBuilderImpl.this.forPath(path, data); // return CreateBuilderImpl.this.forPath(path, data);
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return CreateBuilderImpl.this.forPath(path); // return CreateBuilderImpl.this.forPath(path);
} // }
//
@Override // @Override
public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) { // public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) {
return CreateBuilderImpl.this.withMode(mode); // return CreateBuilderImpl.this.withMode(mode);
} // }
//
@Override // @Override
public ACLCreateModeBackgroundPathAndBytesable<String> withProtection() { // public ACLCreateModeBackgroundPathAndBytesable<String> withProtection() {
return CreateBuilderImpl.this.withProtection(); // return CreateBuilderImpl.this.withProtection();
} // }
//
@Override // @Override
public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded() { // public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded() {
return CreateBuilderImpl.this.creatingParentsIfNeeded(); // return CreateBuilderImpl.this.creatingParentsIfNeeded();
} // }
//
@Override // @Override
public ProtectACLCreateModePathAndBytesable<String> creatingParentContainersIfNeeded() { // public ProtectACLCreateModePathAndBytesable<String> creatingParentContainersIfNeeded() {
return CreateBuilderImpl.this.creatingParentContainersIfNeeded(); // return CreateBuilderImpl.this.creatingParentContainersIfNeeded();
} // }
}; // };
} // }
//
private static String getProtectedPrefix(String protectedId) { // private static String getProtectedPrefix(String protectedId) {
return PROTECTED_PREFIX + protectedId + "-"; // return PROTECTED_PREFIX + protectedId + "-";
} // }
//
static <T> void backgroundCreateParentsThenNode(final CuratorFrameworkImpl client, final OperationAndData<T> mainOperationAndData, final String path, Backgrounding backgrounding, final InternalACLProvider aclProvider, final boolean createParentsAsContainers) { // static <T> void backgroundCreateParentsThenNode(final CuratorFrameworkImpl client, final OperationAndData<T> mainOperationAndData, final String path, Backgrounding backgrounding, final InternalACLProvider aclProvider, final boolean createParentsAsContainers) {
BackgroundOperation<T> operation = new BackgroundOperation<T>() { // BackgroundOperation<T> operation = new BackgroundOperation<T>() {
@Override // @Override
public void performBackgroundOperation(OperationAndData<T> dummy) throws Exception { // public void performBackgroundOperation(OperationAndData<T> dummy) throws Exception {
try { // try {
ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers); // ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers);
} catch (KeeperException e) { // } catch (KeeperException e) {
if (!RetryLoop.isRetryException(e)) { // if (!RetryLoop.isRetryException(e)) {
throw e; // throw e;
} // }
// otherwise safe to ignore as it will get retried // // otherwise safe to ignore as it will get retried
} // }
client.queueOperation(mainOperationAndData); // client.queueOperation(mainOperationAndData);
} // }
}; // };
OperationAndData<T> parentOperation = new OperationAndData<>(operation, mainOperationAndData.getData(), null, null, backgrounding.getContext(), null); // OperationAndData<T> parentOperation = new OperationAndData<>(operation, mainOperationAndData.getData(), null, null, backgrounding.getContext(), null);
client.queueOperation(parentOperation); // client.queueOperation(parentOperation);
} // }
//
private void backgroundSetData(final CuratorFrameworkImpl client, final OperationAndData<PathAndBytes> mainOperationAndData, final String path, final Backgrounding backgrounding) { // private void backgroundSetData(final CuratorFrameworkImpl client, final OperationAndData<PathAndBytes> mainOperationAndData, final String path, final Backgrounding backgrounding) {
final AsyncCallback.StatCallback statCallback = new AsyncCallback.StatCallback() { // final AsyncCallback.StatCallback statCallback = new AsyncCallback.StatCallback() {
@Override // @Override
public void processResult(int rc, String path, Object ctx, Stat stat) { // public void processResult(int rc, String path, Object ctx, Stat stat) {
if (rc == KeeperException.Code.NONODE.intValue()) { // if (rc == KeeperException.Code.NONODE.intValue()) {
client.queueOperation(mainOperationAndData); // try to create it again // client.queueOperation(mainOperationAndData); // try to create it again
} else { // } else {
sendBackgroundResponse(rc, path, ctx, path, stat, mainOperationAndData); // sendBackgroundResponse(rc, path, ctx, path, stat, mainOperationAndData);
} // }
} // }
}; // };
BackgroundOperation<PathAndBytes> operation = new BackgroundOperation<PathAndBytes>() { // BackgroundOperation<PathAndBytes> operation = new BackgroundOperation<PathAndBytes>() {
@Override // @Override
public void performBackgroundOperation(OperationAndData<PathAndBytes> op) throws Exception { // public void performBackgroundOperation(OperationAndData<PathAndBytes> op) throws Exception {
try { // try {
client.getZooKeeper().setData(path, mainOperationAndData.getData().getData(), setDataIfExistsVersion, statCallback, backgrounding.getContext()); // client.getZooKeeper().setData(path, mainOperationAndData.getData().getData(), setDataIfExistsVersion, statCallback, backgrounding.getContext());
} catch (KeeperException e) { // } catch (KeeperException e) {
// ignore // // ignore
} // }
} // }
}; // };
client.queueOperation(new OperationAndData<>(operation, null, null, null, null, null)); // client.queueOperation(new OperationAndData<>(operation, null, null, null, null, null));
} // }
//
private void sendBackgroundResponse(int rc, String path, Object ctx, String name, Stat stat, OperationAndData<PathAndBytes> operationAndData) { // private void sendBackgroundResponse(int rc, String path, Object ctx, String name, Stat stat, OperationAndData<PathAndBytes> operationAndData) {
path = client.unfixForNamespace(path); // path = client.unfixForNamespace(path);
name = client.unfixForNamespace(name); // name = client.unfixForNamespace(name);
//
CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.CREATE, rc, path, name, ctx, stat, null, null, null, null, null); // CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.CREATE, rc, path, name, ctx, stat, null, null, null, null, null);
client.processBackgroundOperation(operationAndData, event); // client.processBackgroundOperation(operationAndData, event);
} // }
//
private ACLCreateModePathAndBytesable<String> asACLCreateModePathAndBytesable() { // private ACLCreateModePathAndBytesable<String> asACLCreateModePathAndBytesable() {
return new ACLCreateModePathAndBytesable<String>() { // return new ACLCreateModePathAndBytesable<String>() {
@Override // @Override
public PathAndBytesable<String> withACL(List<ACL> aclList) { // public PathAndBytesable<String> withACL(List<ACL> aclList) {
return CreateBuilderImpl.this.withACL(aclList); // return CreateBuilderImpl.this.withACL(aclList);
} // }
//
@Override // @Override
public PathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public PathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
CreateBuilderImpl.this.withACL(aclList, applyToParents); // CreateBuilderImpl.this.withACL(aclList, applyToParents);
return this; // return this;
} // }
//
@Override // @Override
public ACLPathAndBytesable<String> withMode(CreateMode mode) { // public ACLPathAndBytesable<String> withMode(CreateMode mode) {
createMode = mode; // createMode = mode;
return new ACLPathAndBytesable<String>() { // return new ACLPathAndBytesable<String>() {
@Override // @Override
public PathAndBytesable<String> withACL(List<ACL> aclList) { // public PathAndBytesable<String> withACL(List<ACL> aclList) {
return CreateBuilderImpl.this.withACL(aclList); // return CreateBuilderImpl.this.withACL(aclList);
} // }
//
@Override // @Override
public PathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public PathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
return CreateBuilderImpl.this.withACL(aclList, applyToParents); // return CreateBuilderImpl.this.withACL(aclList, applyToParents);
} // }
//
@Override // @Override
public String forPath(String path, byte[] data) throws Exception { // public String forPath(String path, byte[] data) throws Exception {
return CreateBuilderImpl.this.forPath(path, data); // return CreateBuilderImpl.this.forPath(path, data);
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return CreateBuilderImpl.this.forPath(path); // return CreateBuilderImpl.this.forPath(path);
} // }
}; // };
} // }
//
@Override // @Override
public String forPath(String path, byte[] data) throws Exception { // public String forPath(String path, byte[] data) throws Exception {
return CreateBuilderImpl.this.forPath(path, data); // return CreateBuilderImpl.this.forPath(path, data);
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return CreateBuilderImpl.this.forPath(path); // return CreateBuilderImpl.this.forPath(path);
} // }
}; // };
} // }
//
private CreateBackgroundModeACLable asCreateBackgroundModeACLable() { // private CreateBackgroundModeACLable asCreateBackgroundModeACLable() {
return new CreateBackgroundModeACLable() { // return new CreateBackgroundModeACLable() {
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) {
return CreateBuilderImpl.this.withACL(aclList); // return CreateBuilderImpl.this.withACL(aclList);
} // }
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
return CreateBuilderImpl.this.withACL(aclList, applyToParents); // return CreateBuilderImpl.this.withACL(aclList, applyToParents);
} // }
//
@Override // @Override
public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) { // public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) {
return CreateBuilderImpl.this.withMode(mode); // return CreateBuilderImpl.this.withMode(mode);
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return CreateBuilderImpl.this.forPath(path); // return CreateBuilderImpl.this.forPath(path);
} // }
//
@Override // @Override
public String forPath(String path, byte[] data) throws Exception { // public String forPath(String path, byte[] data) throws Exception {
return CreateBuilderImpl.this.forPath(path, data); // return CreateBuilderImpl.this.forPath(path, data);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, context, executor); // return CreateBuilderImpl.this.inBackground(callback, context, executor);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, executor); // return CreateBuilderImpl.this.inBackground(callback, executor);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) {
return CreateBuilderImpl.this.inBackground(callback, context); // return CreateBuilderImpl.this.inBackground(callback, context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) {
return CreateBuilderImpl.this.inBackground(callback); // return CreateBuilderImpl.this.inBackground(callback);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(Object context) {
return CreateBuilderImpl.this.inBackground(context); // return CreateBuilderImpl.this.inBackground(context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground() { // public ErrorListenerPathAndBytesable<String> inBackground() {
return CreateBuilderImpl.this.inBackground(); // return CreateBuilderImpl.this.inBackground();
} // }
//
@Override // @Override
public ACLPathAndBytesable<String> withProtectedEphemeralSequential() { // public ACLPathAndBytesable<String> withProtectedEphemeralSequential() {
return CreateBuilderImpl.this.withProtectedEphemeralSequential(); // return CreateBuilderImpl.this.withProtectedEphemeralSequential();
} // }
//
@Override // @Override
public ACLCreateModePathAndBytesable<String> creatingParentsIfNeeded() { // public ACLCreateModePathAndBytesable<String> creatingParentsIfNeeded() {
createParentsIfNeeded = true; // createParentsIfNeeded = true;
return asACLCreateModePathAndBytesable(); // return asACLCreateModePathAndBytesable();
} // }
//
@Override // @Override
public ACLCreateModePathAndBytesable<String> creatingParentContainersIfNeeded() { // public ACLCreateModePathAndBytesable<String> creatingParentContainersIfNeeded() {
setCreateParentsAsContainers(); // setCreateParentsAsContainers();
return asACLCreateModePathAndBytesable(); // return asACLCreateModePathAndBytesable();
} // }
}; // };
} // }
//
private ACLCreateModeStatBackgroundPathAndBytesable<String> asACLCreateModeStatBackgroundPathAndBytesable() { // private ACLCreateModeStatBackgroundPathAndBytesable<String> asACLCreateModeStatBackgroundPathAndBytesable() {
return new ACLCreateModeStatBackgroundPathAndBytesable<String>() { // return new ACLCreateModeStatBackgroundPathAndBytesable<String>() {
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList) {
return CreateBuilderImpl.this.withACL(aclList); // return CreateBuilderImpl.this.withACL(aclList);
} // }
//
@Override // @Override
public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) { // public BackgroundPathAndBytesable<String> withACL(List<ACL> aclList, boolean applyToParents) {
CreateBuilderImpl.this.withACL(aclList, applyToParents); // CreateBuilderImpl.this.withACL(aclList, applyToParents);
return this; // return this;
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground() { // public ErrorListenerPathAndBytesable<String> inBackground() {
return CreateBuilderImpl.this.inBackground(); // return CreateBuilderImpl.this.inBackground();
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, context, executor); // return CreateBuilderImpl.this.inBackground(callback, context, executor);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Executor executor) {
return CreateBuilderImpl.this.inBackground(callback, executor); // return CreateBuilderImpl.this.inBackground(callback, executor);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback, Object context) {
return CreateBuilderImpl.this.inBackground(callback, context); // return CreateBuilderImpl.this.inBackground(callback, context);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) { // public ErrorListenerPathAndBytesable<String> inBackground(BackgroundCallback callback) {
return CreateBuilderImpl.this.inBackground(callback); // return CreateBuilderImpl.this.inBackground(callback);
} // }
//
@Override // @Override
public ErrorListenerPathAndBytesable<String> inBackground(Object context) { // public ErrorListenerPathAndBytesable<String> inBackground(Object context) {
return CreateBuilderImpl.this.inBackground(context); // return CreateBuilderImpl.this.inBackground(context);
} // }
//
@Override // @Override
public String forPath(String path) throws Exception { // public String forPath(String path) throws Exception {
return CreateBuilderImpl.this.forPath(path); // return CreateBuilderImpl.this.forPath(path);
} // }
//
@Override // @Override
public String forPath(String path, byte[] data) throws Exception { // public String forPath(String path, byte[] data) throws Exception {
return CreateBuilderImpl.this.forPath(path, data); // return CreateBuilderImpl.this.forPath(path, data);
} // }
//
@Override // @Override
public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) { // public ACLBackgroundPathAndBytesable<String> withMode(CreateMode mode) {
return CreateBuilderImpl.this.withMode(mode); // return CreateBuilderImpl.this.withMode(mode);
} // }
//
@Override // @Override
public ACLCreateModeBackgroundPathAndBytesable<String> storingStatIn(Stat stat) { // public ACLCreateModeBackgroundPathAndBytesable<String> storingStatIn(Stat stat) {
storingStat = stat; // storingStat = stat;
return CreateBuilderImpl.this; // return CreateBuilderImpl.this;
} // }
}; // };
} // }
//
@VisibleForTesting // @VisibleForTesting
volatile boolean debugForceFindProtectedNode = false; // volatile boolean debugForceFindProtectedNode = false;
//
private void pathInBackground(final String path, final byte[] data, final String givenPath) { // private void pathInBackground(final String path, final byte[] data, final String givenPath) {
final AtomicBoolean firstTime = new AtomicBoolean(true); // final AtomicBoolean firstTime = new AtomicBoolean(true);
OperationAndData<PathAndBytes> operationAndData = new OperationAndData<PathAndBytes>(this, new PathAndBytes(path, data), backgrounding.getCallback(), // OperationAndData<PathAndBytes> operationAndData = new OperationAndData<PathAndBytes>(this, new PathAndBytes(path, data), backgrounding.getCallback(),
new OperationAndData.ErrorCallback<PathAndBytes>() { // new OperationAndData.ErrorCallback<PathAndBytes>() {
public void retriesExhausted(OperationAndData<PathAndBytes> operationAndData) { // public void retriesExhausted(OperationAndData<PathAndBytes> operationAndData) {
if (protectedMode.doProtected()) { // if (protectedMode.doProtected()) {
// all retries have failed, findProtectedNodeInForeground(..) included, schedule a clean up // // all retries have failed, findProtectedNodeInForeground(..) included, schedule a clean up
new FindAndDeleteProtectedNodeInBackground(client, ZKPaths.getPathAndNode(path).getPath(), protectedMode.protectedId()).execute(); // new FindAndDeleteProtectedNodeInBackground(client, ZKPaths.getPathAndNode(path).getPath(), protectedMode.protectedId()).execute();
// assign a new id if this builder is used again later // // assign a new id if this builder is used again later
protectedMode.resetProtectedId(); // protectedMode.resetProtectedId();
} // }
} // }
}, // },
backgrounding.getContext(), // backgrounding.getContext(),
null) { // null) {
@Override // @Override
void callPerformBackgroundOperation() throws Exception { // void callPerformBackgroundOperation() throws Exception {
boolean callSuper = true; // boolean callSuper = true;
boolean localFirstTime = firstTime.getAndSet(false) && !debugForceFindProtectedNode; // boolean localFirstTime = firstTime.getAndSet(false) && !debugForceFindProtectedNode;
//
protectedMode.checkSetSessionId(client, createMode); // protectedMode.checkSetSessionId(client, createMode);
if (!localFirstTime && protectedMode.doProtected()) { // if (!localFirstTime && protectedMode.doProtected()) {
debugForceFindProtectedNode = false; // debugForceFindProtectedNode = false;
String createdPath = null; // String createdPath = null;
try { // try {
createdPath = findProtectedNodeInForeground(path); // createdPath = findProtectedNodeInForeground(path);
} catch (KeeperException.ConnectionLossException e) { // } catch (KeeperException.ConnectionLossException e) {
sendBackgroundResponse(KeeperException.Code.CONNECTIONLOSS.intValue(), path, backgrounding.getContext(), null, null, this); // sendBackgroundResponse(KeeperException.Code.CONNECTIONLOSS.intValue(), path, backgrounding.getContext(), null, null, this);
callSuper = false; // callSuper = false;
} // }
if (createdPath != null) { // if (createdPath != null) {
try { // try {
sendBackgroundResponse(KeeperException.Code.OK.intValue(), createdPath, backgrounding.getContext(), createdPath, null, this); // sendBackgroundResponse(KeeperException.Code.OK.intValue(), createdPath, backgrounding.getContext(), createdPath, null, this);
} catch (Exception e) { // } catch (Exception e) {
ThreadUtils.checkInterrupted(e); // ThreadUtils.checkInterrupted(e);
client.logError("Processing protected create for path: " + givenPath, e); // client.logError("Processing protected create for path: " + givenPath, e);
} // }
callSuper = false; // callSuper = false;
} // }
} // }
//
if (failNextCreateForTesting) { // if (failNextCreateForTesting) {
failNextCreateForTesting = false; // failNextCreateForTesting = false;
pathInForeground(path, data, acling.getAclList(path)); // simulate success on server without notification to client // pathInForeground(path, data, acling.getAclList(path)); // simulate success on server without notification to client
throw new KeeperException.ConnectionLossException(); // throw new KeeperException.ConnectionLossException();
} // }
//
if (callSuper) { // if (callSuper) {
super.callPerformBackgroundOperation(); // super.callPerformBackgroundOperation();
} // }
} // }
}; // };
client.processBackgroundOperation(operationAndData, null); // client.processBackgroundOperation(operationAndData, null);
} // }
//
private String pathInForeground(final String path, final byte[] data, final List<ACL> aclList) throws Exception { // private String pathInForeground(final String path, final byte[] data, final List<ACL> aclList) throws Exception {
OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-Foreground"); // OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-Foreground");
//
final AtomicBoolean firstTime = new AtomicBoolean(true); // final AtomicBoolean firstTime = new AtomicBoolean(true);
String returnPath = RetryLoop.callWithRetry // String returnPath = RetryLoop.callWithRetry
( // (
client.getZookeeperClient(), // client.getZookeeperClient(),
new Callable<String>() { // new Callable<String>() {
@Override // @Override
public String call() throws Exception { // public String call() throws Exception {
boolean localFirstTime = firstTime.getAndSet(false) && !debugForceFindProtectedNode; // boolean localFirstTime = firstTime.getAndSet(false) && !debugForceFindProtectedNode;
protectedMode.checkSetSessionId(client, createMode); // protectedMode.checkSetSessionId(client, createMode);
//
String createdPath = null; // String createdPath = null;
if (!localFirstTime && protectedMode.doProtected()) { // if (!localFirstTime && protectedMode.doProtected()) {
debugForceFindProtectedNode = false; // debugForceFindProtectedNode = false;
createdPath = findProtectedNodeInForeground(path); // createdPath = findProtectedNodeInForeground(path);
} // }
//
if (createdPath == null) { // if (createdPath == null) {
try { // try {
// if (client.isZk34CompatibilityMode()) { //// if (client.isZk34CompatibilityMode()) {
// createdPath = client.getZooKeeper().create(path, data, aclList, createMode); //// createdPath = client.getZooKeeper().create(path, data, aclList, createMode);
//// } else {
//// createdPath = client.getZooKeeper().create(path, data, aclList, createMode);
//// }
// createdPath = client.getZooKeeper().create(path, data, acling.getAclList(path), createMode);
// } catch (KeeperException.NoNodeException e) {
// if (createParentsIfNeeded) {
// ZKPaths.mkdirs(client.getZooKeeper(), path, false, acling.getACLProviderForParents(), createParentsAsContainers);
// if (client.isZk34CompatibilityMode()) {
// createdPath = client.getZooKeeper().create(path, data, acling.getAclList(path), createMode);
// } else {
// createdPath = client.getZooKeeper().create(path, data, acling.getAclList(path), createMode);
// }
// } else { // } else {
// createdPath = client.getZooKeeper().create(path, data, aclList, createMode); // throw e;
// } // }
createdPath = client.getZooKeeper().create(path, data, acling.getAclList(path), createMode); // } catch (KeeperException.NodeExistsException e) {
} catch (KeeperException.NoNodeException e) { // if (setDataIfExists) {
if (createParentsIfNeeded) { // Stat setStat = client.getZooKeeper().setData(path, data, setDataIfExistsVersion);
ZKPaths.mkdirs(client.getZooKeeper(), path, false, acling.getACLProviderForParents(), createParentsAsContainers); // if (storingStat != null) {
if (client.isZk34CompatibilityMode()) { // DataTree.copyStat(setStat, storingStat);
createdPath = client.getZooKeeper().create(path, data, acling.getAclList(path), createMode); // }
} else { // createdPath = path;
createdPath = client.getZooKeeper().create(path, data, acling.getAclList(path), createMode); // } else {
} // throw e;
} else { // }
throw e; // }
} // }
} catch (KeeperException.NodeExistsException e) { //
if (setDataIfExists) { // if (failNextCreateForTesting) {
Stat setStat = client.getZooKeeper().setData(path, data, setDataIfExistsVersion); // failNextCreateForTesting = false;
if (storingStat != null) { // throw new KeeperException.ConnectionLossException();
DataTree.copyStat(setStat, storingStat); // }
} // return createdPath;
createdPath = path; // }
} else { // }
throw e; // );
} //
} // trace.setRequestBytesLength(data).setPath(path).commit();
} // return returnPath;
// }
if (failNextCreateForTesting) { //
failNextCreateForTesting = false; // private String findProtectedNodeInForeground(final String path) throws Exception {
throw new KeeperException.ConnectionLossException(); // OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-findProtectedNodeInForeground");
} //
return createdPath; // String returnPath = RetryLoop.callWithRetry
} // (
} // client.getZookeeperClient(),
); // new Callable<String>() {
// @Override
trace.setRequestBytesLength(data).setPath(path).commit(); // public String call() throws Exception {
return returnPath; // String foundNode = null;
} // try {
// final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path);
private String findProtectedNodeInForeground(final String path) throws Exception { // List<String> children = client.getZooKeeper().getChildren(pathAndNode.getPath(), false);
OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-findProtectedNodeInForeground"); //
// foundNode = findNode(children, pathAndNode.getPath(), protectedMode.protectedId());
String returnPath = RetryLoop.callWithRetry // log.debug("Protected mode findNode result: {}", foundNode);
( //
client.getZookeeperClient(), // foundNode = protectedMode.validateFoundNode(client, createMode, foundNode);
new Callable<String>() { // } catch (KeeperException.NoNodeException ignore) {
@Override // // ignore
public String call() throws Exception { // }
String foundNode = null; // return foundNode;
try { // }
final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); // }
List<String> children = client.getZooKeeper().getChildren(pathAndNode.getPath(), false); // );
//
foundNode = findNode(children, pathAndNode.getPath(), protectedMode.protectedId()); // trace.setPath(path).commit();
log.debug("Protected mode findNode result: {}", foundNode); // return returnPath;
// }
foundNode = protectedMode.validateFoundNode(client, createMode, foundNode); //
} catch (KeeperException.NoNodeException ignore) { // @VisibleForTesting
// ignore // String adjustPath(String path) throws Exception {
} // if (protectedMode.doProtected()) {
return foundNode; // ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path);
} // String name = getProtectedPrefix(protectedMode.protectedId()) + pathAndNode.getNode();
} // path = ZKPaths.makePath(pathAndNode.getPath(), name);
); // }
// return path;
trace.setPath(path).commit(); // }
return returnPath; //
} // /**
// * Attempt to find the znode that matches the given path and protected id
@VisibleForTesting // *
String adjustPath(String path) throws Exception { // * @param children a list of candidates znodes
if (protectedMode.doProtected()) { // * @param path the path
ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); // * @param protectedId the protected id
String name = getProtectedPrefix(protectedMode.protectedId()) + pathAndNode.getNode(); // * @return the absolute path of the znode or <code>null</code> if it is not found
path = ZKPaths.makePath(pathAndNode.getPath(), name); // */
} // static String findNode(final List<String> children, final String path, final String protectedId) {
return path; // final String protectedPrefix = getProtectedPrefix(protectedId);
} // String foundNode = Iterables.find
// (
/** // children,
* Attempt to find the znode that matches the given path and protected id // new Predicate<String>() {
* // @Override
* @param children a list of candidates znodes // public boolean apply(String node) {
* @param path the path // return node.startsWith(protectedPrefix);
* @param protectedId the protected id // }
* @return the absolute path of the znode or <code>null</code> if it is not found // },
*/ // null
static String findNode(final List<String> children, final String path, final String protectedId) { // );
final String protectedPrefix = getProtectedPrefix(protectedId); // if (foundNode != null) {
String foundNode = Iterables.find // foundNode = ZKPaths.makePath(path, foundNode);
( // }
children, // return foundNode;
new Predicate<String>() { // }
@Override //}
public boolean apply(String node) {
return node.startsWith(protectedPrefix);
}
},
null
);
if (foundNode != null) {
foundNode = ZKPaths.makePath(path, foundNode);
}
return foundNode;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!