• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java GetDataBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: readTargetChildsData

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
/**
 * 读取指定节点的子菜单的值
 *
 * @param path
 * @return
 */
public Map<String, String> readTargetChildsData(String path) {
    if (!ObjectUtils.allNotNull(zkClient, path)) {
        return null;
    }
    Map<String, String> map = null;
    try {
        Stat stat = exists(path);
        if (stat != null) {
            List<String> childrens = zkClient.getChildren().forPath(path);
            GetDataBuilder dataBuilder = zkClient.getData();
            if (childrens != null) {
                map = childrens.stream().collect(Collectors.toMap(Function.identity(), (child) -> {
                    try {
                        return new String(dataBuilder.forPath(ZKPaths.makePath(path, child)), Charsets.UTF_8);
                    } catch (Exception e1) {
                        return null;
                    }
                }));
            }
        }
    } catch (Exception e) {
        log.error("get target childs data fail!, path:{} , error:{}", path, e);
    }
    return map;

}
 
开发者ID:lee123lee123,项目名称:GoPush,代码行数:33,代码来源:ZkUtils.java


示例2: load

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
/**
 * 获取指定节点数据
 * @return
 * @throws Exception 
 */
public Object load() throws Exception {
	String name = StringUtils.isBlank(nodeName) ? maker.make() : nodeName;
	if (name == null) return null;
	byte[] data;
	GetDataBuilder builder = client.getData();
	if (watchObj != null) {
		builder.usingWatcher(watchObj);
	}else if (watchBool) {
		builder.watched();
	}
	data = builder.storingStatIn(stat).forPath(name);
	if(debug) {
		log.info("ZooKeeper get data. path: {} --- data: {}", name, data);
	}
	if(deserializer != null) {
		return deserializer.deserialize(data);
	}
	return data;
}
 
开发者ID:easycodebox,项目名称:easycode,代码行数:25,代码来源:CuratorNode.java


示例3: findProperties

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
@Override
public List<PropertyItem> findProperties(String node) {
    LOGGER.debug("Find properties in node: [{}]", node);
    List<PropertyItem> properties = Lists.newArrayList();
    try {
        Stat stat = getClient().checkExists().forPath(node);
        if (stat != null) {
            GetChildrenBuilder childrenBuilder = getClient().getChildren();
            List<String> children = childrenBuilder.forPath(node);
            GetDataBuilder dataBuilder = getClient().getData();
            if (children != null) {
                for (String child : children) {
                    String propPath = ZKPaths.makePath(node, child);
                    PropertyItem item = new PropertyItem(child, new String(dataBuilder.forPath(propPath),
                        Charsets.UTF_8));
                    properties.add(item);
                }
            }
        }
    }
    catch (Exception e) {
        throw Throwables.propagate(e);
    }
    return properties;
}
 
开发者ID:ErinDavid,项目名称:elastic-config,代码行数:26,代码来源:NodeDao.java


