Skip to content

Conversation

harrytmthy
Copy link
Owner

Summary

This PR enforces a singleton instance per fileName for SafeBox, simplifying lifecycle and state management. It prevents edge cases arising from concurrent instances referencing the same underlying blob store.

Implementation Details

  • SafeBox.create(...) now returns the same instance if one already exists for the given fileName.
  • Introduced a global ConcurrentHashMap<String, SafeBox> to manage instance caching.
  • stateListener, if provided on subsequent .create(...) calls, is forwarded to the existing instance via setStateListener(...).
  • Deprecated close() and closeWhenIdle() as SafeBox is now intended to be long-lived and reusable.
  • Removed SafeBoxBlobFileRegistry as manual registration is no longer necessary.

Closes #58

@harrytmthy harrytmthy added this to the 1.2.0 milestone Aug 21, 2025
@harrytmthy harrytmthy self-assigned this Aug 21, 2025
@harrytmthy harrytmthy added the enhancement New feature or request label Aug 21, 2025
@harrytmthy harrytmthy force-pushed the feature/singleton-instance-per-file branch from 836d49e to 0fa89dd Compare August 21, 2025 17:20
- SafeBox.create(...) now returns the same instance for a given fileName
- Deprecated close() and closeWhenIdle() with no-op bodies
- Removed SafeBoxBlobFileRegistry as it's no longer needed
@harrytmthy harrytmthy force-pushed the feature/singleton-instance-per-file branch from 0fa89dd to 00f0db6 Compare August 21, 2025 17:26
@harrytmthy harrytmthy merged commit 1e4ec06 into main Aug 21, 2025
3 checks passed
@harrytmthy harrytmthy deleted the feature/singleton-instance-per-file branch August 21, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enforce singleton SafeBox per file to improve fail-safety and prevent race conditions
1 participant