Reference no: EM132217465
This should be written using JAVA and JSON. Please comment your code.
Goal:
To simulate a task management system with a priority queue.
Problem:
Provide a RESTful service which accepts as a POST of JSON a list of enqueue and dequeue statements onto an in-memory job queue.
Each job definition contains a name and a priority, with 0 being the best priority and positive integers representing lower priorities.
Return the JSON representing the state of the queue (the list of job names, in priority order), after all enqueue and dequeue statements have been processed.
Example input: { "inList" : [ { "cmd" : "enqueue", "name" : "job1", "pri" : 4 },
{ "cmd" : "enqueue", "name" : "job2", "pri" : 3 },
{ "cmd" : "dequeue" },
{ "cmd" : "enqueue", "name" : "job3", "pri" : 0 },
{ "cmd" : "enqueue", "name" : "job4", "pri" : 1 },
{ "cmd" : "dequeue" }
] }
Example output: { "outList" : [ "job4", "job1" ] }
Erroneous input (e.g. malformed JSON) should be handled gracefully.