gpt4 book ai didi

com.bazaarvoice.emodb.common.zookeeper.store.ZkMapStore类的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 17:07:31 26 4
gpt4 key购买 nike

本文整理了Java中com.bazaarvoice.emodb.common.zookeeper.store.ZkMapStore类的一些代码示例,展示了ZkMapStore类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkMapStore类的具体详情如下:
包路径:com.bazaarvoice.emodb.common.zookeeper.store.ZkMapStore
类名称:ZkMapStore

ZkMapStore介绍

[英]Stores a Map in ZooKeeper, watches for changes made by other servers, and caches values locally for fast access. Uses NodeDiscovery to cache values.
[中]在ZooKeeper中存储地图,监视其他服务器所做的更改,并在本地缓存值以便快速访问。使用NodeDiscovery缓存值。

代码示例

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

@Override
public void start() throws Exception {
  // Create the ZooKeeper node (persistent, not ephemeral)
  createNode(_zkPath);
  _nodeDiscovery.start();
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

private String getKeyFromPath(String path) {
  return decodeKey(ZKPaths.getNodeFromPath(path));
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

@Override
public void set(String key, T value) throws Exception {
  if (getAll().containsKey(key)) {
    _curator.setData().forPath(toPath(key), toZkBytes(value));
  } else {
    _curator.create().forPath(toPath(key), toZkBytes(value));
  }
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-sor

@Provides @Singleton @MinSplitSizeMap
MapStore<DataStoreMinSplitSize> provideMinSplitSizeMap(@DataStoreZooKeeper CuratorFramework curator,
                      LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(new ZkMapStore<>(curator, "min-split-size", new ZKDataStoreMinSplitSizeSerializer()));
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

@Nullable
@Override
public T get(String key) {
  return _nodeDiscovery.getNodes().get(toPath(key));
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

@Override
public Map<String, T> getAll() {
  // Return an immutable copy since users should only be able to modify the map using set and remove.
  ImmutableMap.Builder<String, T> builder = ImmutableMap.builder();
  for (Map.Entry<String, T> entry : _nodeDiscovery.getNodes().entrySet()) {
    builder.put(getKeyFromPath(entry.getKey()), entry.getValue());
  }
  return builder.build();
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

private String toPath(String key) {
  checkArgument(key.indexOf('/') == -1, "Keys may not contain '/'.");
  // The key may contain special characters which are invalid in ZooKeeper paths.  Encode them
  String encodedKey = encodeKey(key);
  String path = ZKPaths.makePath(_zkPath, encodedKey);
  PathUtils.validatePath(path);
  return path;
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

@Override
  public String toString() {
    return Maps.transformValues(getAll(), new Function<T, Object>() {
      @Override
      public Object apply(T value) {
        return _serializer.toString(value);
      }
    }).toString();
  }
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

private String encodeKey(String key) {
  StringBuilder encodedKey = null;
  int lastEncodedCharPos = -1;
  int length = key.length();
  for (int i=0; i < length; i++) {
    char c = key.charAt(i);
    if (c == '.'            // May be interpreted as relative path
        || c == '%'     // Collides with encoding scheme
        || isUnsupportedCharacter(c)) {
      if (lastEncodedCharPos == -1) {
        // This is the first character that has been encoded
        encodedKey = new StringBuilder();
      }
      encodedKey.append(key.substring(lastEncodedCharPos + 1, i));
      encodedKey.append("%").append(String.format("%04x", (int) c));
      lastEncodedCharPos = i;
    }
  }
  if (lastEncodedCharPos == -1) {
    return key;
  }
  encodedKey.append(key.substring(lastEncodedCharPos+1));
  return encodedKey.toString();
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-sor

@Provides @Singleton @Maintenance
MapStore<Double> provideRateLimiterSettings(@DataStoreZooKeeper CuratorFramework curator,
                      LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(new ZkMapStore<>(curator, "background_table_maintenance-rate-limits", new ZkDoubleSerializer()));
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

@Override
public void remove(String key) throws Exception {
  try {
    _curator.delete().forPath(toPath(key));
  } catch (KeeperException.NoNodeException e) {
    // Don't care
  }
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-zookeeper

@Override
public Set<String> keySet() {
  ImmutableSet.Builder<String> builder = ImmutableSet.builder();
  for (String key : _nodeDiscovery.getNodes().keySet()) {
    builder.add(getKeyFromPath(key));
  }
  return builder.build();
}

代码示例来源:origin: bazaarvoice/emodb

private String toPath(String key) {
  checkArgument(key.indexOf('/') == -1, "Keys may not contain '/'.");
  // The key may contain special characters which are invalid in ZooKeeper paths.  Encode them
  String encodedKey = encodeKey(key);
  String path = ZKPaths.makePath(_zkPath, encodedKey);
  PathUtils.validatePath(path);
  return path;
}

代码示例来源:origin: bazaarvoice/emodb

@Override
  public String toString() {
    return Maps.transformValues(getAll(), new Function<T, Object>() {
      @Override
      public Object apply(T value) {
        return _serializer.toString(value);
      }
    }).toString();
  }
}

代码示例来源:origin: bazaarvoice/emodb

private String encodeKey(String key) {
  StringBuilder encodedKey = null;
  int lastEncodedCharPos = -1;
  int length = key.length();
  for (int i=0; i < length; i++) {
    char c = key.charAt(i);
    if (c == '.'            // May be interpreted as relative path
        || c == '%'     // Collides with encoding scheme
        || isUnsupportedCharacter(c)) {
      if (lastEncodedCharPos == -1) {
        // This is the first character that has been encoded
        encodedKey = new StringBuilder();
      }
      encodedKey.append(key.substring(lastEncodedCharPos + 1, i));
      encodedKey.append("%").append(String.format("%04x", (int) c));
      lastEncodedCharPos = i;
    }
  }
  if (lastEncodedCharPos == -1) {
    return key;
  }
  encodedKey.append(key.substring(lastEncodedCharPos+1));
  return encodedKey.toString();
}

代码示例来源:origin: bazaarvoice/emodb

@Provides @Singleton @MinSplitSizeMap
MapStore<DataStoreMinSplitSize> provideMinSplitSizeMap(@DataStoreZooKeeper CuratorFramework curator,
                      LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(new ZkMapStore<>(curator, "min-split-size", new ZKDataStoreMinSplitSizeSerializer()));
}

代码示例来源:origin: bazaarvoice/emodb

@Override
public void set(String key, T value) throws Exception {
  if (getAll().containsKey(key)) {
    _curator.setData().forPath(toPath(key), toZkBytes(value));
  } else {
    _curator.create().forPath(toPath(key), toZkBytes(value));
  }
}

代码示例来源:origin: bazaarvoice/emodb

@Override
public void remove(String key) throws Exception {
  try {
    _curator.delete().forPath(toPath(key));
  } catch (KeeperException.NoNodeException e) {
    // Don't care
  }
}

代码示例来源:origin: bazaarvoice/emodb

@Override
public Map<String, T> getAll() {
  // Return an immutable copy since users should only be able to modify the map using set and remove.
  ImmutableMap.Builder<String, T> builder = ImmutableMap.builder();
  for (Map.Entry<String, T> entry : _nodeDiscovery.getNodes().entrySet()) {
    builder.put(getKeyFromPath(entry.getKey()), entry.getValue());
  }
  return builder.build();
}

代码示例来源:origin: bazaarvoice/emodb

@Override
public void start() throws Exception {
  // Create the ZooKeeper node (persistent, not ephemeral)
  createNode(_zkPath);
  _nodeDiscovery.start();
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com