From ed31b8db1a90dca9157b1da41bb6d33afc63ecae Mon Sep 17 00:00:00 2001 From: Denis Karmyshakov Date: Thu, 28 Sep 2017 13:57:37 +0300 Subject: [PATCH] Noblocking getSync method --- .../core/observables/storable/BaseStorable.java | 13 +++++++++---- .../roboswag/core/observables/storable/Store.java | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/touchin/roboswag/core/observables/storable/BaseStorable.java b/src/main/java/ru/touchin/roboswag/core/observables/storable/BaseStorable.java index 390a024..db3475c 100644 --- a/src/main/java/ru/touchin/roboswag/core/observables/storable/BaseStorable.java +++ b/src/main/java/ru/touchin/roboswag/core/observables/storable/BaseStorable.java @@ -334,11 +334,16 @@ public abstract class BaseStorable { * * @return Returns value; */ - @Deprecated - //deprecation: it should be used for debug only and in very rare cases. @Nullable - public TReturnObject getSync() { - return get().blockingGet(); + public TObject getSync() { + final TStoreObject storeObject = store.getObject(storeObjectType, key); + try { + return converter.toObject(objectType, storeObjectType, storeObject); + } catch (final Converter.ConversionException exception) { + STORABLE_LC_GROUP.w(exception, "Exception while trying to converting value of '%s' from store %s by %s", + key, storeObject, store, converter); + return null; + } } /** diff --git a/src/main/java/ru/touchin/roboswag/core/observables/storable/Store.java b/src/main/java/ru/touchin/roboswag/core/observables/storable/Store.java index afc2609..410f4ba 100644 --- a/src/main/java/ru/touchin/roboswag/core/observables/storable/Store.java +++ b/src/main/java/ru/touchin/roboswag/core/observables/storable/Store.java @@ -67,4 +67,14 @@ public interface Store { @NonNull Single> loadObject(@NonNull Type storeObjectType, @NonNull TKey key); + /** + * Gets object from store by key. + * + * @param storeObjectType Type of object to store; + * @param key Key related to object; + * @return Object from store found by key; + */ + @Nullable + TStoreObject getObject(@NonNull Type storeObjectType, @NonNull TKey key); + }