├── gradle ├── netflix-oss.gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── license.gradle ├── buildscript.gradle └── check.gradle ├── settings.gradle ├── NOTICE.txt ├── curator-x-discovery └── src │ ├── main │ └── java │ │ └── com │ │ └── netflix │ │ └── curator │ │ └── x │ │ └── discovery │ │ ├── LocalIpFilter.java │ │ ├── ServiceType.java │ │ ├── details │ │ ├── ServiceCacheListener.java │ │ ├── Latch.java │ │ ├── InstanceProvider.java │ │ └── InstanceSerializer.java │ │ ├── ProviderStrategy.java │ │ ├── ServiceCacheBuilder.java │ │ ├── ServiceProvider.java │ │ ├── ServiceCache.java │ │ └── strategies │ │ ├── RandomStrategy.java │ │ └── RoundRobinStrategy.java │ └── test │ ├── resources │ └── log4j.properties │ └── java │ └── com │ └── netflix │ └── curator │ └── x │ └── discovery │ └── TestLocalIpFilter.java ├── curator-examples └── src │ └── main │ └── java │ ├── README.txt │ ├── discovery │ └── InstanceDetails.java │ └── locking │ ├── FakeLimitedResource.java │ └── ExampleClientThatLocks.java ├── codequality └── HEADER ├── gradle.properties ├── curator-recipes └── src │ ├── main │ └── java │ │ └── com │ │ └── netflix │ │ └── curator │ │ └── framework │ │ └── recipes │ │ ├── cache │ │ ├── Operation.java │ │ ├── NodeCacheListener.java │ │ ├── PathChildrenCacheListener.java │ │ ├── EventOperation.java │ │ ├── PathChildrenCacheMode.java │ │ ├── RefreshOperation.java │ │ └── GetDataOperation.java │ │ ├── atomic │ │ ├── MakeValue.java │ │ ├── AtomicValue.java │ │ └── MutableAtomicValue.java │ │ ├── locks │ │ ├── LockInternalsSorter.java │ │ ├── LockInternalsDriver.java │ │ ├── RevocationListener.java │ │ ├── PredicateResults.java │ │ ├── RevocationSpec.java │ │ ├── Revocable.java │ │ ├── Lease.java │ │ └── Revoker.java │ │ ├── queue │ │ ├── QueueAllocator.java │ │ ├── QueueConsumer.java │ │ ├── ErrorMode.java │ │ ├── MultiItem.java │ │ ├── QueueSerializer.java │ │ ├── QueuePutListener.java │ │ └── QueueSafety.java │ │ ├── shared │ │ ├── SharedCountReader.java │ │ ├── SharedValueReader.java │ │ ├── SharedValueListener.java │ │ └── SharedCountListener.java │ │ └── leader │ │ └── LeaderSelectorListener.java │ └── test │ ├── java │ └── com │ │ └── netflix │ │ └── curator │ │ └── framework │ │ └── recipes │ │ ├── locks │ │ ├── Counter.java │ │ ├── Stepper.java │ │ └── TestInterProcessSemaphoreMutex.java │ │ ├── queue │ │ ├── QueueItemSerializer.java │ │ ├── QueueTestProducer.java │ │ └── TestQueueItem.java │ │ └── BaseClassForTests.java │ └── resources │ └── log4j.properties ├── curator-framework └── src │ ├── main │ └── java │ │ └── com │ │ └── netflix │ │ └── curator │ │ └── framework │ │ ├── api │ │ ├── StatPathable.java │ │ ├── WatchPathable.java │ │ ├── BackgroundPathable.java │ │ ├── ACLPathAndBytesable.java │ │ ├── ACLBackgroundPathable.java │ │ ├── DeleteBuilderBase.java │ │ ├── BackgroundPathAndBytesable.java │ │ ├── CreateModalPathAndBytesable.java │ │ ├── ACLCreateModePathAndBytesable.java │ │ ├── TempGetDataBuilder.java │ │ ├── ACLBackgroundPathAndBytesable.java │ │ ├── ACLVersionBackgroundPathable.java │ │ ├── ExistsBuilder.java │ │ ├── SetACLBuilder.java │ │ ├── Compressible.java │ │ ├── GetACLBuilder.java │ │ ├── GetDataWatchBackgroundStatable.java │ │ ├── CompressionProvider.java │ │ ├── Decompressible.java │ │ ├── SetDataBackgroundVersionable.java │ │ ├── GetDataBuilder.java │ │ ├── GetChildrenBuilder.java │ │ ├── ACLCreateModeBackgroundPathAndBytesable.java │ │ ├── Versionable.java │ │ ├── SetDataBuilder.java │ │ ├── transaction │ │ │ ├── CuratorTransactionBridge.java │ │ │ ├── TransactionCheckBuilder.java │ │ │ ├── TransactionDeleteBuilder.java │ │ │ ├── TransactionSetDataBuilder.java │ │ │ ├── TransactionCreateBuilder.java │ │ │ ├── OperationType.java │ │ │ └── CuratorTransactionFinal.java │ │ ├── Statable.java │ │ ├── CreateModable.java │ │ ├── Pathable.java │ │ ├── ACLable.java │ │ ├── BackgroundCallback.java │ │ ├── CuratorWatcher.java │ │ ├── CuratorListener.java │ │ ├── ACLProvider.java │ │ ├── Watchable.java │ │ ├── UnhandledErrorListener.java │ │ ├── PathAndBytesable.java │ │ ├── DeleteBuilder.java │ │ └── CuratorEventType.java │ │ ├── imps │ │ ├── BackgroundOperation.java │ │ ├── NamespaceWatchedEvent.java │ │ ├── PathAndBytes.java │ │ ├── CuratorFrameworkState.java │ │ ├── DefaultACLProvider.java │ │ ├── FailedDeleteManager.java │ │ ├── Watching.java │ │ ├── CuratorMultiTransactionRecord.java │ │ └── ACLing.java │ │ ├── state │ │ └── ConnectionStateListener.java │ │ └── listen │ │ ├── ListenerEntry.java │ │ └── Listenable.java │ └── test │ ├── resources │ └── log4j.properties │ └── java │ └── com │ └── netflix │ └── curator │ └── framework │ └── imps │ └── BaseClassForTests.java ├── curator-x-zkclient-bridge └── src │ └── test │ └── java │ └── org │ └── I0Itec │ └── zkclient │ ├── InMemoryConnectionTest.java │ ├── DeferredGatewayStarter.java │ ├── ZkConnectionTest.java │ └── MemoryZkClientTest.java ├── curator-client └── src │ ├── main │ └── java │ │ └── com │ │ └── netflix │ │ └── curator │ │ ├── retry │ │ ├── RetryOneTime.java │ │ ├── RetryNTimes.java │ │ ├── RetryUntilElapsed.java │ │ ├── SleepingRetry.java │ │ └── BoundedExponentialBackoffRetry.java │ │ ├── utils │ │ ├── DebugUtils.java │ │ ├── DefaultZookeeperFactory.java │ │ ├── DefaultTracerDriver.java │ │ └── ZookeeperFactory.java │ │ ├── RetrySleeper.java │ │ ├── ensemble │ │ ├── exhibitor │ │ │ └── ExhibitorRestClient.java │ │ ├── fixed │ │ │ └── FixedEnsembleProvider.java │ │ └── EnsembleProvider.java │ │ ├── RetryPolicy.java │ │ ├── drivers │ │ └── TracerDriver.java │ │ └── TimeTrace.java │ └── test │ ├── resources │ └── log4j.properties │ └── java │ └── com │ └── netflix │ └── curator │ └── BaseClassForTests.java ├── curator-x-discovery-server └── src │ ├── test │ ├── resources │ │ └── log4j.properties │ └── java │ │ └── com │ │ └── netflix │ │ └── curator │ │ └── x │ │ └── discovery │ │ └── server │ │ ├── jetty_jersey │ │ ├── StringDiscoveryResource.java │ │ ├── MapDiscoveryResource.java │ │ ├── ServiceDetailsDiscoveryResource.java │ │ └── ServiceDetailsDiscoveryContext.java │ │ └── jetty_resteasy │ │ ├── StringDiscoveryResource.java │ │ └── RestEasyApplication.java │ └── main │ └── java │ └── com │ └── netflix │ └── curator │ └── x │ └── discovery │ └── server │ ├── entity │ ├── ServiceNames.java │ └── ServiceInstances.java │ └── contexts │ └── MapDiscoveryContext.java ├── .gitignore ├── curator-test └── src │ └── main │ └── java │ └── com │ └── netflix │ └── curator │ └── test │ ├── ZooKeeperMainFace.java │ └── DirectoryUtils.java └── README.rdoc /gradle/netflix-oss.gradle: -------------------------------------------------------------------------------- 1 | apply from: 'http://artifacts.netflix.com/gradle-netflix-local/artifactory.gradle' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/box/curator/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name='curator' 2 | include 'curator-client','curator-framework','curator-recipes','curator-test','curator-x-discovery','curator-x-discovery-server','curator-x-zkclient-bridge','curator-examples' 3 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Curator 2 | Copyright 2011 Netflix, Inc. 3 | 4 | This product includes software developed by The Apache Software 5 | Foundation (http://www.apache.org/). 6 | 7 | Alternative collection types provided by Google Guava from 8 | http://code.google.com/p/guava-libraries/ 9 | Copyright (C) 2007 Google Inc. 10 | -------------------------------------------------------------------------------- /gradle/license.gradle: -------------------------------------------------------------------------------- 1 | // Dependency for plugin was set in buildscript.gradle 2 | 3 | subprojects { 4 | apply plugin: 'license' //nl.javadude.gradle.plugins.license.LicensePlugin 5 | license { 6 | header rootProject.file('codequality/HEADER') 7 | ext.year = Calendar.getInstance().get(Calendar.YEAR) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/LocalIpFilter.java: -------------------------------------------------------------------------------- 1 | package com.netflix.curator.x.discovery; 2 | 3 | import java.net.InetAddress; 4 | import java.net.NetworkInterface; 5 | import java.net.SocketException; 6 | 7 | public interface LocalIpFilter 8 | { 9 | public boolean use(NetworkInterface networkInterface, InetAddress address) throws SocketException; 10 | } 11 | -------------------------------------------------------------------------------- /curator-examples/src/main/java/README.txt: -------------------------------------------------------------------------------- 1 | This project contains example usages of various Curator features. Each directory is a separate example. 2 | 3 | /leader Example leader selector code 4 | /cache Example PathChildrenCache usage 5 | /locking Example of using InterProcessMutex 6 | /discovery Example usage of the Curator's ServiceDiscovery 7 | /framework A few examples of how to use the CuratorFramework class 8 | -------------------------------------------------------------------------------- /gradle/buildscript.gradle: -------------------------------------------------------------------------------- 1 | // Executed in context of buildscript 2 | repositories { 3 | // Repo in addition to maven central 4 | maven { 5 | name 'build-repo' 6 | url 'https://raw.github.com/Netflix-Skunkworks/build-repo/master/releases/' // gradle-release/gradle-release/1.0-SNAPSHOT/gradle-release-1.0-SNAPSHOT.jar 7 | } 8 | } 9 | dependencies { 10 | classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.6.0' 11 | classpath 'com.mapvine:gradle-cobertura-plugin:0.1' 12 | classpath 'gradle-release:gradle-release:1.0-SNAPSHOT' 13 | } 14 | -------------------------------------------------------------------------------- /codequality/HEADER: -------------------------------------------------------------------------------- 1 | Copyright ${year} Netflix, Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2013 Netflix, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | version=1.3.5-SNAPSHOT 18 | -------------------------------------------------------------------------------- /gradle/check.gradle: -------------------------------------------------------------------------------- 1 | subprojects { 2 | // Checkstyle 3 | apply plugin: 'checkstyle' 4 | tasks.withType(Checkstyle) { ignoreFailures = true } 5 | checkstyle { 6 | ignoreFailures = true // Waiting on GRADLE-2163 7 | configFile = rootProject.file('codequality/checkstyle.xml') 8 | } 9 | 10 | // FindBugs 11 | apply plugin: 'findbugs' 12 | //tasks.withType(Findbugs) { reports.html.enabled true } 13 | 14 | // PMD 15 | apply plugin: 'pmd' 16 | //tasks.withType(Pmd) { reports.html.enabled true } 17 | 18 | apply plugin: 'cobertura' 19 | cobertura { 20 | sourceDirs = sourceSets.main.java.srcDirs 21 | format = 'html' 22 | includes = ['**/*.java', '**/*.groovy'] 23 | excludes = [] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/cache/Operation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.cache; 18 | 19 | interface Operation 20 | { 21 | public void invoke() throws Exception; 22 | } 23 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/atomic/MakeValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.atomic; 18 | 19 | interface MakeValue 20 | { 21 | public byte[] makeFrom(byte[] previous); 22 | } 23 | -------------------------------------------------------------------------------- /curator-recipes/src/test/java/com/netflix/curator/framework/recipes/locks/Counter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | class Counter 20 | { 21 | int currentCount = 0; 22 | int maxCount = 0; 23 | } 24 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/ServiceType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery; 20 | 21 | public enum ServiceType 22 | { 23 | DYNAMIC, 24 | STATIC, 25 | PERMANENT 26 | } 27 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/StatPathable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface StatPathable extends 21 | Pathable, 22 | Statable> 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/WatchPathable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface WatchPathable extends 21 | Watchable>, 22 | Pathable 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2013 Netflix, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | #Tue Aug 14 16:28:54 PDT 2012 18 | distributionBase=GRADLE_USER_HOME 19 | distributionPath=wrapper/dists 20 | zipStoreBase=GRADLE_USER_HOME 21 | zipStorePath=wrapper/dists 22 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.1-bin.zip 23 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/BackgroundPathable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface BackgroundPathable extends 21 | Backgroundable>, 22 | Pathable 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/locks/LockInternalsSorter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | public interface LockInternalsSorter 20 | { 21 | public String fixForSorting(String str, String lockName); 22 | } 23 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/ACLPathAndBytesable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface ACLPathAndBytesable extends 21 | ACLable>, 22 | PathAndBytesable 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/ACLBackgroundPathable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface ACLBackgroundPathable extends 21 | ACLable>, 22 | BackgroundPathable 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/DeleteBuilderBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface DeleteBuilderBase extends 21 | BackgroundPathable, 22 | Versionable> 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/imps/BackgroundOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.imps; 19 | 20 | interface BackgroundOperation 21 | { 22 | public void performBackgroundOperation(OperationAndData data) throws Exception; 23 | } 24 | -------------------------------------------------------------------------------- /curator-x-zkclient-bridge/src/test/java/org/I0Itec/zkclient/InMemoryConnectionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.I0Itec.zkclient; 17 | 18 | 19 | public class InMemoryConnectionTest extends AbstractConnectionTest { 20 | 21 | public InMemoryConnectionTest() { 22 | super(new InMemoryConnection()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/BackgroundPathAndBytesable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface BackgroundPathAndBytesable extends 21 | Backgroundable>, 22 | PathAndBytesable 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/CreateModalPathAndBytesable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface CreateModalPathAndBytesable extends 21 | CreateModable>, 22 | PathAndBytesable 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/ACLCreateModePathAndBytesable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface ACLCreateModePathAndBytesable extends 21 | ACLPathAndBytesable, 22 | CreateModable> 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/TempGetDataBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface TempGetDataBuilder extends 21 | StatPathable, 22 | Decompressible>, 23 | Pathable 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/cache/NodeCacheListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.netflix.curator.framework.recipes.cache; 17 | 18 | public interface NodeCacheListener 19 | { 20 | /** 21 | * Called when a change has occurred 22 | */ 23 | public void nodeChanged() throws Exception; 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/ACLBackgroundPathAndBytesable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface ACLBackgroundPathAndBytesable extends 21 | ACLable>, 22 | BackgroundPathAndBytesable 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/ACLVersionBackgroundPathable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface ACLVersionBackgroundPathable extends 21 | ACLable>>, 22 | Versionable> 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/ExistsBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import org.apache.zookeeper.data.Stat; 21 | 22 | public interface ExistsBuilder extends 23 | Watchable>, 24 | BackgroundPathable 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/SetACLBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import org.apache.zookeeper.data.Stat; 21 | 22 | public interface SetACLBuilder extends 23 | ACLable>, 24 | Versionable>> 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/Compressible.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.api; 18 | 19 | public interface Compressible 20 | { 21 | /** 22 | * Cause the data to be compressed using the configured compression provider 23 | * 24 | * @return this 25 | */ 26 | public T compressed(); 27 | } 28 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/GetACLBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import org.apache.zookeeper.data.ACL; 21 | import java.util.List; 22 | 23 | public interface GetACLBuilder extends 24 | BackgroundPathable>, 25 | Statable>> 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/GetDataWatchBackgroundStatable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface GetDataWatchBackgroundStatable extends 21 | Watchable>, 22 | BackgroundPathable, 23 | Statable> 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/CompressionProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.api; 18 | 19 | public interface CompressionProvider 20 | { 21 | public byte[] compress(String path, byte[] data) throws Exception; 22 | 23 | public byte[] decompress(String path, byte[] compressedData) throws Exception; 24 | } 25 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/queue/QueueAllocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.queue; 18 | 19 | import com.netflix.curator.framework.CuratorFramework; 20 | 21 | public interface QueueAllocator> 22 | { 23 | public T allocateQueue(CuratorFramework client, String queuePath); 24 | } 25 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/retry/RetryOneTime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.retry; 19 | 20 | /** 21 | * A retry policy that retries only once 22 | */ 23 | public class RetryOneTime extends RetryNTimes 24 | { 25 | public RetryOneTime(int sleepMsBetweenRetry) 26 | { 27 | super(1, sleepMsBetweenRetry); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /curator-client/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2013 Netflix, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=ERROR, console 18 | 19 | log4j.logger.com.netflix.curator=DEBUG, console 20 | log4j.additivity.com.netflix.curator=false 21 | 22 | log4j.appender.console=org.apache.log4j.ConsoleAppender 23 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 24 | log4j.appender.console.layout.ConversionPattern=%-5p %c %x %m [%t]%n 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/Decompressible.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.api; 18 | 19 | public interface Decompressible 20 | { 21 | /** 22 | * Cause the data to be de-compressed using the configured compression provider 23 | * 24 | * @return this 25 | */ 26 | public T decompressed(); 27 | } 28 | -------------------------------------------------------------------------------- /curator-recipes/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2012 Netflix, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=ERROR, console 18 | 19 | log4j.logger.com.netflix.curator=DEBUG, console 20 | log4j.additivity.com.netflix.curator=false 21 | 22 | log4j.appender.console=org.apache.log4j.ConsoleAppender 23 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 24 | log4j.appender.console.layout.ConversionPattern=%-5p %c %x %m [%t]%n 25 | -------------------------------------------------------------------------------- /curator-framework/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2013 Netflix, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=ERROR, console 18 | 19 | log4j.logger.com.netflix.curator=DEBUG, console 20 | log4j.additivity.com.netflix.curator=false 21 | 22 | log4j.appender.console=org.apache.log4j.ConsoleAppender 23 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 24 | log4j.appender.console.layout.ConversionPattern=%-5p %c %x %m [%t]%n 25 | -------------------------------------------------------------------------------- /curator-x-discovery/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2013 Netflix, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=ERROR, console 18 | 19 | log4j.logger.com.netflix.curator=DEBUG, console 20 | log4j.additivity.com.netflix.curator=false 21 | 22 | log4j.appender.console=org.apache.log4j.ConsoleAppender 23 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 24 | log4j.appender.console.layout.ConversionPattern=%-5p %c %x %m [%t]%n 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/SetDataBackgroundVersionable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import org.apache.zookeeper.data.Stat; 21 | 22 | public interface SetDataBackgroundVersionable extends 23 | BackgroundPathAndBytesable, 24 | Versionable> 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2013 Netflix, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=ERROR, console 18 | 19 | log4j.logger.com.netflix.curator=DEBUG, console 20 | log4j.additivity.com.netflix.curator=false 21 | 22 | log4j.appender.console=org.apache.log4j.ConsoleAppender 23 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 24 | log4j.appender.console.layout.ConversionPattern=%-5p %c %x %m [%t]%n 25 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/GetDataBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface GetDataBuilder extends 21 | Watchable>, 22 | BackgroundPathable, 23 | Statable>, 24 | Decompressible 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.com 4 | *.class 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | 10 | # Packages # 11 | ############ 12 | # it's better to unpack these files and commit the raw source 13 | # git has its own built in compression methods 14 | *.7z 15 | *.dmg 16 | *.gz 17 | *.iso 18 | *.jar 19 | *.rar 20 | *.tar 21 | *.zip 22 | 23 | # Logs and databases # 24 | ###################### 25 | *.log 26 | 27 | # OS generated files # 28 | ###################### 29 | .DS_Store* 30 | ehthumbs.db 31 | Icon? 32 | Thumbs.db 33 | 34 | # Editor Files # 35 | ################ 36 | *~ 37 | *.swp 38 | 39 | # Gradle Files # 40 | ################ 41 | .gradle 42 | 43 | # Build output directies 44 | /target 45 | */target 46 | /build 47 | */build 48 | */bin 49 | 50 | # IntelliJ specific files/directories 51 | out 52 | .idea 53 | *.ipr 54 | *.iws 55 | *.iml 56 | atlassian-ide-plugin.xml 57 | 58 | # Eclipse specific files/directories 59 | .classpath 60 | .project 61 | .settings 62 | .metadata 63 | 64 | # NetBeans specific files/directories 65 | .nbattrs 66 | 67 | 68 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/GetChildrenBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import java.util.List; 21 | 22 | public interface GetChildrenBuilder extends 23 | Watchable>>, 24 | BackgroundPathable>, 25 | Statable>> 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/ACLCreateModeBackgroundPathAndBytesable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface ACLCreateModeBackgroundPathAndBytesable extends 21 | ACLBackgroundPathAndBytesable, 22 | BackgroundPathAndBytesable, 23 | CreateModable> 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/Versionable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface Versionable 21 | { 22 | /** 23 | * Use the given version (the default is -1) 24 | * 25 | * @param version version to use 26 | * @return this 27 | */ 28 | public T withVersion(int version); 29 | } 30 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/SetDataBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import org.apache.zookeeper.data.Stat; 21 | 22 | public interface SetDataBuilder extends 23 | BackgroundPathAndBytesable, 24 | Versionable>, 25 | Compressible 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/utils/DebugUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.utils; 18 | 19 | public class DebugUtils 20 | { 21 | public static final String PROPERTY_LOG_EVENTS = "curator-log-events"; 22 | public static final String PROPERTY_DONT_LOG_CONNECTION_ISSUES = "curator-dont-log-connection-problems"; 23 | 24 | private DebugUtils() 25 | { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/transaction/CuratorTransactionBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.api.transaction; 20 | 21 | public interface CuratorTransactionBridge 22 | { 23 | /** 24 | * Syntactic sugar to make the fluent interface more readable 25 | * 26 | * @return transaction continuation 27 | */ 28 | public CuratorTransactionFinal and(); 29 | } 30 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/Statable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import org.apache.zookeeper.data.Stat; 21 | 22 | public interface Statable 23 | { 24 | /** 25 | * Have the operation fill the provided stat object 26 | * 27 | * @param stat the stat to have filled in 28 | * @return this 29 | */ 30 | public T storingStatIn(Stat stat); 31 | } 32 | -------------------------------------------------------------------------------- /curator-test/src/main/java/com/netflix/curator/test/ZooKeeperMainFace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.test; 18 | 19 | import org.apache.zookeeper.server.quorum.QuorumPeerConfig; 20 | import java.io.Closeable; 21 | 22 | public interface ZooKeeperMainFace extends Closeable 23 | { 24 | public void runFromConfig(QuorumPeerConfig config) throws Exception; 25 | 26 | public void blockUntilStarted() throws Exception; 27 | 28 | public void kill(); 29 | } 30 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/CreateModable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import org.apache.zookeeper.CreateMode; 21 | 22 | public interface CreateModable 23 | { 24 | /** 25 | * Set a create mode - the default is {@link CreateMode#PERSISTENT} 26 | * 27 | * @param mode new create mode 28 | * @return this 29 | */ 30 | public T withMode(CreateMode mode); 31 | } 32 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/transaction/TransactionCheckBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api.transaction; 19 | 20 | import com.netflix.curator.framework.api.Pathable; 21 | import com.netflix.curator.framework.api.Versionable; 22 | 23 | public interface TransactionCheckBuilder extends 24 | Pathable, 25 | Versionable> 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/transaction/TransactionDeleteBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api.transaction; 19 | 20 | import com.netflix.curator.framework.api.Pathable; 21 | import com.netflix.curator.framework.api.Versionable; 22 | 23 | public interface TransactionDeleteBuilder extends 24 | Pathable, 25 | Versionable> 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/locks/LockInternalsDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | import com.netflix.curator.framework.CuratorFramework; 20 | import java.util.List; 21 | 22 | interface LockInternalsDriver extends LockInternalsSorter 23 | { 24 | public PredicateResults getsTheLock(CuratorFramework client, List children, String sequenceNodeName, int maxLeases) throws Exception; 25 | } 26 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/Pathable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | public interface Pathable 21 | { 22 | /** 23 | * Commit the currently building operation using the given path 24 | * 25 | * @param path the path 26 | * @return operation result if any 27 | * @throws Exception errors 28 | */ 29 | public T forPath(String path) throws Exception; 30 | } 31 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/transaction/TransactionSetDataBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api.transaction; 19 | 20 | import com.netflix.curator.framework.api.PathAndBytesable; 21 | import com.netflix.curator.framework.api.Versionable; 22 | 23 | public interface TransactionSetDataBuilder extends 24 | PathAndBytesable, 25 | Versionable> 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/locks/RevocationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | public interface RevocationListener 20 | { 21 | /** 22 | * Called when a revocation request has been received. You should release the lock as soon 23 | * as possible. Revocation is cooperative. 24 | * 25 | * @param forLock the lock that should release 26 | */ 27 | public void revocationRequested(T forLock); 28 | } 29 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/imps/NamespaceWatchedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.imps; 20 | 21 | import org.apache.zookeeper.WatchedEvent; 22 | import org.apache.zookeeper.Watcher; 23 | 24 | class NamespaceWatchedEvent extends WatchedEvent 25 | { 26 | NamespaceWatchedEvent(CuratorFrameworkImpl client, WatchedEvent event) 27 | { 28 | super(event.getType(), event.getState(), client.unfixForNamespace(event.getPath())); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /curator-recipes/src/test/java/com/netflix/curator/framework/recipes/queue/QueueItemSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.netflix.curator.framework.recipes.queue; 17 | 18 | class QueueItemSerializer implements QueueSerializer 19 | { 20 | @Override 21 | public byte[] serialize(TestQueueItem item) 22 | { 23 | return item.str.getBytes(); 24 | } 25 | 26 | @Override 27 | public TestQueueItem deserialize(byte[] bytes) 28 | { 29 | return new TestQueueItem(new String(bytes)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/ACLable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import org.apache.zookeeper.ZooDefs; 21 | import org.apache.zookeeper.data.ACL; 22 | import java.util.List; 23 | 24 | public interface ACLable 25 | { 26 | /** 27 | * Set an ACL list (default is {@link ZooDefs.Ids#OPEN_ACL_UNSAFE}) 28 | * 29 | * @param aclList the ACL list to use 30 | * @return this 31 | */ 32 | public T withACL(List aclList); 33 | } 34 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/details/ServiceCacheListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.x.discovery.details; 19 | 20 | import com.netflix.curator.framework.state.ConnectionStateListener; 21 | 22 | /** 23 | * Listener for changes to a service cache 24 | */ 25 | public interface ServiceCacheListener extends ConnectionStateListener 26 | { 27 | /** 28 | * Called when the cache has changed (instances added/deleted, etc.) 29 | */ 30 | public void cacheChanged(); 31 | } 32 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/RetrySleeper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator; 18 | 19 | import java.util.concurrent.TimeUnit; 20 | 21 | /** 22 | * Abstraction for retry policies to sleep 23 | */ 24 | public interface RetrySleeper 25 | { 26 | /** 27 | * Sleep for the given time 28 | * 29 | * @param time time 30 | * @param unit time unit 31 | * @throws InterruptedException if the sleep is interrupted 32 | */ 33 | public void sleepFor(long time, TimeUnit unit) throws InterruptedException; 34 | } 35 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/shared/SharedCountReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.shared; 18 | 19 | import com.netflix.curator.framework.listen.Listenable; 20 | 21 | /** 22 | * Abstracts a shared integer and allows listening for changes to its value 23 | */ 24 | public interface SharedCountReader extends Listenable 25 | { 26 | /** 27 | * Return the current value of the count 28 | * 29 | * @return count 30 | */ 31 | int getCount(); 32 | } 33 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/utils/DefaultZookeeperFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.utils; 18 | 19 | import org.apache.zookeeper.Watcher; 20 | import org.apache.zookeeper.ZooKeeper; 21 | 22 | public class DefaultZookeeperFactory implements ZookeeperFactory 23 | { 24 | @Override 25 | public ZooKeeper newZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws Exception 26 | { 27 | return new ZooKeeper(connectString, sessionTimeout, watcher, canBeReadOnly); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/imps/PathAndBytes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.imps; 19 | 20 | class PathAndBytes 21 | { 22 | private final String path; 23 | private final byte[] data; 24 | 25 | PathAndBytes(String path, byte[] data) 26 | { 27 | this.path = path; 28 | this.data = data; 29 | } 30 | 31 | String getPath() 32 | { 33 | return path; 34 | } 35 | 36 | byte[] getData() 37 | { 38 | return data; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/state/ConnectionStateListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.state; 20 | 21 | import com.netflix.curator.framework.CuratorFramework; 22 | 23 | public interface ConnectionStateListener 24 | { 25 | /** 26 | * Called when there is a state change in the connection 27 | * 28 | * @param client the client 29 | * @param newState the new state 30 | */ 31 | public void stateChanged(CuratorFramework client, ConnectionState newState); 32 | } 33 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/details/Latch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.details; 20 | 21 | class Latch 22 | { 23 | private volatile boolean laden = false; 24 | 25 | synchronized void set() 26 | { 27 | laden = true; 28 | notifyAll(); 29 | } 30 | 31 | synchronized void await() throws InterruptedException 32 | { 33 | while ( !laden ) 34 | { 35 | wait(); 36 | } 37 | laden = false; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/queue/QueueConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.queue; 18 | 19 | import com.netflix.curator.framework.state.ConnectionStateListener; 20 | 21 | /** 22 | * Message Consumer 23 | */ 24 | public interface QueueConsumer extends ConnectionStateListener 25 | { 26 | /** 27 | * Process a message from the queue 28 | * 29 | * @param message message to process 30 | * @throws Exception any errors 31 | */ 32 | public void consumeMessage(T message) throws Exception; 33 | } 34 | -------------------------------------------------------------------------------- /curator-recipes/src/test/java/com/netflix/curator/framework/recipes/locks/Stepper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | class Stepper 20 | { 21 | private int available = 0; 22 | 23 | synchronized void await() throws InterruptedException 24 | { 25 | while ( available == 0 ) 26 | { 27 | wait(); 28 | } 29 | --available; 30 | notifyAll(); 31 | } 32 | 33 | synchronized void countDown(int qty) 34 | { 35 | available += qty; 36 | notifyAll(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/listen/ListenerEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.listen; 19 | 20 | import java.util.concurrent.Executor; 21 | 22 | /** 23 | * Generic holder POJO for a listener and its executor 24 | * @param the listener type 25 | */ 26 | public class ListenerEntry 27 | { 28 | public final T listener; 29 | public final Executor executor; 30 | 31 | public ListenerEntry(T listener, Executor executor) 32 | { 33 | this.listener = listener; 34 | this.executor = executor; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/queue/ErrorMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.queue; 18 | 19 | /** 20 | * Used when the queue is created with a {@link QueueBuilder#lockPath(String)}. Determines 21 | * the behavior when the queue consumer throws an exception 22 | */ 23 | public enum ErrorMode 24 | { 25 | /** 26 | * If the consumer throws an exception, requeue the message. This is the default. 27 | */ 28 | REQUEUE, 29 | 30 | /** 31 | * If the consumer throws an exception, delete the message 32 | */ 33 | DELETE 34 | } 35 | -------------------------------------------------------------------------------- /curator-x-zkclient-bridge/src/test/java/org/I0Itec/zkclient/DeferredGatewayStarter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.I0Itec.zkclient; 17 | 18 | public class DeferredGatewayStarter extends Thread { 19 | 20 | private final Gateway _zkServer; 21 | private int _delay; 22 | 23 | public DeferredGatewayStarter(Gateway gateway, int delay) { 24 | _zkServer = gateway; 25 | _delay = delay; 26 | } 27 | 28 | @Override 29 | public void run() { 30 | try { 31 | Thread.sleep(_delay); 32 | _zkServer.start(); 33 | } catch (Exception e) { 34 | // ignore 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/transaction/TransactionCreateBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api.transaction; 19 | 20 | import com.netflix.curator.framework.api.ACLPathAndBytesable; 21 | import com.netflix.curator.framework.api.CreateModable; 22 | import com.netflix.curator.framework.api.PathAndBytesable; 23 | 24 | public interface TransactionCreateBuilder extends 25 | PathAndBytesable, 26 | CreateModable>, 27 | ACLPathAndBytesable 28 | { 29 | } 30 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/imps/CuratorFrameworkState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.imps; 18 | 19 | import com.netflix.curator.framework.CuratorFramework; 20 | 21 | /** 22 | * @see CuratorFramework#getState() 23 | */ 24 | public enum CuratorFrameworkState 25 | { 26 | /** 27 | * {@link CuratorFramework#start()} has not yet been called 28 | */ 29 | LATENT, 30 | 31 | /** 32 | * {@link CuratorFramework#start()} has been called 33 | */ 34 | STARTED, 35 | 36 | /** 37 | * {@link CuratorFramework#close()} has been called 38 | */ 39 | STOPPED 40 | } 41 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/locks/PredicateResults.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | class PredicateResults 20 | { 21 | private final boolean getsTheLock; 22 | private final String pathToWatch; 23 | 24 | PredicateResults(String pathToWatch, boolean getsTheLock) 25 | { 26 | this.pathToWatch = pathToWatch; 27 | this.getsTheLock = getsTheLock; 28 | } 29 | 30 | String getPathToWatch() 31 | { 32 | return pathToWatch; 33 | } 34 | 35 | boolean getsTheLock() 36 | { 37 | return getsTheLock; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/retry/RetryNTimes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.retry; 19 | 20 | /** 21 | * Retry policy that retries a max number of times 22 | */ 23 | public class RetryNTimes extends SleepingRetry 24 | { 25 | private final int sleepMsBetweenRetries; 26 | 27 | public RetryNTimes(int n, int sleepMsBetweenRetries) 28 | { 29 | super(n); 30 | this.sleepMsBetweenRetries = sleepMsBetweenRetries; 31 | } 32 | 33 | @Override 34 | protected int getSleepTimeMs(int retryCount, long elapsedTimeMs) 35 | { 36 | return sleepMsBetweenRetries; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/transaction/OperationType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.api.transaction; 20 | 21 | /** 22 | * Transaction operation types 23 | */ 24 | public enum OperationType 25 | { 26 | /** 27 | * {@link CuratorTransaction#create()} 28 | */ 29 | CREATE, 30 | 31 | /** 32 | * {@link CuratorTransaction#delete()} 33 | */ 34 | DELETE, 35 | 36 | /** 37 | * {@link CuratorTransaction#setData()} 38 | */ 39 | SET_DATA, 40 | 41 | /** 42 | * {@link CuratorTransaction#check()} 43 | */ 44 | CHECK 45 | } 46 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/cache/PathChildrenCacheListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.netflix.curator.framework.recipes.cache; 17 | 18 | import com.netflix.curator.framework.CuratorFramework; 19 | 20 | /** 21 | * Listener for PathChildrenCache changes 22 | */ 23 | public interface PathChildrenCacheListener 24 | { 25 | /** 26 | * Called when a change has occurred 27 | * 28 | * @param client the client 29 | * @param event describes the change 30 | * @throws Exception errors 31 | */ 32 | public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception; 33 | } 34 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/ensemble/exhibitor/ExhibitorRestClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.ensemble.exhibitor; 20 | 21 | public interface ExhibitorRestClient 22 | { 23 | /** 24 | * Connect to the given Exhibitor and return the raw result 25 | * 26 | * @param hostname host to connect to 27 | * @param port connect port 28 | * @param uriPath path 29 | * @param mimeType Accept mime type 30 | * @return raw result 31 | * @throws Exception errors 32 | */ 33 | public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception; 34 | } 35 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/BackgroundCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import com.netflix.curator.framework.CuratorFramework; 21 | 22 | /** 23 | * Functor for an async background operation 24 | */ 25 | public interface BackgroundCallback 26 | { 27 | /** 28 | * Called when the async background operation completes 29 | * 30 | * @param client the client 31 | * @param event operation result details 32 | * @throws Exception errors 33 | */ 34 | public void processResult(CuratorFramework client, CuratorEvent event) throws Exception; 35 | } 36 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/CuratorWatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.api; 18 | 19 | import org.apache.zookeeper.WatchedEvent; 20 | import org.apache.zookeeper.Watcher; 21 | 22 | /** 23 | * A version of {@link Watcher} that can throw an exception 24 | */ 25 | public interface CuratorWatcher 26 | { 27 | /** 28 | * Same as {@link Watcher#process(WatchedEvent)}. If an exception 29 | * is thrown, Curator will log it 30 | * 31 | * @param event the event 32 | * @throws Exception any exceptions to log 33 | */ 34 | public void process(WatchedEvent event) throws Exception; 35 | } 36 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/imps/DefaultACLProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.imps; 18 | 19 | import com.netflix.curator.framework.api.ACLProvider; 20 | import org.apache.zookeeper.ZooDefs; 21 | import org.apache.zookeeper.data.ACL; 22 | import java.util.List; 23 | 24 | public class DefaultACLProvider implements ACLProvider 25 | { 26 | @Override 27 | public List getDefaultAcl() 28 | { 29 | return ZooDefs.Ids.OPEN_ACL_UNSAFE; 30 | } 31 | 32 | @Override 33 | public List getAclForPath(String path) 34 | { 35 | return ZooDefs.Ids.OPEN_ACL_UNSAFE; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/details/InstanceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.details; 20 | 21 | import com.netflix.curator.x.discovery.ServiceInstance; 22 | import java.util.List; 23 | 24 | /** 25 | * Provides a set of available instances for a service so that a strategy can pick one of them 26 | */ 27 | public interface InstanceProvider 28 | { 29 | /** 30 | * Return the current available set of instances 31 | * @return instances 32 | * @throws Exception any errors 33 | */ 34 | public List> getInstances() throws Exception; 35 | } 36 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/locks/RevocationSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | import java.util.concurrent.Executor; 20 | 21 | class RevocationSpec 22 | { 23 | private final Runnable runnable; 24 | private final Executor executor; 25 | 26 | RevocationSpec(Executor executor, Runnable runnable) 27 | { 28 | this.runnable = runnable; 29 | this.executor = executor; 30 | } 31 | 32 | Runnable getRunnable() 33 | { 34 | return runnable; 35 | } 36 | 37 | Executor getExecutor() 38 | { 39 | return executor; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/CuratorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import com.netflix.curator.framework.CuratorFramework; 21 | 22 | /** 23 | * Receives notifications about errors and background events 24 | */ 25 | public interface CuratorListener 26 | { 27 | /** 28 | * Called when a background task has completed or a watch has triggered 29 | * 30 | * @param client client 31 | * @param event the event 32 | * @throws Exception any errors 33 | */ 34 | public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception; 35 | } 36 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/queue/MultiItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.queue; 18 | 19 | /** 20 | * Abstraction for multiple items. 21 | * @see DistributedQueue#putMulti(MultiItem) 22 | * @see DistributedPriorityQueue#putMulti(MultiItem, int) 23 | */ 24 | public interface MultiItem 25 | { 26 | /** 27 | * Called repeatedly to get the items to add to the queue. This method 28 | * should return null when there are no more items to add. 29 | * 30 | * @return item or null 31 | * @throws Exception any errors 32 | */ 33 | public T nextItem() throws Exception; 34 | } 35 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/queue/QueueSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.netflix.curator.framework.recipes.queue; 17 | 18 | /** 19 | * Helper to serialize/deserialize queue items 20 | */ 21 | public interface QueueSerializer 22 | { 23 | /** 24 | * Turn a queue item into bytes 25 | * 26 | * @param item the item 27 | * @return byte representation 28 | */ 29 | public byte[] serialize(T item); 30 | 31 | /** 32 | * Deserialize bytes into a queue item 33 | * 34 | * @param bytes byte representation 35 | * @return item 36 | */ 37 | public T deserialize(byte[] bytes); 38 | } 39 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/shared/SharedValueReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.shared; 18 | 19 | import com.netflix.curator.framework.listen.ListenerContainer; 20 | 21 | /** 22 | * Abstracts a shared value and allows listening for changes to the value 23 | */ 24 | public interface SharedValueReader 25 | { 26 | /** 27 | * Return the current value of the count 28 | * 29 | * @return count 30 | */ 31 | public byte[] getValue(); 32 | 33 | /** 34 | * Returns the listenable 35 | * 36 | * @return listenable 37 | */ 38 | public ListenerContainer getListenable(); 39 | } 40 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/shared/SharedValueListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.shared; 18 | 19 | import com.netflix.curator.framework.state.ConnectionStateListener; 20 | 21 | /** 22 | * Listener for changes to a shared value 23 | */ 24 | public interface SharedValueListener extends ConnectionStateListener 25 | { 26 | /** 27 | * Called when the shared value has changed 28 | * 29 | * @param sharedValue the shared value instance 30 | * @param newValue the new value 31 | * @throws Exception errors 32 | */ 33 | public void valueHasChanged(SharedValueReader sharedValue, byte[] newValue) throws Exception; 34 | } 35 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/shared/SharedCountListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.shared; 18 | 19 | import com.netflix.curator.framework.state.ConnectionStateListener; 20 | 21 | /** 22 | * Listener for changes to a shared count 23 | */ 24 | public interface SharedCountListener extends ConnectionStateListener 25 | { 26 | /** 27 | * Called when the shared value has changed 28 | * 29 | * @param sharedCount the shared count instance 30 | * @param newCount the new count 31 | * @throws Exception errors 32 | */ 33 | public void countHasChanged(SharedCountReader sharedCount, int newCount) throws Exception; 34 | } 35 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/queue/QueuePutListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.queue; 18 | 19 | /** 20 | * Queue puts are done in the background. Use this listener to 21 | * be notified when the put completes 22 | */ 23 | public interface QueuePutListener 24 | { 25 | /** 26 | * Notification that a single item put has completed 27 | * 28 | * @param item the item 29 | */ 30 | public void putCompleted(T item); 31 | 32 | /** 33 | * Notification that a multi item put has completed 34 | * 35 | * @param items the items 36 | */ 37 | public void putMultiCompleted(MultiItem items); 38 | } 39 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/ProviderStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery; 20 | 21 | import com.netflix.curator.x.discovery.details.InstanceProvider; 22 | 23 | /** 24 | * A strategy for picking one from a set of instances 25 | */ 26 | public interface ProviderStrategy 27 | { 28 | /** 29 | * Given a source of instances, return one of them for a single use. 30 | * 31 | * @param instanceProvider the instance provider 32 | * @return the instance to use 33 | * @throws Exception any errors 34 | */ 35 | public ServiceInstance getInstance(InstanceProvider instanceProvider) throws Exception; 36 | } 37 | -------------------------------------------------------------------------------- /curator-x-zkclient-bridge/src/test/java/org/I0Itec/zkclient/ZkConnectionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.I0Itec.zkclient; 17 | 18 | import org.I0Itec.zkclient.testutil.ZkTestSystem; 19 | import org.junit.Rule; 20 | 21 | public class ZkConnectionTest extends AbstractConnectionTest { 22 | 23 | @Rule 24 | public ZkTestSystem _zk = ZkTestSystem.getInstance(); 25 | 26 | public ZkConnectionTest() { 27 | super(establishConnection()); 28 | } 29 | 30 | private static IZkConnection establishConnection() { 31 | IZkConnection zkConnection = ZkTestSystem.createZkConnection("localhost:" + ZkTestSystem.getInstance().getZkServer().getPort()); 32 | new ZkClient(zkConnection);// connect 33 | return zkConnection; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/ACLProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.api; 18 | 19 | import org.apache.zookeeper.ZooDefs; 20 | import org.apache.zookeeper.data.ACL; 21 | import java.util.List; 22 | 23 | public interface ACLProvider 24 | { 25 | /** 26 | * Return the ACL list to use by default (usually {@link ZooDefs.Ids#OPEN_ACL_UNSAFE}). 27 | * 28 | * @return default ACL list 29 | */ 30 | public List getDefaultAcl(); 31 | 32 | /** 33 | * Return the ACL list to use for the given path 34 | * 35 | * @param path path (NOTE: might be null) 36 | * @return ACL list 37 | */ 38 | public List getAclForPath(String path); 39 | } 40 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/test/java/com/netflix/curator/x/discovery/server/jetty_jersey/StringDiscoveryResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.server.jetty_jersey; 20 | 21 | import com.netflix.curator.x.discovery.server.rest.DiscoveryContext; 22 | import com.netflix.curator.x.discovery.server.rest.DiscoveryResource; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.core.Context; 25 | import javax.ws.rs.ext.ContextResolver; 26 | 27 | @Path("/") 28 | public class StringDiscoveryResource extends DiscoveryResource 29 | { 30 | public StringDiscoveryResource(@Context ContextResolver> resolver) 31 | { 32 | super(resolver.getContext(DiscoveryContext.class)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | http://netflix.github.com/curator/curator.png 2 | 3 | == DESCRIPTION 4 | 5 | Curator is a set of Java libraries that make using Apache ZooKeeper much easier. While 6 | ZooKeeper comes bundled with a Java client, using the client is non-trivial and error prone. 7 | 8 | == DETAILS 9 | 10 | Please see the doc at https://github.com/Netflix/curator/wiki 11 | 12 | == BUILDING 13 | 14 | Curator is built via Gradle (http://www.gradle.org). To build from the command line: 15 | ./gradlew build 16 | 17 | == ARTIFACTS 18 | 19 | Curator binaries are published to Maven Central. Please see the docs for details. 20 | 21 | == MAILING LIST 22 | 23 | There is a Curator mailing list. Join here: http://groups.google.com/group/curator-users 24 | 25 | == AUTHOR 26 | 27 | Jordan Zimmerman (mailto:jzimmerman@netflix.com) 28 | 29 | == LICENSE 30 | 31 | Copyright 2011 Netflix, Inc. 32 | 33 | Licensed under the Apache License, Version 2.0 (the "License"); 34 | you may not use this file except in compliance with the License. 35 | You may obtain a copy of the License at 36 | 37 | http://www.apache.org/licenses/LICENSE-2.0 38 | 39 | Unless required by applicable law or agreed to in writing, software 40 | distributed under the License is distributed on an "AS IS" BASIS, 41 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 42 | See the License for the specific language governing permissions and 43 | limitations under the License. 44 | -------------------------------------------------------------------------------- /curator-client/src/test/java/com/netflix/curator/BaseClassForTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator; 19 | 20 | import com.netflix.curator.test.TestingServer; 21 | import com.netflix.curator.utils.DebugUtils; 22 | import org.testng.annotations.AfterMethod; 23 | import org.testng.annotations.BeforeMethod; 24 | 25 | public class BaseClassForTests 26 | { 27 | protected TestingServer server; 28 | 29 | @BeforeMethod 30 | public void setup() throws Exception 31 | { 32 | System.setProperty(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES, "true"); 33 | server = new TestingServer(); 34 | } 35 | 36 | @AfterMethod 37 | public void teardown() throws Exception 38 | { 39 | server.close(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/cache/EventOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.cache; 18 | 19 | class EventOperation implements Operation 20 | { 21 | private final PathChildrenCache cache; 22 | private final PathChildrenCacheEvent event; 23 | 24 | EventOperation(PathChildrenCache cache, PathChildrenCacheEvent event) 25 | { 26 | this.cache = cache; 27 | this.event = event; 28 | } 29 | 30 | @Override 31 | public void invoke() 32 | { 33 | cache.callListeners(event); 34 | } 35 | 36 | @Override 37 | public String toString() 38 | { 39 | return "EventOperation{" + 40 | "event=" + event + 41 | '}'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/Watchable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import org.apache.zookeeper.Watcher; 21 | 22 | public interface Watchable 23 | { 24 | /** 25 | * Have the operation set a watch 26 | * 27 | * @return this 28 | */ 29 | public T watched(); 30 | 31 | /** 32 | * Set a watcher for the operation 33 | * 34 | * @param watcher the watcher 35 | * @return this 36 | */ 37 | public T usingWatcher(Watcher watcher); 38 | 39 | /** 40 | * Set a watcher for the operation 41 | * 42 | * @param watcher the watcher 43 | * @return this 44 | */ 45 | public T usingWatcher(CuratorWatcher watcher); 46 | } 47 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/RetryPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator; 19 | 20 | /** 21 | * Abstracts the policy to use when retrying connections 22 | */ 23 | public interface RetryPolicy 24 | { 25 | /** 26 | * Called when an operation has failed for some reason. This method should return 27 | * true to make another attempt. 28 | * 29 | * 30 | * @param retryCount the number of times retried so far (0 the first time) 31 | * @param elapsedTimeMs the elapsed time in ms since the operation was attempted 32 | * @param sleeper use this to sleep - DO NOT call Thread.sleep 33 | * @return true/false 34 | */ 35 | public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper); 36 | } 37 | -------------------------------------------------------------------------------- /curator-recipes/src/test/java/com/netflix/curator/framework/recipes/BaseClassForTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes; 18 | 19 | import com.netflix.curator.test.TestingServer; 20 | import com.netflix.curator.utils.DebugUtils; 21 | import org.testng.annotations.AfterMethod; 22 | import org.testng.annotations.BeforeMethod; 23 | 24 | public class BaseClassForTests 25 | { 26 | protected TestingServer server; 27 | 28 | @BeforeMethod 29 | public void setup() throws Exception 30 | { 31 | System.setProperty(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES, "true"); 32 | server = new TestingServer(); 33 | } 34 | 35 | @AfterMethod 36 | public void teardown() throws Exception 37 | { 38 | server.close(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/drivers/TracerDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.drivers; 19 | 20 | import java.util.concurrent.TimeUnit; 21 | 22 | /** 23 | * Mechanism for timing methods and recording counters 24 | */ 25 | public interface TracerDriver 26 | { 27 | /** 28 | * Record the given trace event 29 | * 30 | * @param name of the event 31 | * @param time time event took 32 | * @param unit time unit 33 | */ 34 | public void addTrace(String name, long time, TimeUnit unit); 35 | 36 | /** 37 | * Add to a named counter 38 | * 39 | * @param name name of the counter 40 | * @param increment amount to increment 41 | */ 42 | public void addCount(String name, int increment); 43 | } 44 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/test/java/com/netflix/curator/x/discovery/server/jetty_jersey/MapDiscoveryResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.server.jetty_jersey; 20 | 21 | import com.netflix.curator.x.discovery.server.rest.DiscoveryContext; 22 | import com.netflix.curator.x.discovery.server.rest.DiscoveryResource; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.core.Context; 25 | import javax.ws.rs.ext.ContextResolver; 26 | import java.util.Map; 27 | 28 | @Path("/") 29 | public class MapDiscoveryResource extends DiscoveryResource> 30 | { 31 | public MapDiscoveryResource(@Context ContextResolver>> resolver) 32 | { 33 | super(resolver.getContext(DiscoveryContext.class)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/leader/LeaderSelectorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.netflix.curator.framework.recipes.leader; 17 | 18 | import com.netflix.curator.framework.CuratorFramework; 19 | import com.netflix.curator.framework.state.ConnectionStateListener; 20 | 21 | /** 22 | * Notification for leadership 23 | * 24 | * @see LeaderSelector 25 | */ 26 | public interface LeaderSelectorListener extends ConnectionStateListener 27 | { 28 | /** 29 | * Called when your instance has been granted leadership. This method 30 | * should not return until you wish to release leadership 31 | * 32 | * @param client the client 33 | * @throws Exception any errors 34 | */ 35 | public void takeLeadership(CuratorFramework client) throws Exception; 36 | } 37 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/test/java/com/netflix/curator/x/discovery/server/jetty_jersey/ServiceDetailsDiscoveryResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.server.jetty_jersey; 20 | 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.core.Context; 23 | import javax.ws.rs.ext.ContextResolver; 24 | 25 | import com.netflix.curator.x.discovery.server.rest.DiscoveryContext; 26 | import com.netflix.curator.x.discovery.server.rest.DiscoveryResource; 27 | 28 | @Path("/") 29 | public class ServiceDetailsDiscoveryResource extends DiscoveryResource 30 | { 31 | public ServiceDetailsDiscoveryResource(@Context ContextResolver> resolver) 32 | { 33 | super(resolver.getContext(DiscoveryContext.class)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/UnhandledErrorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.api; 20 | 21 | import com.netflix.curator.framework.state.ConnectionState; 22 | import com.netflix.curator.framework.state.ConnectionStateListener; 23 | 24 | public interface UnhandledErrorListener 25 | { 26 | /** 27 | * Called when an exception is caught in a background thread, handler, etc. Before this 28 | * listener is called, the error will have been logged and a {@link ConnectionState#LOST} 29 | * event will have been queued for any {@link ConnectionStateListener}s. 30 | * 31 | * @param message Source message 32 | * @param e exception 33 | */ 34 | public void unhandledError(String message, Throwable e); 35 | } 36 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/transaction/CuratorTransactionFinal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.api.transaction; 20 | 21 | import java.util.Collection; 22 | 23 | /** 24 | * Adds commit to the transaction interface 25 | */ 26 | public interface CuratorTransactionFinal extends CuratorTransaction 27 | { 28 | /** 29 | * Commit all added operations as an atomic unit and return results 30 | * for the operations. One result is returned for each operation added. 31 | * Further, the ordering of the results matches the ordering that the 32 | * operations were added. 33 | * 34 | * @return operation results 35 | * @throws Exception errors 36 | */ 37 | public Collection commit() throws Exception; 38 | } 39 | -------------------------------------------------------------------------------- /curator-examples/src/main/java/discovery/InstanceDetails.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package discovery; 18 | 19 | import org.codehaus.jackson.map.annotate.JsonRootName; 20 | 21 | /** 22 | * In a real application, the Service payload will most likely 23 | * be more detailed than this. But, this gives a good example. 24 | */ 25 | @JsonRootName("details") 26 | public class InstanceDetails 27 | { 28 | private String description; 29 | 30 | public InstanceDetails() 31 | { 32 | this(""); 33 | } 34 | 35 | public InstanceDetails(String description) 36 | { 37 | this.description = description; 38 | } 39 | 40 | public void setDescription(String description) 41 | { 42 | this.description = description; 43 | } 44 | 45 | public String getDescription() 46 | { 47 | return description; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/utils/DefaultTracerDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.utils; 19 | 20 | import com.netflix.curator.drivers.TracerDriver; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | /** 26 | * Default tracer driver 27 | */ 28 | public class DefaultTracerDriver implements TracerDriver 29 | { 30 | private final Logger log = LoggerFactory.getLogger(getClass()); 31 | 32 | @Override 33 | public void addTrace(String name, long time, TimeUnit unit) 34 | { 35 | log.trace("Trace: " + TimeUnit.MILLISECONDS.convert(time, unit) + " ms"); 36 | } 37 | 38 | @Override 39 | public void addCount(String name, int increment) 40 | { 41 | log.trace("Counter " + name + ": " + increment); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /curator-recipes/src/test/java/com/netflix/curator/framework/recipes/locks/TestInterProcessSemaphoreMutex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.netflix.curator.framework.recipes.locks; 17 | 18 | import com.netflix.curator.framework.CuratorFramework; 19 | import org.testng.annotations.Test; 20 | 21 | public class TestInterProcessSemaphoreMutex extends TestInterProcessMutexBase 22 | { 23 | private static final String LOCK_PATH = "/locks/our-lock"; 24 | 25 | @Override 26 | @Test(enabled = false) 27 | public void testReentrant() throws Exception 28 | { 29 | } 30 | 31 | @Override 32 | @Test(enabled = false) 33 | public void testReentrant2Threads() throws Exception 34 | { 35 | } 36 | 37 | @Override 38 | protected InterProcessLock makeLock(CuratorFramework client) 39 | { 40 | return new InterProcessSemaphoreMutex(client, LOCK_PATH); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /curator-x-discovery/src/test/java/com/netflix/curator/x/discovery/TestLocalIpFilter.java: -------------------------------------------------------------------------------- 1 | package com.netflix.curator.x.discovery; 2 | 3 | import com.google.common.collect.Lists; 4 | import org.testng.Assert; 5 | import org.testng.annotations.Test; 6 | import java.net.InetAddress; 7 | import java.net.NetworkInterface; 8 | import java.net.SocketException; 9 | import java.util.List; 10 | 11 | public class TestLocalIpFilter 12 | { 13 | @Test 14 | public void testFilterEverything() throws SocketException 15 | { 16 | LocalIpFilter localIpFilter = ServiceInstanceBuilder.getLocalIpFilter(); 17 | try 18 | { 19 | ServiceInstanceBuilder.setLocalIpFilter 20 | ( 21 | new LocalIpFilter() 22 | { 23 | @Override 24 | public boolean use(NetworkInterface networkInterface, InetAddress address) throws SocketException 25 | { 26 | return false; 27 | } 28 | } 29 | ); 30 | 31 | List allLocalIPs = Lists.newArrayList(ServiceInstanceBuilder.getAllLocalIPs()); 32 | Assert.assertEquals(allLocalIPs.size(), 0); 33 | } 34 | finally 35 | { 36 | ServiceInstanceBuilder.setLocalIpFilter(localIpFilter); 37 | } 38 | 39 | List allLocalIPs = Lists.newArrayList(ServiceInstanceBuilder.getAllLocalIPs()); 40 | Assert.assertTrue(allLocalIPs.size() > 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/ServiceCacheBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery; 20 | 21 | import java.util.concurrent.ThreadFactory; 22 | 23 | public interface ServiceCacheBuilder 24 | { 25 | /** 26 | * Return a new service cache with the current settings 27 | * 28 | * @return service cache 29 | */ 30 | public ServiceCache build(); 31 | 32 | /** 33 | * The name of the service to cache (required) 34 | * 35 | * @param name service name 36 | * @return this 37 | */ 38 | public ServiceCacheBuilder name(String name); 39 | 40 | /** 41 | * Optional thread factory to use for the cache's internal thread 42 | * 43 | * @param threadFactory factory 44 | * @return this 45 | */ 46 | public ServiceCacheBuilder threadFactory(ThreadFactory threadFactory); 47 | } 48 | -------------------------------------------------------------------------------- /curator-examples/src/main/java/locking/FakeLimitedResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package locking; 18 | 19 | import java.util.concurrent.atomic.AtomicBoolean; 20 | 21 | /** 22 | * Simulates some external resource that can only be access by one process at a time 23 | */ 24 | public class FakeLimitedResource 25 | { 26 | private final AtomicBoolean inUse = new AtomicBoolean(false); 27 | 28 | public void use() throws InterruptedException 29 | { 30 | // in a real application this would be accessing/manipulating a shared resource 31 | 32 | if ( !inUse.compareAndSet(false, true) ) 33 | { 34 | throw new IllegalStateException("Needs to be used by one client at a time"); 35 | } 36 | 37 | try 38 | { 39 | Thread.sleep((long)(3 * Math.random())); 40 | } 41 | finally 42 | { 43 | inUse.set(false); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /curator-framework/src/test/java/com/netflix/curator/framework/imps/BaseClassForTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.imps; 20 | 21 | import com.netflix.curator.test.TestingServer; 22 | import com.netflix.curator.utils.DebugUtils; 23 | import org.testng.annotations.AfterMethod; 24 | import org.testng.annotations.BeforeMethod; 25 | 26 | public class BaseClassForTests 27 | { 28 | protected TestingServer server; 29 | 30 | @BeforeMethod 31 | public void setup() throws Exception 32 | { 33 | System.setProperty(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES, "true"); 34 | server = new TestingServer(); 35 | } 36 | 37 | @AfterMethod 38 | public void teardown() 39 | { 40 | try 41 | { 42 | server.close(); 43 | } 44 | catch ( Throwable e ) 45 | { 46 | e.printStackTrace(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/details/InstanceSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.x.discovery.details; 19 | 20 | import com.netflix.curator.x.discovery.ServiceInstance; 21 | 22 | /** 23 | * Injectable serializer for service instances 24 | */ 25 | public interface InstanceSerializer 26 | { 27 | /** 28 | * Serialize an instance into bytes 29 | * 30 | * @param instance the instance 31 | * @return byte array representing the instance 32 | * @throws Exception any errors 33 | */ 34 | public byte[] serialize(ServiceInstance instance) throws Exception; 35 | 36 | /** 37 | * Deserialize a byte array into an instance 38 | * 39 | * @param bytes the bytes 40 | * @return service instance 41 | * @throws Exception any errors 42 | */ 43 | public ServiceInstance deserialize(byte[] bytes) throws Exception; 44 | } 45 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/main/java/com/netflix/curator/x/discovery/server/entity/ServiceNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.server.entity; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | import com.google.common.collect.Lists; 23 | import javax.xml.bind.annotation.XmlElement; 24 | import javax.xml.bind.annotation.XmlRootElement; 25 | import java.util.Collection; 26 | import java.util.List; 27 | 28 | /** 29 | * Raw generic lists don't work well in JAX-RS. Thus, this wrapper is needed. 30 | */ 31 | public class ServiceNames 32 | { 33 | private final List names; 34 | 35 | public ServiceNames() 36 | { 37 | names = Lists.newArrayList(); 38 | } 39 | 40 | public ServiceNames(Collection c) 41 | { 42 | names = Lists.newArrayList(c); 43 | } 44 | 45 | public List getNames() 46 | { 47 | return ImmutableList.copyOf(names); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/locks/Revocable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | import java.util.concurrent.Executor; 20 | 21 | /** 22 | * Specifies locks that can be revoked 23 | */ 24 | public interface Revocable 25 | { 26 | /** 27 | * Make the lock revocable. Your listener will get called when another process/thread 28 | * wants you to release the lock. Revocation is cooperative. 29 | * 30 | * @param listener the listener 31 | */ 32 | public void makeRevocable(RevocationListener listener); 33 | 34 | /** 35 | * Make the lock revocable. Your listener will get called when another process/thread 36 | * wants you to release the lock. Revocation is cooperative. 37 | * 38 | * @param listener the listener 39 | * @param executor executor for the listener 40 | */ 41 | public void makeRevocable(RevocationListener listener, Executor executor); 42 | } 43 | -------------------------------------------------------------------------------- /curator-recipes/src/test/java/com/netflix/curator/framework/recipes/queue/QueueTestProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.netflix.curator.framework.recipes.queue; 17 | 18 | import java.util.concurrent.Callable; 19 | 20 | public class QueueTestProducer implements Callable 21 | { 22 | private final DistributedQueue queue; 23 | private final int itemQty; 24 | private final int startIndex; 25 | 26 | public QueueTestProducer(DistributedQueue queue, int itemQty, int startIndex) 27 | { 28 | this.queue = queue; 29 | this.itemQty = itemQty; 30 | this.startIndex = startIndex; 31 | } 32 | 33 | @Override 34 | public Void call() throws Exception 35 | { 36 | int count = 0; 37 | while ( !Thread.currentThread().isInterrupted() && (count < itemQty) ) 38 | { 39 | queue.put(new TestQueueItem(Integer.toString(count + startIndex))); 40 | ++count; 41 | } 42 | return null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/main/java/com/netflix/curator/x/discovery/server/entity/ServiceInstances.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.server.entity; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | import com.google.common.collect.Lists; 23 | import com.netflix.curator.x.discovery.ServiceInstance; 24 | import java.util.Collection; 25 | import java.util.List; 26 | 27 | /** 28 | * Raw generic lists don't work well in JAX-RS. Thus, this wrapper is needed. 29 | */ 30 | public class ServiceInstances 31 | { 32 | private final List> services; 33 | 34 | public ServiceInstances() 35 | { 36 | services = Lists.newArrayList(); 37 | } 38 | 39 | public ServiceInstances(Collection> c) 40 | { 41 | services = Lists.newArrayList(c); 42 | } 43 | 44 | public List> getServices() 45 | { 46 | return ImmutableList.copyOf(services); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/TimeTrace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator; 19 | 20 | import com.netflix.curator.drivers.TracerDriver; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | /** 24 | * Utility to time a method or portion of code 25 | */ 26 | public class TimeTrace 27 | { 28 | private final String name; 29 | private final TracerDriver driver; 30 | private final long startTimeNanos = System.nanoTime(); 31 | 32 | /** 33 | * Create and start a timer 34 | * 35 | * @param name name of the event 36 | * @param driver driver 37 | */ 38 | public TimeTrace(String name, TracerDriver driver) 39 | { 40 | this.name = name; 41 | this.driver = driver; 42 | } 43 | 44 | /** 45 | * Record the elapsed time 46 | */ 47 | public void commit() 48 | { 49 | long elapsed = System.nanoTime() - startTimeNanos; 50 | driver.addTrace(name, elapsed, TimeUnit.NANOSECONDS); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/locks/Lease.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | import java.io.Closeable; 20 | import java.io.IOException; 21 | 22 | /** 23 | * Represents an acquired lease from an {@link InterProcessSemaphore}. It is the client's responsibility 24 | * to close this lease when it is no longer needed so that other blocked clients can use it. If the 25 | * client crashes (or its session expires, etc.) the lease will automatically be closed. 26 | */ 27 | public interface Lease extends Closeable 28 | { 29 | /** 30 | * Releases the lease so that other clients/processes can acquire it 31 | * 32 | * @throws IOException errors 33 | */ 34 | @Override 35 | public void close() throws IOException; 36 | 37 | /** 38 | * Return the data stored in the node for this lease 39 | * 40 | * @return data 41 | * @throws Exception errors 42 | */ 43 | public byte[] getData() throws Exception; 44 | } 45 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/utils/ZookeeperFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.utils; 18 | 19 | import org.apache.zookeeper.Watcher; 20 | import org.apache.zookeeper.ZooKeeper; 21 | 22 | public interface ZookeeperFactory 23 | { 24 | /** 25 | * Allocate a new ZooKeeper instance 26 | * 27 | * 28 | * @param connectString the connection string 29 | * @param sessionTimeout session timeout in milliseconds 30 | * @param watcher optional watcher 31 | * @param canBeReadOnly if true, allow ZooKeeper client to enter 32 | * read only mode in case of a network partition. See 33 | * {@link ZooKeeper#ZooKeeper(String, int, Watcher, long, byte[], boolean)} 34 | * for details 35 | * @return the instance 36 | * @throws Exception errors 37 | */ 38 | public ZooKeeper newZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws Exception; 39 | } 40 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/ServiceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery; 20 | 21 | import com.netflix.curator.x.discovery.details.InstanceProvider; 22 | import java.io.Closeable; 23 | 24 | /** 25 | * The main API for Discovery. This class is essentially a facade over a {@link ProviderStrategy} 26 | * paired with an {@link InstanceProvider} 27 | */ 28 | public interface ServiceProvider extends Closeable 29 | { 30 | /** 31 | * The provider must be started before use 32 | * 33 | * @throws Exception any errors 34 | */ 35 | public void start() throws Exception; 36 | 37 | /** 38 | * Return an instance for a single use. IMPORTANT: users 39 | * should not hold on to the instance returned. They should always get a fresh instance. 40 | * 41 | * @return the instance to use 42 | * @throws Exception any errors 43 | */ 44 | public ServiceInstance getInstance() throws Exception; 45 | } 46 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/listen/Listenable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.listen; 20 | 21 | import java.util.concurrent.Executor; 22 | 23 | /** 24 | * Abstracts a listenable object 25 | */ 26 | public interface Listenable 27 | { 28 | /** 29 | * Add the given listener. The listener will be executed in the containing 30 | * instance's thread. 31 | * 32 | * @param listener listener to add 33 | */ 34 | public void addListener(T listener); 35 | 36 | /** 37 | * Add the given listener. The listener will be executed using the given 38 | * executor 39 | * 40 | * @param listener listener to add 41 | * @param executor executor to run listener in 42 | */ 43 | public void addListener(T listener, Executor executor); 44 | 45 | /** 46 | * Remove the given listener 47 | * 48 | * @param listener listener to remove 49 | */ 50 | public void removeListener(T listener); 51 | } 52 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/imps/FailedDeleteManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.imps; 20 | 21 | import com.netflix.curator.framework.CuratorFramework; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | class FailedDeleteManager 26 | { 27 | private final Logger log = LoggerFactory.getLogger(getClass()); 28 | private final CuratorFramework client; 29 | 30 | FailedDeleteManager(CuratorFramework client) 31 | { 32 | this.client = client; 33 | } 34 | 35 | void addFailedDelete(String path) 36 | { 37 | if ( client.isStarted() ) 38 | { 39 | log.debug("Path being added to guaranteed delete set: " + path); 40 | try 41 | { 42 | client.delete().guaranteed().inBackground().forPath(path); 43 | } 44 | catch ( Exception e ) 45 | { 46 | addFailedDelete(path); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/PathAndBytesable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import com.netflix.curator.framework.CuratorFrameworkFactory; 21 | 22 | public interface PathAndBytesable 23 | { 24 | /** 25 | * Commit the currently building operation using the given path and data 26 | * 27 | * @param path the path 28 | * @param data the data 29 | * @return operation result if any 30 | * @throws Exception errors 31 | */ 32 | public T forPath(String path, byte[] data) throws Exception; 33 | 34 | /** 35 | * Commit the currently building operation using the given path and the default data 36 | * for the client (usually a byte[0] unless changed via 37 | * {@link CuratorFrameworkFactory.Builder#defaultData(byte[])}). 38 | * 39 | * @param path the path 40 | * @return operation result if any 41 | * @throws Exception errors 42 | */ 43 | public T forPath(String path) throws Exception; 44 | } 45 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/ServiceCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.x.discovery; 18 | 19 | import com.netflix.curator.framework.listen.Listenable; 20 | import com.netflix.curator.x.discovery.details.InstanceProvider; 21 | import com.netflix.curator.x.discovery.details.ServiceCacheListener; 22 | import java.io.Closeable; 23 | import java.util.List; 24 | 25 | public interface ServiceCache extends Closeable, Listenable, InstanceProvider 26 | { 27 | /** 28 | * Return the current list of instances. NOTE: there is no guarantee of freshness. This is 29 | * merely the last known list of instances. However, the list is updated via a ZooKeeper watcher 30 | * so it should be fresh within a window of a second or two. 31 | * 32 | * @return the list 33 | */ 34 | public List> getInstances(); 35 | 36 | /** 37 | * The cache must be started before use 38 | * 39 | * @throws Exception errors 40 | */ 41 | public void start() throws Exception; 42 | } 43 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/atomic/AtomicValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.atomic; 18 | 19 | /** 20 | * Abstracts a value returned from one of the Atomics 21 | */ 22 | public interface AtomicValue 23 | { 24 | /** 25 | * MUST be checked. Returns true if the operation succeeded. If false is returned, 26 | * the operation failed and the atomic was not updated. 27 | * 28 | * @return true/false 29 | */ 30 | public boolean succeeded(); 31 | 32 | /** 33 | * Returns the value of the counter prior to the operation 34 | * 35 | * @return pre-operation value 36 | */ 37 | public T preValue(); 38 | 39 | /** 40 | * Returns the value of the counter after to the operation 41 | * 42 | * @return post-operation value 43 | */ 44 | public T postValue(); 45 | 46 | /** 47 | * Returns debugging stats about the operation 48 | * 49 | * @return stats 50 | */ 51 | public AtomicStats getStats(); 52 | } 53 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/strategies/RandomStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.strategies; 20 | 21 | import com.netflix.curator.x.discovery.details.InstanceProvider; 22 | import com.netflix.curator.x.discovery.ProviderStrategy; 23 | import com.netflix.curator.x.discovery.ServiceInstance; 24 | import java.util.List; 25 | import java.util.Random; 26 | 27 | /** 28 | * This strategy always picks a random instance from the list 29 | */ 30 | public class RandomStrategy implements ProviderStrategy 31 | { 32 | private final Random random = new Random(); 33 | 34 | @Override 35 | public ServiceInstance getInstance(InstanceProvider instanceProvider) throws Exception 36 | { 37 | List> instances = instanceProvider.getInstances(); 38 | if ( instances.size() == 0 ) 39 | { 40 | return null; 41 | } 42 | int thisIndex = random.nextInt(instances.size()); 43 | return instances.get(thisIndex); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/retry/RetryUntilElapsed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.retry; 19 | 20 | import com.netflix.curator.RetrySleeper; 21 | 22 | /** 23 | * A retry policy that retries until a given amount of time elapses 24 | */ 25 | public class RetryUntilElapsed extends SleepingRetry 26 | { 27 | private final int maxElapsedTimeMs; 28 | private final int sleepMsBetweenRetries; 29 | 30 | public RetryUntilElapsed(int maxElapsedTimeMs, int sleepMsBetweenRetries) 31 | { 32 | super(Integer.MAX_VALUE); 33 | this.maxElapsedTimeMs = maxElapsedTimeMs; 34 | this.sleepMsBetweenRetries = sleepMsBetweenRetries; 35 | } 36 | 37 | @Override 38 | public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper) 39 | { 40 | return super.allowRetry(retryCount, elapsedTimeMs, sleeper) && (elapsedTimeMs < maxElapsedTimeMs); 41 | } 42 | 43 | @Override 44 | protected int getSleepTimeMs(int retryCount, long elapsedTimeMs) 45 | { 46 | return sleepMsBetweenRetries; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/atomic/MutableAtomicValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.atomic; 18 | 19 | class MutableAtomicValue implements AtomicValue 20 | { 21 | T preValue; 22 | T postValue; 23 | boolean succeeded = false; 24 | AtomicStats stats = new AtomicStats(); 25 | 26 | MutableAtomicValue(T preValue, T postValue) 27 | { 28 | this(preValue, postValue, false); 29 | } 30 | 31 | MutableAtomicValue(T preValue, T postValue, boolean succeeded) 32 | { 33 | this.preValue = preValue; 34 | this.postValue = postValue; 35 | this.succeeded = succeeded; 36 | } 37 | 38 | @Override 39 | public T preValue() 40 | { 41 | return preValue; 42 | } 43 | 44 | @Override 45 | public T postValue() 46 | { 47 | return postValue; 48 | } 49 | 50 | @Override 51 | public boolean succeeded() 52 | { 53 | return succeeded; 54 | } 55 | 56 | @Override 57 | public AtomicStats getStats() 58 | { 59 | return stats; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/DeleteBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import com.netflix.curator.framework.CuratorFramework; 21 | 22 | public interface DeleteBuilder extends DeleteBuilderBase 23 | { 24 | /** 25 | *

26 | * Solves this edge case: deleting a node can fail due to connection issues. Further, 27 | * if the node was ephemeral, the node will not get auto-deleted as the session is still valid. 28 | * This can wreak havoc with lock implementations. 29 | *

30 | * 31 | *

32 | * When guaranteed is set, Curator will record failed node deletions and 33 | * attempt to delete them in the background until successful. NOTE: you will still get an 34 | * exception when the deletion fails. But, you can be assured that as long as the 35 | * {@link CuratorFramework} instance is open attempts will be made to delete the node. 36 | *

37 | * 38 | * @return this 39 | */ 40 | public DeleteBuilderBase guaranteed(); 41 | } 42 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/main/java/com/netflix/curator/x/discovery/server/contexts/MapDiscoveryContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.server.contexts; 20 | 21 | import com.google.inject.TypeLiteral; 22 | import com.netflix.curator.x.discovery.ProviderStrategy; 23 | import com.netflix.curator.x.discovery.ServiceDiscovery; 24 | import com.netflix.curator.x.discovery.server.rest.DiscoveryContext; 25 | import javax.ws.rs.ext.ContextResolver; 26 | import javax.ws.rs.ext.Provider; 27 | import java.util.Map; 28 | 29 | /** 30 | * For convenience, a version of {@link DiscoveryContext} that uses a String-to-String map as the 31 | * payload 32 | */ 33 | @Provider 34 | public class MapDiscoveryContext extends GenericDiscoveryContext> implements ContextResolver>> 35 | { 36 | public MapDiscoveryContext(ServiceDiscovery> serviceDiscovery, ProviderStrategy> providerStrategy, int instanceRefreshMs) 37 | { 38 | super(serviceDiscovery, providerStrategy, instanceRefreshMs, new TypeLiteral>(){}); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/test/java/com/netflix/curator/x/discovery/server/jetty_resteasy/StringDiscoveryResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.server.jetty_resteasy; 20 | 21 | import com.netflix.curator.x.discovery.server.rest.DiscoveryContext; 22 | import com.netflix.curator.x.discovery.server.rest.DiscoveryResource; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.core.Context; 25 | import javax.ws.rs.core.MediaType; 26 | import javax.ws.rs.ext.ContextResolver; 27 | import javax.ws.rs.ext.Providers; 28 | 29 | @Path("/") 30 | public class StringDiscoveryResource extends DiscoveryResource 31 | { 32 | public StringDiscoveryResource(@Context Providers providers) 33 | { 34 | super(getContextFromProvider(providers)); 35 | } 36 | 37 | private static DiscoveryContext getContextFromProvider(Providers providers) 38 | { 39 | ContextResolver contextResolver = providers.getContextResolver(DiscoveryContext.class, MediaType.WILDCARD_TYPE); 40 | //noinspection unchecked 41 | return contextResolver.getContext(DiscoveryContext.class); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/strategies/RoundRobinStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.strategies; 20 | 21 | import com.netflix.curator.x.discovery.details.InstanceProvider; 22 | import com.netflix.curator.x.discovery.ProviderStrategy; 23 | import com.netflix.curator.x.discovery.ServiceInstance; 24 | import java.util.List; 25 | import java.util.concurrent.atomic.AtomicInteger; 26 | 27 | /** 28 | * This strategy rotates sequentially through the list of instances 29 | */ 30 | public class RoundRobinStrategy implements ProviderStrategy 31 | { 32 | private final AtomicInteger index = new AtomicInteger(0); 33 | 34 | @Override 35 | public ServiceInstance getInstance(InstanceProvider instanceProvider) throws Exception 36 | { 37 | List> instances = instanceProvider.getInstances(); 38 | if ( instances.size() == 0 ) 39 | { 40 | return null; 41 | } 42 | int thisIndex = Math.abs(index.getAndIncrement()); 43 | return instances.get(thisIndex % instances.size()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/locks/Revoker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.locks; 18 | 19 | import com.netflix.curator.framework.CuratorFramework; 20 | import org.apache.zookeeper.KeeperException; 21 | 22 | public class Revoker 23 | { 24 | /** 25 | * Utility to mark a lock for revocation. Assuming that the lock has been registered with 26 | * a {@link RevocationListener}, it will get called and the lock should be released. Note, 27 | * however, that revocation is cooperative. 28 | * 29 | * @param client the client 30 | * @param path the path of the lock - usually from something like 31 | * {@link InterProcessMutex#getParticipantNodes()} 32 | * @throws Exception errors 33 | */ 34 | public static void attemptRevoke(CuratorFramework client, String path) throws Exception 35 | { 36 | try 37 | { 38 | client.setData().forPath(path, LockInternals.REVOKE_MESSAGE); 39 | } 40 | catch ( KeeperException.NoNodeException ignore ) 41 | { 42 | // ignore 43 | } 44 | } 45 | 46 | private Revoker() 47 | { 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/test/java/com/netflix/curator/x/discovery/server/jetty_jersey/ServiceDetailsDiscoveryContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.server.jetty_jersey; 20 | 21 | import javax.ws.rs.ext.ContextResolver; 22 | import javax.ws.rs.ext.Provider; 23 | 24 | import com.netflix.curator.x.discovery.ProviderStrategy; 25 | import com.netflix.curator.x.discovery.ServiceDiscovery; 26 | import com.netflix.curator.x.discovery.server.contexts.GenericDiscoveryContext; 27 | import com.netflix.curator.x.discovery.server.rest.DiscoveryContext; 28 | 29 | /** 30 | * A DiscoveryContext that maps a concrete payload object of ServiceDetails 31 | */ 32 | @Provider 33 | public class ServiceDetailsDiscoveryContext extends GenericDiscoveryContext implements DiscoveryContext, ContextResolver> 34 | { 35 | public ServiceDetailsDiscoveryContext(ServiceDiscovery serviceDiscovery, ProviderStrategy providerStrategy, int instanceRefreshMs) 36 | { 37 | super(serviceDiscovery, providerStrategy, instanceRefreshMs, ServiceDetails.class); 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /curator-x-zkclient-bridge/src/test/java/org/I0Itec/zkclient/MemoryZkClientTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.I0Itec.zkclient; 17 | 18 | import org.apache.zookeeper.CreateMode; 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | 22 | public class MemoryZkClientTest extends AbstractBaseZkClientTest { 23 | 24 | @Override 25 | public void setUp() throws Exception { 26 | super.setUp(); 27 | _client = new ZkClient(new InMemoryConnection()); 28 | } 29 | 30 | @Override 31 | public void tearDown() throws Exception { 32 | super.tearDown(); 33 | _client.close(); 34 | } 35 | 36 | @Test 37 | public void testGetChildren() throws Exception { 38 | String path1 = "/a"; 39 | String path2 = "/a/a"; 40 | String path3 = "/a/a/a"; 41 | 42 | _client.create(path1, null, CreateMode.PERSISTENT); 43 | _client.create(path2, null, CreateMode.PERSISTENT); 44 | _client.create(path3, null, CreateMode.PERSISTENT); 45 | Assert.assertEquals(1, _client.getChildren(path1).size()); 46 | Assert.assertEquals(1, _client.getChildren(path2).size()); 47 | Assert.assertEquals(0, _client.getChildren(path3).size()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/ensemble/fixed/FixedEnsembleProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.ensemble.fixed; 20 | 21 | import com.google.common.base.Preconditions; 22 | import com.netflix.curator.ensemble.EnsembleProvider; 23 | import java.io.IOException; 24 | 25 | /** 26 | * Standard ensemble provider that wraps a fixed connection string 27 | */ 28 | public class FixedEnsembleProvider implements EnsembleProvider 29 | { 30 | private final String connectionString; 31 | 32 | /** 33 | * The connection string to use 34 | * 35 | * @param connectionString connection string 36 | */ 37 | public FixedEnsembleProvider(String connectionString) 38 | { 39 | this.connectionString = Preconditions.checkNotNull(connectionString, "connectionString cannot be null"); 40 | } 41 | 42 | @Override 43 | public void start() throws Exception 44 | { 45 | // NOP 46 | } 47 | 48 | @Override 49 | public void close() throws IOException 50 | { 51 | // NOP 52 | } 53 | 54 | @Override 55 | public String getConnectionString() 56 | { 57 | return connectionString; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/cache/PathChildrenCacheMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.cache; 18 | 19 | import com.netflix.curator.framework.CuratorFramework; 20 | import java.util.concurrent.ThreadFactory; 21 | 22 | /** 23 | * Controls which data is cached 24 | * 25 | * @deprecated no longer used. Instead use either {@link PathChildrenCache#PathChildrenCache(CuratorFramework, String, boolean)} 26 | * or {@link PathChildrenCache#PathChildrenCache(CuratorFramework, String, boolean, ThreadFactory)} 27 | */ 28 | public enum PathChildrenCacheMode 29 | { 30 | /** 31 | * The cache will hold all the children, the data for each child node 32 | * and the stat for each child node 33 | */ 34 | CACHE_DATA_AND_STAT, 35 | 36 | /** 37 | * The cache will hold all the children and the data for each child node. 38 | * {@link ChildData#getStat()} will return null. 39 | */ 40 | CACHE_DATA, 41 | 42 | /** 43 | * The cache will hold only the children path names. 44 | * {@link ChildData#getStat()} and {@link ChildData#getData()} will both return null. 45 | */ 46 | CACHE_PATHS_ONLY 47 | } 48 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/retry/SleepingRetry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.retry; 19 | 20 | import com.netflix.curator.RetryPolicy; 21 | import com.netflix.curator.RetrySleeper; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | abstract class SleepingRetry implements RetryPolicy 25 | { 26 | private final int n; 27 | 28 | protected SleepingRetry(int n) 29 | { 30 | this.n = n; 31 | } 32 | 33 | // made public for testing 34 | public int getN() 35 | { 36 | return n; 37 | } 38 | 39 | public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper) 40 | { 41 | if ( retryCount < n ) 42 | { 43 | try 44 | { 45 | sleeper.sleepFor(getSleepTimeMs(retryCount, elapsedTimeMs), TimeUnit.MILLISECONDS); 46 | } 47 | catch ( InterruptedException e ) 48 | { 49 | Thread.currentThread().interrupt(); 50 | return false; 51 | } 52 | return true; 53 | } 54 | return false; 55 | } 56 | 57 | protected abstract int getSleepTimeMs(int retryCount, long elapsedTimeMs); 58 | } 59 | -------------------------------------------------------------------------------- /curator-recipes/src/test/java/com/netflix/curator/framework/recipes/queue/TestQueueItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.netflix.curator.framework.recipes.queue; 17 | 18 | class TestQueueItem implements Comparable 19 | { 20 | final String str; 21 | 22 | TestQueueItem(String str) 23 | { 24 | this.str = str; 25 | } 26 | 27 | @Override 28 | public int compareTo(TestQueueItem rhs) 29 | { 30 | if ( this == rhs ) 31 | { 32 | return 0; 33 | } 34 | 35 | int val = Integer.parseInt(str); 36 | int rhsVal = Integer.parseInt(rhs.str); 37 | int diff = val - rhsVal; 38 | return (diff < 0) ? -1 : ((diff > 0) ? 1 : 0); 39 | } 40 | 41 | @Override 42 | public boolean equals(Object o) 43 | { 44 | if ( this == o ) 45 | { 46 | return true; 47 | } 48 | if ( o == null || getClass() != o.getClass() ) 49 | { 50 | return false; 51 | } 52 | 53 | TestQueueItem that = (TestQueueItem)o; 54 | 55 | return str.equals(that.str); 56 | 57 | } 58 | 59 | @Override 60 | public int hashCode() 61 | { 62 | return str.hashCode(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/imps/Watching.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.imps; 19 | 20 | import com.netflix.curator.framework.api.CuratorWatcher; 21 | import org.apache.zookeeper.Watcher; 22 | 23 | class Watching 24 | { 25 | private final Watcher watcher; 26 | private final boolean watched; 27 | 28 | Watching(boolean watched) 29 | { 30 | this.watcher = null; 31 | this.watched = watched; 32 | } 33 | 34 | Watching(CuratorFrameworkImpl client, Watcher watcher) 35 | { 36 | this.watcher = (watcher != null) ? client.getNamespaceWatcherMap().getNamespaceWatcher(watcher) : null; 37 | this.watched = false; 38 | } 39 | 40 | Watching(CuratorFrameworkImpl client, CuratorWatcher watcher) 41 | { 42 | this.watcher = (watcher != null) ? client.getNamespaceWatcherMap().getNamespaceWatcher(watcher) : null; 43 | this.watched = false; 44 | } 45 | 46 | Watching() 47 | { 48 | watcher = null; 49 | watched = false; 50 | } 51 | 52 | Watcher getWatcher() 53 | { 54 | return watcher; 55 | } 56 | 57 | boolean isWatched() 58 | { 59 | return watched; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /curator-test/src/main/java/com/netflix/curator/test/DirectoryUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.test; 20 | 21 | import com.google.common.base.Preconditions; 22 | import java.io.File; 23 | import java.io.IOException; 24 | 25 | // copied from Google Guava as these methods are now deprecated 26 | // NOTE: removed the line of code documented: Symbolic links will have different canonical and absolute paths 27 | public class DirectoryUtils 28 | { 29 | public static void deleteRecursively(File file) throws IOException 30 | { 31 | if (file.isDirectory()) { 32 | deleteDirectoryContents(file); 33 | } 34 | if (!file.delete()) { 35 | throw new IOException("Failed to delete " + file); 36 | } 37 | } 38 | 39 | public static void deleteDirectoryContents(File directory) 40 | throws IOException { 41 | Preconditions.checkArgument(directory.isDirectory(), 42 | "Not a directory: %s", directory); 43 | File[] files = directory.listFiles(); 44 | if (files == null) { 45 | throw new IOException("Error listing files for " + directory); 46 | } 47 | for (File file : files) { 48 | deleteRecursively(file); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/retry/BoundedExponentialBackoffRetry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2012 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.retry; 19 | 20 | import com.google.common.annotations.VisibleForTesting; 21 | 22 | /** 23 | * Retry policy that retries a set number of times with an increasing (up to a maximum bound) sleep time between retries 24 | */ 25 | public class BoundedExponentialBackoffRetry extends ExponentialBackoffRetry 26 | { 27 | private final int maxSleepTimeMs; 28 | 29 | /** 30 | * @param baseSleepTimeMs initial amount of time to wait between retries 31 | * @param maxSleepTimeMs maximum amount of time to wait between retries 32 | * @param maxRetries maximum number of times to retry 33 | */ 34 | public BoundedExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepTimeMs, int maxRetries) 35 | { 36 | super(baseSleepTimeMs, maxRetries); 37 | this.maxSleepTimeMs = maxSleepTimeMs; 38 | } 39 | 40 | @VisibleForTesting 41 | public int getMaxSleepTimeMs() 42 | { 43 | return maxSleepTimeMs; 44 | } 45 | 46 | @Override 47 | protected int getSleepTimeMs(int retryCount, long elapsedTimeMs) 48 | { 49 | return Math.min(maxSleepTimeMs, super.getSleepTimeMs(retryCount, elapsedTimeMs)); 50 | } 51 | } -------------------------------------------------------------------------------- /curator-client/src/main/java/com/netflix/curator/ensemble/EnsembleProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.ensemble; 20 | 21 | import com.netflix.curator.CuratorZookeeperClient; 22 | import org.apache.zookeeper.Watcher; 23 | import org.apache.zookeeper.ZooKeeper; 24 | import java.io.Closeable; 25 | import java.io.IOException; 26 | 27 | /** 28 | * Abstraction that provides the ZooKeeper connection string 29 | */ 30 | public interface EnsembleProvider extends Closeable 31 | { 32 | /** 33 | * Curator will call this method when {@link CuratorZookeeperClient#start()} is 34 | * called 35 | * 36 | * @throws Exception errors 37 | */ 38 | public void start() throws Exception; 39 | 40 | /** 41 | * Return the current connection string to use. Curator will call this each 42 | * time it needs to create a ZooKeeper instance 43 | * 44 | * @return connection string (per {@link ZooKeeper#ZooKeeper(String, int, Watcher)} etc.) 45 | */ 46 | public String getConnectionString(); 47 | 48 | /** 49 | * Curator will call this method when {@link CuratorZookeeperClient#close()} is called 50 | * 51 | * @throws IOException errors 52 | */ 53 | public void close() throws IOException; 54 | } 55 | -------------------------------------------------------------------------------- /curator-x-discovery-server/src/test/java/com/netflix/curator/x/discovery/server/jetty_resteasy/RestEasyApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.x.discovery.server.jetty_resteasy; 20 | 21 | import com.google.common.collect.Sets; 22 | import javax.ws.rs.core.Application; 23 | import java.util.Set; 24 | import java.util.concurrent.atomic.AtomicReference; 25 | 26 | public class RestEasyApplication extends Application 27 | { 28 | public static final AtomicReference singletonsRef = new AtomicReference(new RestEasySingletons()); 29 | 30 | @Override 31 | public Set> getClasses() 32 | { 33 | Set> classes = Sets.newHashSet(); 34 | classes.add(StringDiscoveryResource.class); 35 | return classes; 36 | } 37 | 38 | @Override 39 | public Set getSingletons() 40 | { 41 | Set singletons = Sets.newHashSet(); 42 | singletons.add(singletonsRef.get().contextSingleton); 43 | singletons.add(singletonsRef.get().serviceNamesMarshallerSingleton); 44 | singletons.add(singletonsRef.get().serviceInstanceMarshallerSingleton); 45 | singletons.add(singletonsRef.get().serviceInstancesMarshallerSingleton); 46 | return singletons; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/queue/QueueSafety.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.queue; 18 | 19 | import java.util.concurrent.BlockingQueue; 20 | 21 | /** 22 | * Parameter block for specifying queue safety with either {@link DistributedQueue} or 23 | * {@link DistributedPriorityQueue} 24 | */ 25 | public class QueueSafety 26 | { 27 | private final String lockPath; 28 | private final QueueConsumer consumer; 29 | private final BlockingQueue queue; 30 | 31 | /** 32 | * @param lockPath ZKPath to use for locking purposes 33 | * @param consumer the message consumer 34 | */ 35 | public QueueSafety(String lockPath, QueueConsumer consumer) 36 | { 37 | this.lockPath = lockPath; 38 | this.consumer = consumer; 39 | this.queue = null; 40 | } 41 | 42 | QueueSafety(String lockPath, BlockingQueue queue) 43 | { 44 | this.lockPath = lockPath; 45 | this.consumer = null; 46 | this.queue = queue; 47 | } 48 | 49 | String getLockPath() 50 | { 51 | return lockPath; 52 | } 53 | 54 | QueueConsumer getConsumer() 55 | { 56 | return consumer; 57 | } 58 | 59 | BlockingQueue getQueue() 60 | { 61 | return queue; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /curator-examples/src/main/java/locking/ExampleClientThatLocks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package locking; 18 | 19 | import com.netflix.curator.framework.CuratorFramework; 20 | import com.netflix.curator.framework.recipes.locks.InterProcessMutex; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | public class ExampleClientThatLocks 24 | { 25 | private final InterProcessMutex lock; 26 | private final FakeLimitedResource resource; 27 | private final String clientName; 28 | 29 | public ExampleClientThatLocks(CuratorFramework client, String lockPath, FakeLimitedResource resource, String clientName) 30 | { 31 | this.resource = resource; 32 | this.clientName = clientName; 33 | lock = new InterProcessMutex(client, lockPath); 34 | } 35 | 36 | public void doWork(long time, TimeUnit unit) throws Exception 37 | { 38 | if ( !lock.acquire(time, unit) ) 39 | { 40 | throw new IllegalStateException(clientName + " could not acquire the lock"); 41 | } 42 | try 43 | { 44 | System.out.println(clientName + " has the lock"); 45 | resource.use(); 46 | } 47 | finally 48 | { 49 | System.out.println(clientName + " releasing the lock"); 50 | lock.release(); // always release the lock in a finally block 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/cache/RefreshOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.cache; 18 | 19 | class RefreshOperation implements Operation 20 | { 21 | private final PathChildrenCache cache; 22 | private final PathChildrenCache.RefreshMode mode; 23 | 24 | RefreshOperation(PathChildrenCache cache, PathChildrenCache.RefreshMode mode) 25 | { 26 | this.cache = cache; 27 | this.mode = mode; 28 | } 29 | 30 | @Override 31 | public void invoke() throws Exception 32 | { 33 | cache.refresh(mode); 34 | } 35 | 36 | @Override 37 | public boolean equals(Object o) 38 | { 39 | if ( this == o ) 40 | { 41 | return true; 42 | } 43 | if ( o == null || getClass() != o.getClass() ) 44 | { 45 | return false; 46 | } 47 | 48 | RefreshOperation that = (RefreshOperation)o; 49 | 50 | //noinspection RedundantIfStatement 51 | if ( mode != that.mode ) 52 | { 53 | return false; 54 | } 55 | 56 | return true; 57 | } 58 | 59 | @Override 60 | public int hashCode() 61 | { 62 | return mode.hashCode(); 63 | } 64 | 65 | @Override 66 | public String toString() 67 | { 68 | return "RefreshOperation(" + mode + "){}"; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/imps/CuratorMultiTransactionRecord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.netflix.curator.framework.imps; 20 | 21 | import com.google.common.collect.Lists; 22 | import com.netflix.curator.framework.api.transaction.OperationType; 23 | import org.apache.zookeeper.MultiTransactionRecord; 24 | import org.apache.zookeeper.Op; 25 | import java.util.List; 26 | 27 | class CuratorMultiTransactionRecord extends MultiTransactionRecord 28 | { 29 | private final List metadata = Lists.newArrayList(); 30 | 31 | static class TypeAndPath 32 | { 33 | final OperationType type; 34 | final String forPath; 35 | 36 | TypeAndPath(OperationType type, String forPath) 37 | { 38 | this.type = type; 39 | this.forPath = forPath; 40 | } 41 | } 42 | 43 | @Override 44 | public final void add(Op op) 45 | { 46 | throw new UnsupportedOperationException(); 47 | } 48 | 49 | void add(Op op, OperationType type, String forPath) 50 | { 51 | super.add(op); 52 | metadata.add(new TypeAndPath(type, forPath)); 53 | } 54 | 55 | TypeAndPath getMetadata(int index) 56 | { 57 | return metadata.get(index); 58 | } 59 | 60 | int metadataSize() 61 | { 62 | return metadata.size(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/imps/ACLing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.imps; 19 | 20 | import com.google.common.collect.ImmutableList; 21 | import com.netflix.curator.framework.api.ACLProvider; 22 | import org.apache.zookeeper.data.ACL; 23 | import java.util.List; 24 | 25 | class ACLing 26 | { 27 | private final List aclList; 28 | private final ACLProvider aclProvider; 29 | 30 | ACLing(ACLProvider aclProvider) 31 | { 32 | this(aclProvider, null); 33 | } 34 | 35 | ACLing(ACLProvider aclProvider, List aclList) 36 | { 37 | this.aclProvider = aclProvider; 38 | this.aclList = (aclList != null) ? ImmutableList.copyOf(aclList) : null; 39 | } 40 | 41 | List getAclList(String path) 42 | { 43 | List localAclList = aclList; 44 | do 45 | { 46 | if ( localAclList != null ) 47 | { 48 | break; 49 | } 50 | 51 | if ( path != null ) 52 | { 53 | localAclList = aclProvider.getAclForPath(path); 54 | if ( localAclList != null ) 55 | { 56 | break; 57 | } 58 | } 59 | 60 | localAclList = aclProvider.getDefaultAcl(); 61 | } while ( false ); 62 | return localAclList; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /curator-framework/src/main/java/com/netflix/curator/framework/api/CuratorEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2011 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package com.netflix.curator.framework.api; 19 | 20 | import com.netflix.curator.framework.CuratorFramework; 21 | import org.apache.zookeeper.Watcher; 22 | 23 | public enum CuratorEventType 24 | { 25 | /** 26 | * Corresponds to {@link CuratorFramework#create()} 27 | */ 28 | CREATE, 29 | 30 | /** 31 | * Corresponds to {@link CuratorFramework#delete()} 32 | */ 33 | DELETE, 34 | 35 | /** 36 | * Corresponds to {@link CuratorFramework#checkExists()} 37 | */ 38 | EXISTS, 39 | 40 | /** 41 | * Corresponds to {@link CuratorFramework#getData()} 42 | */ 43 | GET_DATA, 44 | 45 | /** 46 | * Corresponds to {@link CuratorFramework#setData()} 47 | */ 48 | SET_DATA, 49 | 50 | /** 51 | * Corresponds to {@link CuratorFramework#getChildren()} 52 | */ 53 | CHILDREN, 54 | 55 | /** 56 | * Corresponds to {@link CuratorFramework#sync(String, Object)} 57 | */ 58 | SYNC, 59 | 60 | /** 61 | * Corresponds to {@link CuratorFramework#getACL()} 62 | */ 63 | GET_ACL, 64 | 65 | /** 66 | * Corresponds to {@link Watchable#usingWatcher(Watcher)} or {@link Watchable#watched()} 67 | */ 68 | WATCHED, 69 | 70 | /** 71 | * Event sent when client is being closed 72 | */ 73 | CLOSING 74 | } 75 | -------------------------------------------------------------------------------- /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/cache/GetDataOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.netflix.curator.framework.recipes.cache; 18 | 19 | class GetDataOperation implements Operation 20 | { 21 | private final PathChildrenCache cache; 22 | private final String fullPath; 23 | 24 | GetDataOperation(PathChildrenCache cache, String fullPath) 25 | { 26 | this.cache = cache; 27 | this.fullPath = fullPath; 28 | } 29 | 30 | @Override 31 | public void invoke() throws Exception 32 | { 33 | cache.getDataAndStat(fullPath); 34 | } 35 | 36 | @Override 37 | public boolean equals(Object o) 38 | { 39 | if ( this == o ) 40 | { 41 | return true; 42 | } 43 | if ( o == null || getClass() != o.getClass() ) 44 | { 45 | return false; 46 | } 47 | 48 | GetDataOperation that = (GetDataOperation)o; 49 | 50 | //noinspection RedundantIfStatement 51 | if ( !fullPath.equals(that.fullPath) ) 52 | { 53 | return false; 54 | } 55 | 56 | return true; 57 | } 58 | 59 | @Override 60 | public int hashCode() 61 | { 62 | return fullPath.hashCode(); 63 | } 64 | 65 | @Override 66 | public String toString() 67 | { 68 | return "GetDataOperation{" + 69 | "fullPath='" + fullPath + '\'' + 70 | '}'; 71 | } 72 | } 73 | --------------------------------------------------------------------------------