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

    Constructors
    Constructor
    Description
    Create a QueueController with a DistributedQueue.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<Map<String,Object>>
    drain(int max)
    Drain (remove and return) up to N items from the queue.
    org.springframework.http.ResponseEntity<Map<String,Object>>
    offer(@Nullable String item)
    Enqueue (offer) an item to the queue.
    org.springframework.http.ResponseEntity<?>
    Peek at the head of the queue without removing it.
    org.springframework.http.ResponseEntity<?>
    Dequeue (poll) an item from the head of the queue.
    org.springframework.http.ResponseEntity<Map<String,Integer>>
    Get the current size (number of items) in the queue.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • QueueController

      public QueueController(DistributedQueue<String> defaultQueue)
      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

      @RolesAllowed({"ADMIN","USER","READONLY"}) @GetMapping("/size") public org.springframework.http.ResponseEntity<Map<String,Integer>> size()
      Get the current size (number of items) in the queue.
      Returns:
      response with the size value
    • 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