Conversation
9e0a4b8 to
4d85f12
Compare
|
Even if I agree we lack consistency across backends and potential improvements (on iOS for example), I don't think going synchronous on disk write locking the main thread is the way to go. On mobile Android with Ideally persisting should occur in a background thread and we would have a callback that allows users to "block" or display a "Saving...." progress element on their end when ultra critical/rollback necessary write operations are required. For the rest of standard preferences persisting, performance is much more important. |
|
A verified write must not block the game thread, so I’m keeping the existing no-argument |
|
For async with callback I think a |
|
Implemented in |
… outcome flush() gives no way to tell whether a write reached disk: Android drops failures silently via apply(), LWJGL3 throws GdxRuntimeException, iOS ignores the writeToFile boolean. Add an additive save() that reports SUCCESS or a best-effort PreferencesSaveResult through a callback, implemented across all backends.
- FileNotFoundException no longer implies ACCESS_DENIED: it is thrown for many non-access reasons (missing parent dir, ...). Only explicit permission evidence (SecurityException, java.nio.file .AccessDeniedException matched by name for GWT compatibility, permission-related messages) maps to ACCESS_DENIED. - DISK_FULL is now actually detected: POSIX/Windows disk-full messages and GWT QuotaExceededError map to it; removed the GWT backend override in favor of the shared classifier. - Classification walks cause chains and prefers the most specific finding; bare IOException degrades to IO_ERROR. - Deduplicated write logic in LWJGL/LWJGL3/Headless backends: flush() and save() share one writeToDisk() path. - save(null) fails fast; javadoc documents threading and callback exception behavior. - Added PreferencesSaveResultTest covering all classification rules.
OS error strings come from strerror() and are locale-dependent, so message matching was fragile. Instead: - Core from() uses only universally available types: SecurityException -> ACCESS_DENIED, IOException -> IO_ERROR, else UNKNOWN. - LWJGL3/LWJGL/Headless write through java.nio.file.Files.newOutputStream so the JVM's errno translation is preserved as exception types; AccessDeniedException upgrades to ACCESS_DENIED locally. - Desktop produces no DISK_FULL: ENOSPC has no dedicated NIO type and recovering it would require message parsing. - GWT classifies locally: QuotaExceededError (a JS identifier, not localized prose) maps to DISK_FULL, else IO_ERROR. Tests updated to type-based expectations.
- Async variant saveAsync(PreferencesSaveCallback) dispatches write to background: - Android: HandlerThread + commit() - LWJGL3/LWJGL/Headless: cached thread pool - iOS: GCD global queue (DispatchQueue) - GWT: Timer.schedule(0) to yield event loop - Sync save() unchanged for callers needing immediate verification - All backends override with platform-appropriate threading
d52db02 to
4599801
Compare
|
Reworked this in |
Adds an additive callback overload to
Preferences.flush(PreferencesSaveCallback)for asynchronous persistence with a reported result. Existingflush()behavior remains unchanged.API
The callback is invoked once after persistence completes. Existing custom
Preferencesimplementations remain source-compatible through the default interface implementation; platform backends override it to perform asynchronous work.Backend behavior
SharedPreferences.Editor.commit()on a daemon worker thread, preserving the synchronous result without blocking the application thread.AccessDeniedExceptionis classified asACCESS_DENIED; other write failures areIO_ERROR.IO_ERROR.DISK_FULLusing the browser error identifierQuotaExceededError.PreferencesSaveResult.from(Throwable)is deliberately conservative and GWT-safe:SecurityExceptionmaps toACCESS_DENIED,IOExceptionmaps toIO_ERROR, and other failures map toUNKNOWN. It does not parse localized OS error messages. Desktop backends do not claimDISK_FULLbecause Java NIO provides no dedicated ENOSPC exception type.Verification
gdx, Android, GWT, Headless, LWJGL, LWJGL3, RoboVM, and RoboVM MetalANGLE.:gdx:testsuite passed.PreferencesSaveResultTestcovers conservative type classification and cause-chain handling.