Class QueueFactory

java.lang.Object
io.github.elimelt.pmqueue.QueueFactory

public class QueueFactory extends Object
Factory for creating MessageQueue instances with various configurations. This class is thread-safe. Example usage:

 String filePath = "path/to/queue.dat";
 MessageQueue queue = QueueFactory.createQueue(filePath);
 
Example usage with custom configuration:

 String filePath = "path/to/queue.dat";
 MessageQueue queue = new QueueFactory.CustomQueueBuilder()
         .withFilePath(filePath)
         .withDebugEnabled(true)
         .withChecksumEnabled(true)
         .withMaxFileSize(1024 * 1024 * 1024)
         .withDefaultBufferSize(1024 * 1024)
         .withMaxBufferSize(8 * 1024 * 1024)
         .withBatchThreshold(64)
         .build();
 
  • Method Details

    • createQueue

      public static MessageQueue createQueue(String filePath) throws IOException
      Default queue configuration suitable for general use. Features moderate buffer sizes and checksum verification.
      Parameters:
      filePath - the file path for the queue
      Returns:
      MessageQueue instance
      Throws:
      IOException - if an I/O error occurs
    • createHighThroughputQueue

      public static MessageQueue createHighThroughputQueue(String filePath) throws IOException
      Creates a queue optimized for high throughput scenarios. Features larger buffers, batching, and less frequent checksum verification.

      Configuration:

      • Default buffer size: 4MB
      • Max buffer size: 16MB
      • Batch threshold: 256
      • Checksums: Disabled
      Parameters:
      filePath - the file path for the queue
      Returns:
      MessageQueue instance
      Throws:
      IOException - if an I/O error occurs
    • createDurableQueue

      public static MessageQueue createDurableQueue(String filePath) throws IOException
      Creates a queue optimized for durability and reliability. Features smaller buffers, checksum verification, and debug logging.

      Configuration:

      • Default buffer size: 1MB
      • Max buffer size: 4MB
      • Batch threshold: 32
      • Checksums: Enabled
      • Debug logging: Enabled
      Parameters:
      filePath - the file path for the queue
      Returns:
      MessageQueue instance
      Throws:
      IOException - if an I/O error occurs
    • createLargeMessageQueue

      public static MessageQueue createLargeMessageQueue(String filePath) throws IOException
      Creates a queue optimized for storing large messages. Features larger buffers and smaller batch sizes.

      Configuration:

      • Default buffer size: 16MB
      • Max buffer size: 32MB
      • Batch threshold: 16
      Parameters:
      filePath - the file path for the queue
      Returns:
      MessageQueue instance
      Throws:
      IOException - if an I/O error occurs
    • createLowMemoryQueue

      public static MessageQueue createLowMemoryQueue(String filePath) throws IOException
      Creates a queue optimized for low memory environments. Features smaller buffers and batch sizes.

      Configuration:

      • Default buffer size: 256KB
      • Max buffer size: 1MB
      • Batch threshold: 16
      Parameters:
      filePath - the file path for the queue
      Returns:
      MessageQueue instance
      Throws:
      IOException - if an I/O error occurs
    • createDebugQueue

      public static MessageQueue createDebugQueue(String filePath) throws IOException
      Creates a queue with debug logging enabled. Features checksum verification and debug logging. Note: Debug logging can impact performance.

      Configuration:

      • Default buffer size: 1MB
      • Max buffer size: 2MB
      • Batch threshold: 32
      • Checksums: Enabled
      • Debug logging: Enabled
      Parameters:
      filePath - the file path for the queue
      Returns:
      MessageQueue instance
      Throws:
      IOException - if an I/O error occurs