gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-18 09:55:31 25 4
gpt4 key购买 nike

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

ZkValueStore介绍

[英]Stores a single value in ZooKeeper, watches for changes made by other servers in the same cluster, and caches values locally for fast access.
[中]在ZooKeeper中存储单个值,监视同一集群中的其他服务器所做的更改,并在本地缓存值,以便快速访问。

代码示例

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

@Override
public void start() throws Exception {
  // Create the zookeeper node
  createNode();
  // Initial data load (avoid race conditions w/"NodeCache.start(true)")
  updateFromZkBytes(_curator.getData().forPath(_zkPath), _defaultValue);
  // Re-load the data and watch for changes.
  _nodeCache.getListenable().addListener(new NodeCacheListener() {
    @Override
    public void nodeChanged() throws Exception {
      ChildData childData = _nodeCache.getCurrentData();
      if (childData != null) {
        updateFromZkBytes(childData.getData(), _defaultValue);
      }
    }
  });
  _nodeCache.start();
}

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

private void updateFromZkBytes(byte[] bytes, T defaultValue) {
  if (bytes == null || bytes.length == 0) {
    _value = defaultValue;
  } else {
    try {
      String string = new String(bytes, Charsets.UTF_8);
      _value = _serializer.fromString(string);
    } catch (Exception e) {
      _log.error("Exception trying to parse value from ZK path {}: {}", _zkPath, e);
    }
  }
  fireChanged();
}

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

@Override
public void set(T value) throws Exception {
  // Eventually consistent.  To ensure things work the same when testing w/a single server vs. multiple
  // servers, get() won't return the value until it has round-tripped through ZooKeeper.
  _curator.setData().forPath(_zkPath, toZkBytes(value));
}

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

@Provides @Singleton @TableChangesEnabled
ValueStore<Boolean> provideTableChangesEnabled(@DataStoreZooKeeper CuratorFramework curator,
                        LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(new ZkValueStore<>(curator, "settings/table-changes-enabled", new ZkBooleanSerializer(), true));
}

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

public ZkValueStore(CuratorFramework curator, String zkPath, ZkValueSerializer<T> serializer, T defaultValue) {
  _curator = checkNotNull(curator, "curator");
  _zkPath = checkNotNull(zkPath, "zkPath");
  _serializer = checkNotNull(serializer, "serializer");
  _nodeCache = new NodeCache(curator, zkPath);
  _defaultValue = defaultValue;
  // Create node on instantiation
  // In practice, this creates a persistent zookeeper node without having to start the Managed resource.
  try {
    createNode();
  } catch (Exception e) {
    // Log a warning. We will try again when Managed is started
    _log.warn(format("Could not create node %s", _zkPath));
  }
}

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

@Provides @Singleton @DedupEnabled
ValueStore<Boolean> provideDedupEnabled(@DatabusZooKeeper CuratorFramework curator,
                    LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(
      new ZkValueStore<>(curator, "/settings/dedup-enabled", new ZkBooleanSerializer(), true));
}

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

public ZkValueStore(CuratorFramework curator, String zkPath, ZkValueSerializer<T> serializer, T defaultValue) {
  _curator = checkNotNull(curator, "curator");
  _zkPath = checkNotNull(zkPath, "zkPath");
  _serializer = checkNotNull(serializer, "serializer");
  _nodeCache = new NodeCache(curator, zkPath);
  _defaultValue = defaultValue;
  // Create node on instantiation
  // In practice, this creates a persistent zookeeper node without having to start the Managed resource.
  try {
    createNode();
  } catch (Exception e) {
    // Log a warning. We will try again when Managed is started
    _log.warn(format("Could not create node %s", _zkPath));
  }
}

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

@Provides @Singleton @ReplicationEnabled
ValueStore<Boolean> provideReplicationEnabled(@DatabusZooKeeper CuratorFramework curator,
                       LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(
      new ZkValueStore<>(curator, "/settings/replication-enabled", new ZkBooleanSerializer(), true));
}

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

@Override
public void start() throws Exception {
  // Create the zookeeper node
  createNode();
  // Initial data load (avoid race conditions w/"NodeCache.start(true)")
  updateFromZkBytes(_curator.getData().forPath(_zkPath), _defaultValue);
  // Re-load the data and watch for changes.
  _nodeCache.getListenable().addListener(new NodeCacheListener() {
    @Override
    public void nodeChanged() throws Exception {
      ChildData childData = _nodeCache.getCurrentData();
      if (childData != null) {
        updateFromZkBytes(childData.getData(), _defaultValue);
      }
    }
  });
  _nodeCache.start();
}

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

@Override
public void set(T value) throws Exception {
  // Eventually consistent.  To ensure things work the same when testing w/a single server vs. multiple
  // servers, get() won't return the value until it has round-tripped through ZooKeeper.
  _curator.setData().forPath(_zkPath, toZkBytes(value));
}

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

private void updateFromZkBytes(byte[] bytes, T defaultValue) {
  if (bytes == null || bytes.length == 0) {
    _value = defaultValue;
  } else {
    try {
      String string = new String(bytes, Charsets.UTF_8);
      _value = _serializer.fromString(string);
    } catch (Exception e) {
      _log.error("Exception trying to parse value from ZK path {}: {}", _zkPath, e);
    }
  }
  fireChanged();
}

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

