com.twitter.common.zookeeper
Class ServerSetImpl

java.lang.Object
  extended by com.twitter.common.zookeeper.ServerSetImpl
All Implemented Interfaces:
DynamicHostSet<ServiceInstance>, ServerSet

public class ServerSetImpl
extends Object
implements ServerSet

Implementation of ServerSet.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.twitter.common.zookeeper.ServerSet
ServerSet.EndpointStatus, ServerSet.UpdateException
 
Nested classes/interfaces inherited from interface com.twitter.common.net.pool.DynamicHostSet
DynamicHostSet.HostChangeMonitor<T>, DynamicHostSet.MonitorException
 
Constructor Summary
ServerSetImpl(ZooKeeperClient zkClient, Group group)
          Creates a new ServerSet using the given service group.
ServerSetImpl(ZooKeeperClient zkClient, Group group, Codec<ServiceInstance> codec)
          Creates a new ServerSet using the given service group and a custom codec.
ServerSetImpl(ZooKeeperClient zkClient, Iterable<org.apache.zookeeper.data.ACL> acl, String path)
          Creates a new ServerSet for the given service path.
ServerSetImpl(ZooKeeperClient zkClient, String path)
          Creates a new ServerSet using open ZooKeeper node ACLs.
 
Method Summary
static Codec<ServiceInstance> createDefaultCodec()
          Returns a codec for ServiceInstance objects that uses either the Thrift or the JSON encoding, depending on whether the command line argument serverset_json_encofing is set to true, and can decode both Thrift and JSON encodings.
static Codec<ServiceInstance> createJsonCodec()
          Creates a codec for ServiceInstance objects that uses JSON encoding, and can decode both Thrift and JSON encodings.
static Codec<ServiceInstance> createThriftCodec()
          Creates a codec for ServiceInstance objects that uses Thrift binary encoding, and can decode both Thrift and JSON encodings.
 ServerSet.EndpointStatus join(InetSocketAddress endpoint, Map<String,InetSocketAddress> additionalEndpoints, Status status)
          Attempts to join a server set for this logical service group.
 void monitor(DynamicHostSet.HostChangeMonitor<ServiceInstance> monitor)
          Registers a monitor to receive change notices for this server set as long as this jvm process is alive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerSetImpl

public ServerSetImpl(ZooKeeperClient zkClient,
                     String path)
Creates a new ServerSet using open ZooKeeper node ACLs.

Parameters:
zkClient - the client to use for interactions with ZooKeeper
path - the name-service path of the service to connect to

ServerSetImpl

public ServerSetImpl(ZooKeeperClient zkClient,
                     Iterable<org.apache.zookeeper.data.ACL> acl,
                     String path)
Creates a new ServerSet for the given service path.

Parameters:
zkClient - the client to use for interactions with ZooKeeper
acl - the ACL to use for creating the persistent group path if it does not already exist
path - the name-service path of the service to connect to

ServerSetImpl

public ServerSetImpl(ZooKeeperClient zkClient,
                     Group group)
Creates a new ServerSet using the given service group.

Parameters:
zkClient - the client to use for interactions with ZooKeeper
group - the server group

ServerSetImpl

public ServerSetImpl(ZooKeeperClient zkClient,
                     Group group,
                     Codec<ServiceInstance> codec)
Creates a new ServerSet using the given service group and a custom codec.

Parameters:
zkClient - the client to use for interactions with ZooKeeper
group - the server group
codec - a codec to use for serializing and de-serializing the ServiceInstance data to and from a byte array
Method Detail

join

public ServerSet.EndpointStatus join(InetSocketAddress endpoint,
                                     Map<String,InetSocketAddress> additionalEndpoints,
                                     Status status)
                              throws Group.JoinException,
                                     InterruptedException
Description copied from interface: ServerSet
Attempts to join a server set for this logical service group.

Specified by:
join in interface ServerSet
Parameters:
endpoint - the primary service endpoint
additionalEndpoints - and additional endpoints keyed by their logical name
status - the current service status
Returns:
an EndpointStatus object that allows the endpoint to adjust its status
Throws:
Group.JoinException - if there was a problem joining the server set
InterruptedException - if interrupted while waiting to join the server set

monitor

public void monitor(DynamicHostSet.HostChangeMonitor<ServiceInstance> monitor)
             throws DynamicHostSet.MonitorException
Description copied from interface: DynamicHostSet
Registers a monitor to receive change notices for this server set as long as this jvm process is alive. Blocks until the initial server set can be gathered and delivered to the monitor. The monitor will be notified if the membership set or parameters of existing members have changed.

Specified by:
monitor in interface DynamicHostSet<ServiceInstance>
Parameters:
monitor - the server set monitor to call back when the host set changes
Throws:
DynamicHostSet.MonitorException - if there is a problem monitoring the host set

createThriftCodec

public static Codec<ServiceInstance> createThriftCodec()
Creates a codec for ServiceInstance objects that uses Thrift binary encoding, and can decode both Thrift and JSON encodings.

Returns:
a new codec instance.

createJsonCodec

public static Codec<ServiceInstance> createJsonCodec()
Creates a codec for ServiceInstance objects that uses JSON encoding, and can decode both Thrift and JSON encodings.

Returns:
a new codec instance.

createDefaultCodec

public static Codec<ServiceInstance> createDefaultCodec()
Returns a codec for ServiceInstance objects that uses either the Thrift or the JSON encoding, depending on whether the command line argument serverset_json_encofing is set to true, and can decode both Thrift and JSON encodings.

Returns:
a new codec instance.