当前位置: 首页>>代码示例>>Java>>正文


Java CuratorEventType类代码示例

本文整理汇总了Java中org.apache.curator.framework.api.CuratorEventType的典型用法代码示例。如果您正苦于以下问题:Java CuratorEventType类的具体用法?Java CuratorEventType怎么用?Java CuratorEventType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CuratorEventType类属于org.apache.curator.framework.api包,在下文中一共展示了CuratorEventType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: delete

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
protected void delete(String path, V v, Handler<AsyncResult<V>> asyncResultHandler) {
  try {
    curator.delete().deletingChildrenIfNeeded().inBackground((client, event) -> {
      if (event.getType() == CuratorEventType.DELETE) {
        curator.getChildren().inBackground((childClient, childEvent) -> {
          //clean parent node if doesn't have child node.
          if (childEvent.getChildren().size() == 0) {
            String[] paths = path.split("/");
            String parentNodePath = Stream.of(paths).limit(paths.length - 1).reduce((previous, current) -> previous + "/" + current).get();
            curator.delete().inBackground((deleteClient, deleteEvent) -> {
              if (deleteEvent.getType() == CuratorEventType.DELETE)
                vertx.runOnContext(ea -> asyncResultHandler.handle(Future.succeededFuture(v)));
            }).forPath(parentNodePath);
          } else {
            vertx.runOnContext(ea -> asyncResultHandler.handle(Future.succeededFuture(v)));
          }
        }).forPath(path);
      }
    }).forPath(path);
  } catch (Exception ex) {
    vertx.runOnContext(aVoid -> asyncResultHandler.handle(Future.failedFuture(ex)));
  }
}
 
开发者ID:IBYoung,项目名称:vert.3x-gateway,代码行数:24,代码来源:ZKMap.java

示例2: leave

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
@Override
public synchronized void leave(Handler<AsyncResult<Void>> resultHandler) {
  vertx.executeBlocking(future -> {
    if (active) {
      active = false;
      try {
        curator.delete().deletingChildrenIfNeeded().inBackground((client, event) -> {
          if (event.getType() == CuratorEventType.DELETE) {
            clusterNodes.getListenable().removeListener(ZookeeperClusterManager.this);
          }
        }).forPath(ZK_PATH_CLUSTER_NODE + nodeID);
      } catch (Exception e) {
        log.error(e);
      }
    }
    future.complete();
  }, resultHandler);
}
 
开发者ID:IBYoung,项目名称:vert.3x-gateway,代码行数:19,代码来源:ZookeeperClusterManager.java