@Provides @Singleton @TableChangesEnabled
ValueStore<Boolean> provideTableChangesEnabled(@BlobStoreZooKeeper CuratorFramework curator,
                        LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(new ZkValueStore<>(curator, "settings/table-changes-enabled", new ZkBooleanSerializer(), true));
}

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

@Provides @Singleton @MinLagDurationValues
Map<String, ValueStore<Duration>> provideMinLagDurationValues(@CassandraClusters Collection<String> cassandraClusters,
                               @GlobalFullConsistencyZooKeeper final CuratorFramework curator,
                               final LifeCycleRegistry lifeCycle) {
  final ConcurrentMap<String, ValueStore<Duration>> valuesByCluster = Maps.newConcurrentMap();
  for (String cluster : cassandraClusters) {
    String zkPath = ZKPaths.makePath("/consistency/min-lag", cluster);
    ZkValueStore<Duration> holder = new ZkValueStore<>(curator, zkPath, new ZkDurationSerializer());
    valuesByCluster.put(cluster, lifeCycle.manage(holder));
  }
  return valuesByCluster;
}

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

@Provides @Singleton @DedupEnabled
ValueStore<Boolean> provideDedupEnabled(@DatabusZooKeeper CuratorFramework curator,
                    LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(
      new ZkValueStore<>(curator, "/settings/dedup-enabled", new ZkBooleanSerializer(), true));
}

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

@Provides @Singleton @ReplicationEnabled
ValueStore<Boolean> provideReplicationEnabled(@DatabusZooKeeper CuratorFramework curator,
                       LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(
      new ZkValueStore<>(curator, "/settings/replication-enabled", new ZkBooleanSerializer(), true));
}

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

@Provides @Singleton @MinLagDurationValues
Map<String, ValueStore<Duration>> provideMinLagDurationValues(@CassandraClusters Collection<String> cassandraClusters,
                               @GlobalFullConsistencyZooKeeper final CuratorFramework curator,
                               final LifeCycleRegistry lifeCycle) {
  final ConcurrentMap<String, ValueStore<Duration>> valuesByCluster = Maps.newConcurrentMap();
  for (String cluster : cassandraClusters) {
    String zkPath = ZKPaths.makePath("/consistency/min-lag", cluster);
    ZkValueStore<Duration> holder = new ZkValueStore<>(curator, zkPath, new ZkDurationSerializer());
    valuesByCluster.put(cluster, lifeCycle.manage(holder));
  }
  return valuesByCluster;
}

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

@Provides @Singleton @TableChangesEnabled
ValueStore<Boolean> provideTableChangesEnabled(@DataStoreZooKeeper CuratorFramework curator,
                        LifeCycleRegistry lifeCycle) {
  return lifeCycle.manage(new ZkValueStore<>(curator, "settings/table-changes-enabled", new ZkBooleanSerializer(), true));
}

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

@Provides @Singleton @MinLagDurationValues
Map<String, ValueStore<Duration>> provideMinLagDurationValues(@CassandraClusters Collection<String> cassandraClusters,
                               @GlobalFullConsistencyZooKeeper final CuratorFramework curator,
                               final LifeCycleRegistry lifeCycle) {
  final ConcurrentMap<String, ValueStore<Duration>> valuesByCluster = Maps.newConcurrentMap();
  for (String cluster : cassandraClusters) {
    String zkPath = ZKPaths.makePath("/consistency/min-lag", cluster);
    ZkValueStore<Duration> holder = new ZkValueStore<>(curator, zkPath, new ZkDurationSerializer());
    valuesByCluster.put(cluster, lifeCycle.manage(holder));
  }
  return valuesByCluster;
}

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

@Provides @Singleton @HintsConsistencyTimeValues
Map<String, ValueStore<Long>> provideHintsTimestampValues(@CassandraClusters Collection<String> cassandraClusters,
                             @GlobalFullConsistencyZooKeeper CuratorFramework curator,
                             LifeCycleRegistry lifeCycle)
    throws Exception {
  // Create a timestamp holder for each Cassandra cluster.
  Map<String, ValueStore<Long>> valuesByCluster = Maps.newLinkedHashMap();
  for (String cluster : cassandraClusters) {
    String zkPath = ZKPaths.makePath("/consistency/max-timestamp", cluster);
    ZkValueStore<Long> holder = new ZkValueStore<>(curator, zkPath, new ZkTimestampSerializer());
    valuesByCluster.put(cluster, lifeCycle.manage(holder));
  }
  return valuesByCluster;
}

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

@Provides @Singleton @HintsConsistencyTimeValues
Map<String, ValueStore<Long>> provideHintsTimestampValues(@CassandraClusters Collection<String> cassandraClusters,
                             @GlobalFullConsistencyZooKeeper CuratorFramework curator,
                             LifeCycleRegistry lifeCycle) {
  // Create a timestamp holder for each Cassandra cluster.
  Map<String, ValueStore<Long>> valuesByCluster = Maps.newLinkedHashMap();
  for (String cluster : cassandraClusters) {
    String zkPath = ZKPaths.makePath("/consistency/max-timestamp", cluster);
    ZkValueStore<Long> holder = new ZkValueStore<>(curator, zkPath, new ZkTimestampSerializer());
    valuesByCluster.put(cluster, lifeCycle.manage(holder));
  }
  return valuesByCluster;
}

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