Class QueueController
java.lang.Object
com.loomcache.springboot.controller.QueueController
@RestController
@Conditional(LoomServerEnabledCondition.class)
@RequestMapping("/api/queue")
public class QueueController
extends Object
REST controller for DistributedQueue operations.
Endpoints: POST /api/queue — offer (enqueue) an item POST /api/queue/poll — poll (dequeue) an item GET /api/queue/peek — peek at the head without removing GET /api/queue/size — get queue size POST /api/queue/drain — drain up to N items
-
Constructor Summary
ConstructorsConstructorDescriptionQueueController(DistributedQueue<String> defaultQueue) Create a QueueController with a DistributedQueue. -
Method Summary
Modifier and TypeMethodDescriptiondrain(int max) Drain (remove and return) up to N items from the queue.Enqueue (offer) an item to the queue.org.springframework.http.ResponseEntity<?> peek()Peek at the head of the queue without removing it.org.springframework.http.ResponseEntity<?> poll()Dequeue (poll) an item from the head of the queue.size()Get the current size (number of items) in the queue.
-
Constructor Details
-
QueueController
Create a QueueController with a DistributedQueue.- Parameters:
defaultQueue- the distributed queue to use (must not be null)- Throws:
NullPointerException- if defaultQueue is null
-
-
Method Details
-
offer
@RolesAllowed({"ADMIN","USER"}) @PostMapping public org.springframework.http.ResponseEntity<Map<String,Object>> offer(@RequestBody @Nullable String item) Enqueue (offer) an item to the queue.- Parameters:
item- the item to enqueue (plain string in request body, must not be null)- Returns:
- response with success flag and current queue size
-
poll
@RolesAllowed({"ADMIN","USER"}) @PostMapping("/poll") public org.springframework.http.ResponseEntity<?> poll()Dequeue (poll) an item from the head of the queue.- Returns:
- response with the dequeued item or "null" if queue is empty
-
peek
@RolesAllowed({"ADMIN","USER","READONLY"}) @GetMapping("/peek") public org.springframework.http.ResponseEntity<?> peek()Peek at the head of the queue without removing it.- Returns:
- response with the head item or "null" if queue is empty
-
size
-
drain
@RolesAllowed({"ADMIN","USER"}) @PostMapping("/drain") public org.springframework.http.ResponseEntity<Map<String,Object>> drain(@RequestParam(defaultValue="100") int max) Drain (remove and return) up to N items from the queue.- Parameters:
max- maximum number of items to drain (default 100)- Returns:
- response with list of drained items and count
-