示例3: performBackgroundOperation

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
@Override
public void performBackgroundOperation(final OperationAndData<CuratorMultiTransactionRecord> operationAndData) throws Exception
{
    try
    {
        final TimeTrace trace = client.getZookeeperClient().startTracer("CuratorMultiTransactionImpl-Background");
        AsyncCallback.MultiCallback callback = new AsyncCallback.MultiCallback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx, List<OpResult> opResults)
            {
                trace.commit();
                List<CuratorTransactionResult> curatorResults = (opResults != null) ? CuratorTransactionImpl.wrapResults(client, opResults, operationAndData.getData()) : null;
                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.TRANSACTION, rc, path, null, ctx, null, null, null, null, null, curatorResults);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        client.getZooKeeper().multi(operationAndData.getData(), callback, backgrounding.getContext());
    }
    catch ( Throwable e )
    {
        backgrounding.checkError(e, null);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:25,代码来源:CuratorMultiTransactionImpl.java

示例4: performBackgroundOperation

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception
{
    final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("BackgroundSyncImpl");
    final String data = operationAndData.getData();
    client.getZooKeeper().sync
    (
        data,
        new AsyncCallback.VoidCallback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx)
            {
                trace.setReturnCode(rc).setRequestBytesLength(data).commit();
                CuratorEventImpl event = new CuratorEventImpl(client, CuratorEventType.SYNC, rc, path, null, ctx, null, null, null, null, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        },
        context
    );
}
 
开发者ID:apache,项目名称:curator,代码行数:22,代码来源:BackgroundSyncImpl.java

示例5: performBackgroundOperation

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception
{
    try
    {
        final OperationTrace             trace = client.getZookeeperClient().startAdvancedTracer("GetACLBuilderImpl-Background");
        AsyncCallback.ACLCallback   callback = new AsyncCallback.ACLCallback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx, List<ACL> acl, Stat stat)
            {
                trace.setReturnCode(rc).setPath(path).setStat(stat).commit();
                CuratorEventImpl event = new CuratorEventImpl(client, CuratorEventType.GET_ACL, rc, path, null, ctx, stat, null, null, null, acl, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        client.getZooKeeper().getACL(operationAndData.getData(), responseStat, callback, backgrounding.getContext());
    }
    catch ( Throwable e )
    {
        backgrounding.checkError(e, null);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:GetACLBuilderImpl.java

示例6: processResult

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
@Override
public synchronized void processResult(CuratorFramework client,
		CuratorEvent event) throws Exception {
	if (event.getType().equals(CuratorEventType.CHILDREN)
			|| event.getType().equals(CuratorEventType.CREATE)
			|| event.getType().equals(CuratorEventType.DELETE)) {
		attach();
	}

}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:11,代码来源:ZGroup.java

示例7: checkExists

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
protected void checkExists(String path, AsyncResultHandler<Boolean> handler) {
  try {
    curator.checkExists().inBackground((client, event) -> {
      if (event.getType() == CuratorEventType.EXISTS) {
        if (event.getStat() == null) {
          vertx.runOnContext(aVoid -> handler.handle(Future.succeededFuture(false)));
        } else {
          vertx.runOnContext(aVoid -> handler.handle(Future.succeededFuture(true)));
        }
      }
    }).forPath(path);
  } catch (Exception ex) {
    vertx.runOnContext(aVoid -> handler.handle(Future.failedFuture(ex)));
  }
}
 
开发者ID:IBYoung,项目名称:vert.3x-gateway,代码行数:16,代码来源:ZKMap.java

示例8: create

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
protected void create(String path, V v, Handler<AsyncResult<Void>> completionHandler) {
  try {
    //there are two type of node - ephemeral and persistent.
    //if path is 'asyncMultiMap/subs/' which save the data of eventbus address and serverID we could using ephemeral,
    //since the lifecycle of this path as long as this verticle.
    CreateMode nodeMode = path.contains(EVENTBUS_PATH) ? CreateMode.EPHEMERAL : CreateMode.PERSISTENT;
    curator.create().creatingParentsIfNeeded().withMode(nodeMode).inBackground((cl, el) -> {
      if (el.getType() == CuratorEventType.CREATE) {
        vertx.runOnContext(event -> completionHandler.handle(Future.succeededFuture()));
      }
    }).forPath(path, asByte(v));
  } catch (Exception ex) {
    vertx.runOnContext(event -> completionHandler.handle(Future.failedFuture(ex)));
  }
}
 
开发者ID:IBYoung,项目名称:vert.3x-gateway,代码行数:16,代码来源:ZKMap.java

示例9: setData

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
protected void setData(String path, V v, Handler<AsyncResult<Void>> completionHandler) {
  try {
    curator.setData().inBackground((client, event) -> {
      if (event.getType() == CuratorEventType.SET_DATA) {
        vertx.runOnContext(e -> completionHandler.handle(Future.succeededFuture()));
      }
    }).forPath(path, asByte(v));
  } catch (Exception ex) {
    vertx.runOnContext(event -> completionHandler.handle(Future.failedFuture(ex)));
  }
}
 
开发者ID:IBYoung,项目名称:vert.3x-gateway,代码行数:12,代码来源:ZKMap.java

示例10: mkClient

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
/**
 * connect ZK, register Watch/unhandle Watch
 * 
 * @return
 */
public CuratorFramework mkClient(Map conf, List<String> servers,
		Object port, String root, final WatcherCallBack watcher) {

	CuratorFramework fk = Utils.newCurator(conf, servers, port, root);

	fk.getCuratorListenable().addListener(new CuratorListener() {
		@Override
		public void eventReceived(CuratorFramework _fk, CuratorEvent e)
				throws Exception {
			if (e.getType().equals(CuratorEventType.WATCHED)) {
				WatchedEvent event = e.getWatchedEvent();

				watcher.execute(event.getState(), event.getType(),
						event.getPath());
			}

		}
	});

	fk.getUnhandledErrorListenable().addListener(
			new UnhandledErrorListener() {
				@Override
				public void unhandledError(String msg, Throwable error) {
					String errmsg = "Unrecoverable Zookeeper error, halting process: "
							+ msg;
					LOG.error(errmsg, error);
					JStormUtils.halt_process(1,
							"Unrecoverable Zookeeper error");

				}
			});
	fk.start();
	return fk;
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:40,代码来源:Zookeeper.java

示例11: mkClient

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
/**
 * connect ZK, register Watch/unhandle Watch
 * 
 * @return
 */
public CuratorFramework mkClient(Map conf, List<String> servers, Object port, String root, final WatcherCallBack watcher) {

    CuratorFramework fk = Utils.newCurator(conf, servers, port, root);

    fk.getCuratorListenable().addListener(new CuratorListener() {
        @Override
        public void eventReceived(CuratorFramework _fk, CuratorEvent e) throws Exception {
            if (e.getType().equals(CuratorEventType.WATCHED)) {
                WatchedEvent event = e.getWatchedEvent();

                watcher.execute(event.getState(), event.getType(), event.getPath());
            }

        }
    });

    fk.getUnhandledErrorListenable().addListener(new UnhandledErrorListener() {
        @Override
        public void unhandledError(String msg, Throwable error) {
            String errmsg = "Unrecoverable Zookeeper error, halting process: " + msg;
            LOG.error(errmsg, error);
            JStormUtils.halt_process(1, "Unrecoverable Zookeeper error");

        }
    });
    fk.start();
    return fk;
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:34,代码来源:Zookeeper.java

示例12: processResult

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void processResult(CuratorFramework curatorFramework, CuratorEvent event)
        throws Exception {
    CuratorEventType eventType = event.getType();
    switch (eventType) {
    case CHILDREN:
        break;
    case CLOSING:
        break;
    case CREATE:
        _invalidateCache(event.getPath());
        break;
    case DELETE:
        _invalidateCache(event.getPath());
        break;
    case EXISTS:
        break;
    case GET_ACL:
        break;
    case GET_DATA:
        break;
    case SET_ACL:
        break;
    case SET_DATA:
        break;
    case SYNC:
        break;
    case WATCHED:
        process(event.getWatchedEvent());
        break;
    default:
        LOGGER.debug(event.toString());
        break;
    }
}
 
开发者ID:DDTH,项目名称:ddth-zookeeper,代码行数:39,代码来源:ZooKeeperClient.java

示例13: CuratorEventImpl

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
CuratorEventImpl(CuratorFrameworkImpl client, CuratorEventType type, int resultCode, String path, String name, Object context, Stat stat, byte[] data, List<String> children, WatchedEvent watchedEvent, List<ACL> aclList, List<CuratorTransactionResult> opResults)
{
    this.type = type;
    this.resultCode = resultCode;
    this.opResults = (opResults != null) ? ImmutableList.copyOf(opResults) : null;
    this.path = client.unfixForNamespace(path);
    this.name = name;
    this.context = context;
    this.stat = stat;
    this.data = data;
    this.children = children;
    this.watchedEvent = (watchedEvent != null) ? new NamespaceWatchedEvent(client, watchedEvent) : null;
    this.aclList = (aclList != null) ? ImmutableList.copyOf(aclList) : null;
}
 
开发者ID:apache,项目名称:curator,代码行数:15,代码来源:CuratorEventImpl.java

示例14: performBackgroundOperation

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception
{
    try
    {
        final OperationTrace       trace = client.getZookeeperClient().startAdvancedTracer("GetChildrenBuilderImpl-Background");
        AsyncCallback.Children2Callback callback = new AsyncCallback.Children2Callback()
        {
            @Override
            public void processResult(int rc, String path, Object o, List<String> strings, Stat stat)
            {
                watching.commitWatcher(rc, false);
                trace.setReturnCode(rc).setPath(path).setWithWatcher(watching.hasWatcher()).setStat(stat).commit();
                if ( strings == null )
                {
                    strings = Lists.newArrayList();
                }
                CuratorEventImpl event = new CuratorEventImpl(client, CuratorEventType.CHILDREN, rc, path, null, o, stat, null, strings, null, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        if ( watching.isWatched() )
        {
            client.getZooKeeper().getChildren(operationAndData.getData(), true, callback, backgrounding.getContext());
        }
        else
        {
            client.getZooKeeper().getChildren(operationAndData.getData(), watching.getWatcher(operationAndData.getData()), callback, backgrounding.getContext());
        }
    }
    catch ( Throwable e )
    {
        backgrounding.checkError(e, watching);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:36,代码来源:GetChildrenBuilderImpl.java

示例15: testBackgroundDeleteWithChildren

import org.apache.curator.framework.api.CuratorEventType; //导入依赖的package包/类
@Test
public void testBackgroundDeleteWithChildren() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();
    try
    {
        client.getCuratorListenable().addListener
            ((client1, event) ->
            {
                if ( event.getType() == CuratorEventType.DELETE )
                {
                    Assert.assertEquals(event.getPath(), "/one/two");
                    ((CountDownLatch)event.getContext()).countDown();
                }
            });

        CountDownLatch latch = new CountDownLatch(1);
        AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
        async.create().withOptions(EnumSet.of(CreateOption.createParentsIfNeeded)).forPath("/one/two/three/four").thenRun(() ->
            async.delete().withOptions(EnumSet.of(DeleteOption.deletingChildrenIfNeeded)).forPath("/one/two").handle((v, e) -> {
                Assert.assertNull(v);
                Assert.assertNull(e);
                latch.countDown();
                return null;
            })
        );
        Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
        Assert.assertNull(client.checkExists().forPath("/one/two"));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:36,代码来源:TestFramework.java


注:本文中的org.apache.curator.framework.api.CuratorEventType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。