class SegmentPersistentQueue extends AbstractSessionMessageQueue<SessionRegistry.EnqueuedMessage> {

    private static final Logger LOG = LoggerFactory.getLogger(SegmentPersistentQueue.class);

    private final Queue segmentedQueue;
    private final SegmentedPersistentQueueSerDes serdes = new SegmentedPersistentQueueSerDes();

    public SegmentPersistentQueue(Queue segmentedQueue) {
        this.segmentedQueue = segmentedQueue;
    }

    @Override
    public void enqueue(SessionRegistry.EnqueuedMessage message) {
        LOG.debug("Adding message {}", message);
        checkEnqueuePreconditions(message);

        final ByteBuffer payload = serdes.toBytes(message);
        try {
            segmentedQueue.enqueue(payload);
        } catch (QueueException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public SessionRegistry.EnqueuedMessage dequeue() {<FILL_FUNCTION_BODY>}

    @Override
    public boolean isEmpty() {
        return segmentedQueue.isEmpty();
    }

    @Override
    public void closeAndPurge() {
        closed = true;
    }
}

        checkDequeuePreconditions();

        final Optional<ByteBuffer> dequeue;
        try {
            dequeue = segmentedQueue.dequeue();
        } catch (QueueException e) {
            throw new RuntimeException(e);
        }
        if (!dequeue.isPresent()) {
            LOG.debug("No data pulled out from the queue");
            return null;
        }

        final ByteBuffer content = dequeue.get();
        SessionRegistry.EnqueuedMessage message = serdes.fromBytes(content);
        LOG.debug("Retrieved message {}", message);
        return message;
    
<methods>public non-sealed void <init>() <variables>protected boolean closed