use of com.twitter.thrift.Status in project commons by twitter.
the class ServerSetsTest method testSimpleSerialization.
@Test
public void testSimpleSerialization() throws Exception {
InetSocketAddress endpoint = new InetSocketAddress(12345);
Map<String, Endpoint> additionalEndpoints = ImmutableMap.of();
Status status = Status.ALIVE;
Codec<ServiceInstance> codec = ServerSetImpl.createDefaultCodec();
byte[] data = ServerSets.serializeServiceInstance(endpoint, additionalEndpoints, status, codec);
ServiceInstance instance = ServerSets.deserializeServiceInstance(data, codec);
assertEquals(endpoint.getPort(), instance.getServiceEndpoint().getPort());
assertEquals(additionalEndpoints, instance.getAdditionalEndpoints());
assertEquals(Status.ALIVE, instance.getStatus());
}
use of com.twitter.thrift.Status in project commons by twitter.
the class ServerSetImpl method join.
private EndpointStatus join(InetSocketAddress endpoint, Map<String, InetSocketAddress> additionalEndpoints, Optional<Integer> shardId) throws JoinException, InterruptedException {
checkNotNull(endpoint);
checkNotNull(additionalEndpoints);
final MemberStatus memberStatus = new MemberStatus(endpoint, additionalEndpoints, shardId);
Supplier<byte[]> serviceInstanceSupplier = new Supplier<byte[]>() {
@Override
public byte[] get() {
return memberStatus.serializeServiceInstance();
}
};
final Membership membership = group.join(serviceInstanceSupplier);
return new EndpointStatus() {
@Override
public void update(Status status) throws UpdateException {
checkNotNull(status);
LOG.warning("This method is deprecated. Please use leave() instead.");
if (status == Status.DEAD) {
leave();
} else {
LOG.warning("Status update has been ignored");
}
}
@Override
public void leave() throws UpdateException {
memberStatus.leave(membership);
}
};
}
use of com.twitter.thrift.Status in project commons by twitter.
the class StaticServerSet method join.
private EndpointStatus join(InetSocketAddress endpoint, Map<String, InetSocketAddress> auxEndpoints, Optional<Integer> shardId) {
LOG.warning("Attempt to join fixed server set ignored.");
ServiceInstance joining = new ServiceInstance(ServerSets.toEndpoint(endpoint), Maps.transformValues(auxEndpoints, ServerSets.TO_ENDPOINT), Status.ALIVE);
if (shardId.isPresent()) {
joining.setShard(shardId.get());
}
if (!hosts.contains(joining)) {
LOG.log(Level.SEVERE, "Joining instance " + joining + " does not match any member of the static set.");
}
return new EndpointStatus() {
@Override
public void leave() throws UpdateException {
LOG.warning("Attempt to adjust state of fixed server set ignored.");
}
@Override
public void update(Status status) throws UpdateException {
LOG.warning("Attempt to adjust state of fixed server set ignored.");
}
};
}
Aggregations