1. Write a Java program to simulate a distributed printer queue using ZooKeeper. You will be writing two programs the PrinterMaster and PrinterClient. Use Znodes to represent printer queue. Specifications for these components are given below.
Your program should handle all invalid arguments a
• Whenever the Master is invoked it should connect to one of the ZooKeeper quora as a client. • Master should create Znode to represent the printer queue.
• This program should run indefinitely until you type exit on the console.
• Your master should process the print job with least job id. We do not actually use a physical printer here, so just print on the console that a print job with a given id has been processed. Display the contents (data) of the Znode representing the job on the console as well.
• After your master processes the job it should remove the Znode representing the print job.
• After processing every print job your master should wait for a time period called “cool-off period”. This should be passed as an argument when you start your master.
• Whenever the client is invoked it should connect to one of the ZooKeeper quora as a client.
• This program should be invoked by passing a string as argument. We will call this argument as “data”.
• If the client has been started before the master it should throw an error with appropriate error message and exit.
• If the master hasn’t created the Znode representing the printer queue, the client should throw an appropriate error message and exit.
• If both the conditions mentioned above are not true then your client has to create a Znode under the queue. You should pass the name of the Znode representing the queue as an argument to the client.
• This Znode should be ordered automatically and be deleted when the client terminates its connection. Use an appropriate Znode type to model this behavior.
• Data for the Znode created should be the “data” argument passed when the client was invoked.
• After creating the Znode and assigning content to it, the client has to create a watch for the event “NodeDeleted” on the Znode created by this client.
• Once the watch is triggered, the client should display a message “Your print job is processed. Check the printer” and terminate.
• If the Znode created still exist even after a period of time called “timeout period” the client should print an error message, “Master must be swamped/it should have failed. Please report this to the admin” and terminate.
• Timeout period should also be passed as an argument to the client. Assign it to 10*cool-off period of the master.