Class JournalCompactor
java.lang.Object
com.loomcache.server.journal.JournalCompactor
- All Implemented Interfaces:
AutoCloseable
Scheduled compactor for event journals.
Periodically compacts a journal based on a retention policy, removing old or excessive entries to manage storage.
Example:
EventJournal journal = new EventJournal(...);
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
JournalCompactor compactor = new JournalCompactor(
journal,
new RetentionPolicy.TimeBased(Duration.ofDays(7)),
Duration.ofHours(1),
executor
);
compactor.start();
// ... use journal ...
compactor.stop();
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionJournalCompactor(EventJournal journal, RetentionPolicy retentionPolicy, Duration compactionInterval, ScheduledExecutorService executor) Create a journal compactor. -
Method Summary
-
Constructor Details
-
JournalCompactor
public JournalCompactor(EventJournal journal, RetentionPolicy retentionPolicy, Duration compactionInterval, ScheduledExecutorService executor) Create a journal compactor.- Parameters:
journal- The journal to compactretentionPolicy- The retention policy to applycompactionInterval- How often to run compactionexecutor- The executor for scheduling- Throws:
IllegalArgumentException- if parameters are invalid
-
-
Method Details
-
start
public void start()Start the compaction scheduler.The first compaction runs after the interval duration, then repeats at that interval.
-
stop
public void stop()Stop the compaction scheduler.Cancels any pending compaction tasks.
-
compactNow
public int compactNow()Run compaction immediately (not on the schedule).- Returns:
- Number of entries removed
-
isRunning
public boolean isRunning()Check if the compactor is running.- Returns:
- true if scheduled and running
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-