use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project RxCache by VictorAlbertos.
the class ProcessorProvidersBehaviour method getDataFromLoader.
private Observable<Reply> getDataFromLoader(final io.rx_cache2.ConfigProvider configProvider, final Record record) {
return configProvider.getLoaderObservable().map(new Function<Object, Reply>() {
@Override
public Reply apply(Object data) throws Exception {
boolean useExpiredData = configProvider.useExpiredDataIfNotLoaderAvailable() != null ? configProvider.useExpiredDataIfNotLoaderAvailable() : useExpiredDataIfLoaderNotAvailable;
if (data == null && useExpiredData && record != null) {
return new Reply(record.getData(), record.getSource(), configProvider.isEncrypted());
}
clearKeyIfNeeded(configProvider);
if (data == null) {
throw new io.rx_cache2.RxCacheException(io.rx_cache2.internal.Locale.NOT_DATA_RETURN_WHEN_CALLING_OBSERVABLE_LOADER + " " + configProvider.getProviderKey());
}
twoLayersCache.save(configProvider.getProviderKey(), configProvider.getDynamicKey(), configProvider.getDynamicKeyGroup(), data, configProvider.getLifeTimeMillis(), configProvider.isExpirable(), configProvider.isEncrypted());
return new Reply(data, Source.CLOUD, configProvider.isEncrypted());
}
}).onErrorReturn(new Function<Object, Object>() {
@Override
public Object apply(Object o) throws Exception {
clearKeyIfNeeded(configProvider);
boolean useExpiredData = configProvider.useExpiredDataIfNotLoaderAvailable() != null ? configProvider.useExpiredDataIfNotLoaderAvailable() : useExpiredDataIfLoaderNotAvailable;
if (useExpiredData && record != null) {
return new Reply(record.getData(), record.getSource(), configProvider.isEncrypted());
}
throw new io.rx_cache2.RxCacheException(io.rx_cache2.internal.Locale.NOT_DATA_RETURN_WHEN_CALLING_OBSERVABLE_LOADER + " " + configProvider.getProviderKey(), (Throwable) o);
}
});
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project RxCache by VictorAlbertos.
the class ProvidersRxCacheTest method _10_When_Retrieve_Cached_Data_After_Modified_Object_On_Item_List_Then_Object_Preserves_Initial_State.
@Test
public void _10_When_Retrieve_Cached_Data_After_Modified_Object_On_Item_List_Then_Object_Preserves_Initial_State() {
initProviders(false);
TestObserver<Reply<List<io.rx_cache2.internal.Mock>>> subscriber;
subscriber = new TestObserver<>();
providersRxCache.getMocksWithDetailResponse(createObservableMocks(SIZE)).subscribe(subscriber);
subscriber.awaitTerminalEvent();
Reply<List<io.rx_cache2.internal.Mock>> reply = subscriber.values().get(0);
Type type = new TypeToken<Reply<List<io.rx_cache2.internal.Mock>>>() {
}.getType();
Reply<List<io.rx_cache2.internal.Mock>> replyOriginal = (Reply<List<io.rx_cache2.internal.Mock>>) deepCopy(reply, type);
assertThat(compare(reply, replyOriginal, type), is(true));
reply.getData().get(0).setMessage("modified");
assertThat(compare(reply, replyOriginal, type), is(false));
subscriber = new TestObserver<>();
providersRxCache.getMocksWithDetailResponse(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader()).subscribe(subscriber);
subscriber.awaitTerminalEvent();
assertThat(subscriber.errors().size(), is(0));
assertThat(subscriber.values().size(), is(1));
reply = subscriber.values().get(0);
type = new TypeToken<List<io.rx_cache2.internal.Mock>>() {
}.getType();
assertThat(compare(reply.getData(), replyOriginal.getData(), type), is(true));
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project 91Pop by DanteAndroid.
the class AppApiHelper method loadPorn91VideoUrl.
@Override
public Observable<VideoResult> loadPorn91VideoUrl(String viewKey) {
String ip = addressHelper.getRandomIPAddress();
Observable<String> stringObservable = noLimit91PornServiceApi.getVideoPlayPage(viewKey, ip, HeaderUtils.getIndexHeader(addressHelper));
return cacheProviders.getVideoPlayPage(stringObservable, new DynamicKey(viewKey), new EvictDynamicKey(false)).map(new Function<Reply<String>, String>() {
@Override
public String apply(Reply<String> responseBodyReply) throws Exception {
switch(responseBodyReply.getSource()) {
case CLOUD:
Logger.t(TAG).d("数据来自:网络");
break;
case MEMORY:
Logger.t(TAG).d("数据来自:内存");
break;
case PERSISTENCE:
Logger.t(TAG).d("数据来自:磁盘缓存");
break;
default:
break;
}
return responseBodyReply.getData();
}
}).map(new Function<String, VideoResult>() {
@Override
public VideoResult apply(String s) throws Exception {
return Parse91PronVideo.parseVideoPlayUrl(s);
}
});
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project 91Pop by DanteAndroid.
the class AppApiHelper method loadPorn91VideoRecentUpdates.
@Override
public Observable<BaseResult<List<UnLimit91PornItem>>> loadPorn91VideoRecentUpdates(String next, int page, boolean cleanCache, boolean isLoadMoreCleanCache) {
DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(next, page);
EvictDynamicKey evictDynamicKey = new EvictDynamicKey(cleanCache || isLoadMoreCleanCache);
Observable<String> categoryPage = noLimit91PornServiceApi.recentUpdates(next, page, HeaderUtils.getIndexHeader(addressHelper));
return cacheProviders.getRecentUpdates(categoryPage, dynamicKeyGroup, evictDynamicKey).map(new Function<Reply<String>, String>() {
@Override
public String apply(Reply<String> responseBody) throws Exception {
return responseBody.getData();
}
}).map(new Function<String, BaseResult<List<UnLimit91PornItem>>>() {
@Override
public BaseResult<List<UnLimit91PornItem>> apply(String s) throws Exception {
return Parse91PronVideo.parseHot(s);
}
});
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project 91Pop by DanteAndroid.
the class AppApiHelper method loadPorn91VideoByCategory.
@Override
public Observable<BaseResult<List<UnLimit91PornItem>>> loadPorn91VideoByCategory(String category, String viewType, int page, String m, boolean cleanCache, boolean isLoadMoreCleanCache) {
// RxCache条件区别
String condition;
if (TextUtils.isEmpty(m)) {
condition = category;
} else {
condition = category + m;
}
DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(condition, page);
EvictDynamicKey evictDynamicKey = new EvictDynamicKey(cleanCache || isLoadMoreCleanCache);
Observable<String> categoryPage = noLimit91PornServiceApi.getCategoryPage(category, viewType, page, m, HeaderUtils.getIndexHeader(addressHelper));
return cacheProviders.getCategoryPage(categoryPage, dynamicKeyGroup, evictDynamicKey).map(new Function<Reply<String>, String>() {
@Override
public String apply(Reply<String> responseBody) throws Exception {
return responseBody.getData();
}
}).map(new Function<String, BaseResult<List<UnLimit91PornItem>>>() {
@Override
public BaseResult<List<UnLimit91PornItem>> apply(String s) throws Exception {
return Parse91PronVideo.parseHot(s);
}
});
}
Aggregations