Skip to content

Commit

Permalink
Merge pull request #197 from HubSpot/sequential_nodes
Browse files Browse the repository at this point in the history
create persistent sequential node with empty bytes
  • Loading branch information
ssalinas authored Oct 31, 2016
2 parents cdbf3c7 + e10c4fb commit d818810
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@ protected <T> byte[] serialize(T data) {
protected <T> Optional<T> readFromZk(final String path, final Class<T> klass) {
final long start = System.currentTimeMillis();

return readFromZk(path).transform(new Function<byte[], T>() {
Optional<byte[]> data = readFromZk(path);

@Override
public T apply(byte[] data) {
log(OperationType.READ, Optional.<Integer>absent(), Optional.of(data.length), start, path);
return deserialize(data, klass, path);
if (data.isPresent()) {
log(OperationType.READ, Optional.<Integer>absent(), Optional.of(data.get().length), start, path);
if (data.get().length > 0) {
return Optional.of(deserialize(data.get(), klass, path));
}
});
}
return Optional.absent();
}

protected Optional<byte[]> readFromZk(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ public AmazonElasticLoadBalancingClient providesAwsElbClient(Optional<ElbConfigu
@Singleton
@Provides
public CuratorFramework provideCurator(ZooKeeperConfiguration config, BaragonConnectionStateListener connectionStateListener) {
CuratorFramework client = CuratorFrameworkFactory.newClient(
config.getQuorum(),
config.getSessionTimeoutMillis(),
config.getConnectTimeoutMillis(),
new ExponentialBackoffRetry(config.getRetryBaseSleepTimeMilliseconds(), config.getRetryMaxTries()));
CuratorFramework client = CuratorFrameworkFactory.builder()
.connectString(config.getQuorum())
.sessionTimeoutMs(config.getSessionTimeoutMillis())
.connectionTimeoutMs(config.getConnectTimeoutMillis())
.retryPolicy(new ExponentialBackoffRetry(config.getRetryBaseSleepTimeMilliseconds(), config.getRetryMaxTries()))
.defaultData(new byte[0])
.build();

client.getConnectionStateListenable().addListener(connectionStateListener);

Expand Down

0 comments on commit d818810

Please sign in to comment.