Database Reference
In-Depth Information
In this latter situation, Curator provides several different distributed queue
options, accessible via the QueueBuilder object. As an example, consider
a simple distributed queue that needs to handle WorkUnit objects. This
simple class serves an example of an object that contains the information
needed to perform some task. In this case, it only contains an identifier and
a payload string:
public class WorkUnit implements Serializable {
private static final long serialVersionUID =
-2481441654256813101L;
long workId;
String payload;
public WorkUnit() { }
public WorkUnit( long workId,String payload) {
this .workId = workId;
this .payload = payload;
}
public String toString() {
return "WorkUnit<"+workId+","+payload+">";
}
}
To define a producer of WorkUnit objects, begin by defining a
DistributedQueue objectandcreatingtheCuratorclient.Inthiscase,the
client is defined using a connection string and a single shot retry policy. The
client is then started to begin processing ZooKeeper messages:
public class DistributedQueueProducer implements
Runnable {
DistributedQueue<WorkUnit> queue;
public DistributedQueueProducer(String connectString)
throws Exception {
CuratorFramework client =
CuratorFrameworkFactory. newClient (
connectString,
new RetryOneTime(10)
);
client.start();
Search WWH ::




Custom Search