Search in sources :

Example 1 with Status

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());
}
Also used : Status(com.twitter.thrift.Status) Endpoint(com.twitter.thrift.Endpoint) InetSocketAddress(java.net.InetSocketAddress) ServiceInstance(com.twitter.thrift.ServiceInstance) Test(org.junit.Test)

Example 2 with Status

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);
        }
    };
}
Also used : Status(com.twitter.thrift.Status) Membership(com.twitter.common.zookeeper.Group.Membership) Supplier(com.twitter.common.base.Supplier)

Example 3 with Status

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.");
        }
    };
}
Also used : Status(com.twitter.thrift.Status) ServiceInstance(com.twitter.thrift.ServiceInstance)

Aggregations

Status (com.twitter.thrift.Status)3 ServiceInstance (com.twitter.thrift.ServiceInstance)2 Supplier (com.twitter.common.base.Supplier)1 Membership (com.twitter.common.zookeeper.Group.Membership)1 Endpoint (com.twitter.thrift.Endpoint)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.Test)1