示例4: testShouldReturnActiveServerAddress

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
@Test
public void testShouldReturnActiveServerAddress() throws Exception {
    when(curatorFactory.clientInstance()).thenReturn(curatorFramework);
    when(configuration.getString(
            HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
            thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);


    GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
    when(curatorFramework.getData()).thenReturn(getDataBuilder);
    when(getDataBuilder.forPath(getPath())).
            thenReturn(SERVER_ADDRESS.getBytes(Charset.forName("UTF-8")));

    ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
    String actualServerAddress = activeInstanceState.getActiveServerAddress();

    assertEquals(SERVER_ADDRESS, actualServerAddress);
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:19,代码来源:ActiveInstanceStateTest.java


示例5: testShouldHandleExceptionsInFetchingServerAddress

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
@Test
public void testShouldHandleExceptionsInFetchingServerAddress() throws Exception {
    when(curatorFactory.clientInstance()).thenReturn(curatorFramework);
    when(configuration.getString(
            HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
            thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);


    GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
    when(curatorFramework.getData()).thenReturn(getDataBuilder);
    when(getDataBuilder.forPath(getPath())).
            thenThrow(new Exception());

    ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
    assertNull(activeInstanceState.getActiveServerAddress());
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:17,代码来源:ActiveInstanceStateTest.java


示例6: testCanReadFromZookeeper

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
@Test
public void testCanReadFromZookeeper() throws Exception {

    CuratorFramework curatorFramework = mock(CuratorFramework.class);
    ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
    GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
    GetChildrenBuilder getChildrenBuilder = mock(GetChildrenBuilder.class);

    when(getDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot())).thenReturn(mockGlobalData());
    when(curatorFramework.checkExists()).thenReturn(existsBuilder);
    when(curatorFramework.getData()).thenReturn(getDataBuilder);
    when(curatorFramework.getChildren()).thenReturn(getChildrenBuilder);
    when(getChildrenBuilder.forPath(anyString())).thenReturn(Collections.<String> emptyList());

    Configuration configuration = new Configuration(Paths.get("foo"));
    configuration.curatorFramework = curatorFramework;
    configuration.update();

    checkResult(configuration);
}
 
开发者ID:apache,项目名称:metron,代码行数:21,代码来源:ConfigurationTest.java


示例7: loadKey

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
private Pair<String, String> loadKey(final String nodePath) throws Exception {
    final String nodeName = ZKPaths.getNodeFromPath(nodePath);
    final Set<String> keysSpecified = configProfile.getKeysSpecified();
    switch (configProfile.getKeyLoadingMode()) {
        case INCLUDE:
            if (keysSpecified == null || !keysSpecified.contains(nodeName)) {
                return null;
            }
            break;
        case EXCLUDE:
            if (keysSpecified.contains(nodeName)) {
                return null;
            }
            break;
        case ALL:
            break;
        default:
            break;
    }

    final GetDataBuilder data = client.getData();
    final String value = new String(data.watched().forPath(nodePath), Charsets.UTF_8);
    return new ImmutablePair<String, String>(nodeName, value);
}
 
开发者ID:dangdangdotcom,项目名称:config-toolkit,代码行数:25,代码来源:ZookeeperConfigGroup.java


示例8: findProperties

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
@Override
public List<PropertyItem> findProperties(String node) {
	LOGGER.debug("Find properties in node: [{}]", node);
	List<PropertyItem> properties = Lists.newArrayList();
	try {
		Stat stat = getClient().checkExists().forPath(node);
		if (stat != null) {
			GetChildrenBuilder childrenBuilder = getClient().getChildren();
			List<String> children = childrenBuilder.forPath(node);
			GetDataBuilder dataBuilder = getClient().getData();
			if (children != null) {
				for (String child : children) {
					String propPath = ZKPaths.makePath(node, child);
					PropertyItem item = new PropertyItem(child, new String(dataBuilder.forPath(propPath), Charsets.UTF_8));
					properties.add(item);
				}
			}
		}
	} catch (Exception e) {
		throw Throwables.propagate(e);
	}
	return properties;
}
 
开发者ID:dangdangdotcom,项目名称:config-toolkit,代码行数:24,代码来源:NodeDao.java


示例9: query

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
@Override
protected byte[] query(final boolean setListener) throws NakadiRuntimeException {
    final GetDataBuilder builder = curatorFramework.getData();
    if (setListener) {
        builder.usingWatcher(this);
    }
    try {
        return builder.forPath(key);
    } catch (final Exception ex) {
        throw new NakadiRuntimeException(ex);
    }
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:13,代码来源:ZkSubscriptionImpl.java


示例10: getShouldWrapNonNoNodeExceptionInRestException

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
@Test
public void getShouldWrapNonNoNodeExceptionInRestException() throws Exception {
  exception.expect(RestException.class);

  GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
  when(getDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot())).thenThrow(Exception.class);

  when(curatorFramework.getData()).thenReturn(getDataBuilder);

  globalConfigService.get();
}
 
开发者ID:apache,项目名称:metron,代码行数:12,代码来源:GlobalConfigServiceImplTest.java


示例11: getData

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
private <T> Optional<T> getData(String path, Optional<Stat> stat, Transcoder<T> transcoder, Optional<ZkCache<T>> zkCache, Optional<Boolean> shouldCheckExists) {
  if (!stat.isPresent() && zkCache.isPresent()) {
    Optional<T> cachedValue = zkCache.get().get(path);
    if (cachedValue.isPresent() && (!shouldCheckExists.isPresent() || (shouldCheckExists.get().booleanValue() && checkExists(path).isPresent()))) {
      return cachedValue;
    }
  }

  final long start = System.currentTimeMillis();
  int bytes = 0;

  try {
    GetDataBuilder bldr = curator.getData();

    if (stat.isPresent()) {
      bldr.storingStatIn(stat.get());
    }

    byte[] data = bldr.forPath(path);

    if (data == null || data.length == 0) {
      LOG.trace("Empty data found for path {}", path);
      return Optional.absent();
    }

    bytes = data.length;

    final T object = transcoder.fromBytes(data);

    if (zkCache.isPresent()) {
      zkCache.get().set(path, object);
    }

    return Optional.of(object);
  } catch (NoNodeException nne) {
    return Optional.absent();
  } catch (Throwable t) {
    throw Throwables.propagate(t);
  } finally {
    log(OperationType.READ, Optional.<Integer> absent(), Optional.<Integer> of(bytes), start, path);
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:43,代码来源:CuratorManager.java


示例12: getData

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
@Override
public GetDataBuilder getData() {
    return new MockGetDataBuilder();
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:5,代码来源:MockCurator.java


示例13: testGetNodeData

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
/**
 * Test getNodeData method
 * @throws Exception
 */
@Test
public void testGetNodeData() throws Exception {
  CuratorStateManager spyStateManager = spy(new CuratorStateManager());
  final CuratorFramework mockClient = mock(CuratorFramework.class);
  GetDataBuilder mockGetBuilder = mock(GetDataBuilder.class);
  // Mockito doesn't support mock type-parametrized class, thus suppress the warning
  @SuppressWarnings("rawtypes")
  BackgroundPathable mockBackPathable = mock(BackgroundPathable.class);
  final CuratorEvent mockEvent = mock(CuratorEvent.class);
  Message.Builder mockBuilder = mock(Message.Builder.class);
  Message mockMessage = mock(Message.class);

  final byte[] data = "wy_1989".getBytes();

  doReturn(mockMessage)
      .when(mockBuilder).build();
  doReturn(data)
      .when(mockEvent).getData();
  doReturn(PATH)
      .when(mockEvent).getPath();
  doReturn(mockClient)
      .when(spyStateManager).getCuratorClient();
  doReturn(true)
      .when(mockClient).blockUntilConnected(anyInt(), any(TimeUnit.class));
  doReturn(mockGetBuilder)
      .when(mockClient).getData();
  doReturn(mockBackPathable)
      .when(mockGetBuilder).usingWatcher(any(Watcher.class));
  doAnswer(new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
      Object[] objests = invocationOnMock.getArguments();
      // the first object is the BackgroundCallback
      ((BackgroundCallback) objests[0]).processResult(mockClient, mockEvent);
      return null;
    }
  }).when(mockBackPathable).inBackground(any(BackgroundCallback.class));

  spyStateManager.initialize(config);

  // Verify the data on node is fetched correctly
  ListenableFuture<Message> result = spyStateManager.getNodeData(null, PATH, mockBuilder);
  assertTrue(result.get().equals(mockMessage));
}
 
开发者ID:twitter,项目名称:heron,代码行数:49,代码来源:CuratorStateManagerTest.java


示例14: getData

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
@Override
public GetDataBuilder getData() {
    return namespaceDelegate().getData();
}
 
开发者ID:ReadyTalk,项目名称:cultivar,代码行数:5,代码来源:NamespacedCuratorFramework.java


示例15: getData

import org.apache.curator.framework.api.GetDataBuilder; //导入依赖的package包/类
private <T> Optional<T> getData(String path, Optional<Stat> stat, Transcoder<T> transcoder, Optional<ZkCache<T>> zkCache, Optional<Boolean> shouldCheckExists) {
  if (!stat.isPresent() && zkCache.isPresent()) {
    Optional<T> cachedValue = zkCache.get().get(path);
    if (cachedValue.isPresent() && (!shouldCheckExists.isPresent() || (shouldCheckExists.get().booleanValue() && checkExists(path).isPresent()))) {
      return cachedValue;
    }
  }

  final long start = System.currentTimeMillis();
  int bytes = 0;

  try {
    GetDataBuilder bldr = curator.getData();

    if (stat.isPresent()) {
      bldr.storingStatIn(stat.get());
    }

    byte[] data = bldr.forPath(path);

    if (data == null || data.length == 0) {
      LOG.trace("Empty data found for path {}", path);
      return Optional.absent();
    }

    bytes = data.length;

    final T object = transcoder.fromBytes(data);

    if (zkCache.isPresent()) {
      zkCache.get().set(path, object);
    }

    return Optional.of(object);
  } catch (NoNodeException nne) {
    LOG.trace("No node found for path {}", path);
    return Optional.absent();
  } catch (Throwable t) {
    throw Throwables.propagate(t);
  } finally {
    log(OperationType.GET, Optional.absent(), Optional.<Integer> of(bytes), start, path);
  }
}
 
开发者ID:HubSpot,项目名称:Singularity,代码行数:44,代码来源:CuratorManager.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HdfsBolt类代码示例发布时间:2022-05-21
下一篇:
Java BasicTextUI类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap