You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2019/10/14 13:34:23 UTC
[curator] 04/05: Added support for a PersistentWatcher recipe based
on new persistent watch APIs
This is an automated email from the ASF dual-hosted git repository.
randgalt pushed a commit to branch persistent-watcher-cache
in repository https://gitbox.apache.org/repos/asf/curator.git
commit d8eac95a676d1f217755284c8bbb3c189960cf6d
Author: randgalt <ra...@apache.org>
AuthorDate: Wed Oct 2 23:24:14 2019 -0500
Added support for a PersistentWatcher recipe based on new persistent watch APIs
---
.../imps/AddPersistentWatchBuilderImpl.java | 169 ---------------------
1 file changed, 169 deletions(-)
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/AddPersistentWatchBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/AddPersistentWatchBuilderImpl.java
deleted file mode 100644
index acb70c8..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/AddPersistentWatchBuilderImpl.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.imps;
-
-import org.apache.curator.RetryLoop;
-import org.apache.curator.drivers.OperationTrace;
-import org.apache.curator.framework.api.AddPersistentWatchBuilder;
-import org.apache.curator.framework.api.AddPersistentWatchBuilder2;
-import org.apache.curator.framework.api.AddPersistentWatchable;
-import org.apache.curator.framework.api.BackgroundCallback;
-import org.apache.curator.framework.api.CuratorEvent;
-import org.apache.curator.framework.api.CuratorEventType;
-import org.apache.curator.framework.api.CuratorWatcher;
-import org.apache.curator.framework.api.Pathable;
-import org.apache.zookeeper.Watcher;
-import java.util.concurrent.Executor;
-
-public class AddPersistentWatchBuilderImpl implements AddPersistentWatchBuilder, Pathable<Void>, BackgroundOperation<String>
-{
- private final CuratorFrameworkImpl client;
- private Watching watching = null;
- private Backgrounding backgrounding = new Backgrounding();
- private boolean recursive = false;
-
- AddPersistentWatchBuilderImpl(CuratorFrameworkImpl client)
- {
- this.client = client;
- }
-
- public AddPersistentWatchBuilderImpl(CuratorFrameworkImpl client, Watching watching, Backgrounding backgrounding, boolean recursive)
- {
- this.client = client;
- this.watching = watching;
- this.backgrounding = backgrounding;
- this.recursive = recursive;
- }
-
- @Override
- public AddPersistentWatchable<Pathable<Void>> inBackground()
- {
- backgrounding = new Backgrounding();
- return this;
- }
-
- @Override
- public AddPersistentWatchBuilder2 recursive()
- {
- recursive = true;
- return this;
- }
-
- @Override
- public Pathable<Void> usingWatcher(Watcher watcher)
- {
- watching = new Watching(client, watcher);
- return this;
- }
-
- @Override
- public Pathable<Void> usingWatcher(CuratorWatcher watcher)
- {
- watching = new Watching(client, watcher);
- return this;
- }
-
- @Override
- public AddPersistentWatchable<Pathable<Void>> inBackground(Object context)
- {
- backgrounding = new Backgrounding(context);
- return this;
- }
-
- @Override
- public AddPersistentWatchable<Pathable<Void>> inBackground(BackgroundCallback callback)
- {
- backgrounding = new Backgrounding(callback);
- return this;
- }
-
- @Override
- public AddPersistentWatchable<Pathable<Void>> inBackground(BackgroundCallback callback, Object context)
- {
- backgrounding = new Backgrounding(callback, context);
- return this;
- }
-
- @Override
- public AddPersistentWatchable<Pathable<Void>> inBackground(BackgroundCallback callback, Executor executor)
- {
- backgrounding = new Backgrounding(callback, executor);
- return this;
- }
-
- @Override
- public AddPersistentWatchable<Pathable<Void>> inBackground(BackgroundCallback callback, Object context, Executor executor)
- {
- backgrounding = new Backgrounding(client, callback, context, executor);
- return this;
- }
-
- @Override
- public Void forPath(String path) throws Exception
- {
- if ( backgrounding.inBackground() )
- {
- client.processBackgroundOperation(new OperationAndData<>(this, path, backgrounding.getCallback(), null, backgrounding.getContext(), watching), null);
- }
- else
- {
- pathInForeground(path);
- }
- return null;
- }
-
- @Override
- public void performBackgroundOperation(final OperationAndData<String> data) throws Exception
- {
- String path = data.getData();
- String fixedPath = client.fixForNamespace(path);
- try
- {
- final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("AddPersistentWatchBuilderImpl-Background");
- client.getZooKeeper().addPersistentWatch
- (
- fixedPath,
- watching.getWatcher(path),
- recursive, (rc, path1, ctx) -> {
- trace.setReturnCode(rc).setWithWatcher(true).setPath(path1).commit();
- CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.ADD_PERSISTENT_WATCH, rc, path1, null, ctx, null, null, null, null, null, null);
- client.processBackgroundOperation(data, event);
- },
- backgrounding.getContext()
- );
- }
- catch ( Throwable e )
- {
- backgrounding.checkError(e, watching);
- }
- }
-
- private void pathInForeground(final String path) throws Exception
- {
- final String fixedPath = client.fixForNamespace(path);
- OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("AddPersistentWatchBuilderImpl-Foreground");
- RetryLoop.callWithRetry
- (
- client.getZookeeperClient(), () -> {
- client.getZooKeeper().addPersistentWatch(fixedPath, watching.getWatcher(path), recursive);
- return null;
- });
- trace.setPath(fixedPath).setWithWatcher(true).commit();
- }
-}
\ No newline at end of file