Compare commits
14 Commits
master
...
project/bo
| Author | SHA1 | Date |
|---|---|---|
|
|
6d83eb59bd | |
|
|
635d053a60 | |
|
|
d8a720567d | |
|
|
6eaa7fe987 | |
|
|
5af24c4d30 | |
|
|
4d6d9ea64e | |
|
|
2f39f2a3fb | |
|
|
cf7087417f | |
|
|
42ac5d6130 | |
|
|
3819f51962 | |
|
|
95a8ceef0b | |
|
|
ab3a16136c | |
|
|
e67daf7805 | |
|
|
3196ee4271 |
|
|
@ -3,7 +3,7 @@ apply plugin: 'me.tatarka.retrolambda'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 25
|
compileSdkVersion 25
|
||||||
buildToolsVersion '25.0.2'
|
buildToolsVersion '25.0.3'
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
|
@ -11,8 +11,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 9
|
minSdkVersion 16
|
||||||
targetSdkVersion 25
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
package ru.touchin.roboswag.core.observables;
|
||||||
|
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import ru.touchin.roboswag.core.utils.ProcessPriorityThreadFactory;
|
||||||
|
import rx.Observable;
|
||||||
|
import rx.Scheduler;
|
||||||
|
import rx.Subscriber;
|
||||||
|
import rx.Subscription;
|
||||||
|
import rx.functions.Actions;
|
||||||
|
import rx.schedulers.Schedulers;
|
||||||
|
|
||||||
|
//TODO: errors/next/completion/single/observable/block next after first fail
|
||||||
|
public class SequenceObservableExecutor {
|
||||||
|
|
||||||
|
private static void safeUnsubscribe(@Nullable final Subscription subscription) {
|
||||||
|
if (subscription != null && !subscription.isUnsubscribed()) {
|
||||||
|
subscription.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final Scheduler sendingScheduler = Schedulers.from(Executors.newSingleThreadExecutor());
|
||||||
|
@NonNull
|
||||||
|
private final Scheduler executeScheduler = Schedulers.from(Executors.newSingleThreadExecutor(
|
||||||
|
new ProcessPriorityThreadFactory(Thread.MIN_PRIORITY)));
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public Observable<?> execute(@NonNull final Observable<?> completable) {
|
||||||
|
final Task task = new Task(completable);
|
||||||
|
return Observable
|
||||||
|
.create(task)
|
||||||
|
.doOnUnsubscribe(task::cancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Task implements Observable.OnSubscribe<Subscriber> {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final Observable<?> completable;
|
||||||
|
@Nullable
|
||||||
|
private Subscription scheduleSubscription;
|
||||||
|
@Nullable
|
||||||
|
private Subscription executeSubscription;
|
||||||
|
|
||||||
|
public Task(@NonNull final Observable<?> completable) {
|
||||||
|
this.completable = completable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void call(@NonNull final Subscriber subscriber) {
|
||||||
|
scheduleSubscription = sendingScheduler.createWorker().schedule(() -> {
|
||||||
|
final CountDownLatch blocker = new CountDownLatch(1);
|
||||||
|
executeSubscription = completable
|
||||||
|
.subscribeOn(executeScheduler)
|
||||||
|
.doOnUnsubscribe(blocker::countDown)
|
||||||
|
.subscribe(Actions.empty(), subscriber::onError, subscriber::onCompleted);
|
||||||
|
try {
|
||||||
|
blocker.await();
|
||||||
|
} catch (final InterruptedException exception) {
|
||||||
|
safeUnsubscribe(executeSubscription);
|
||||||
|
subscriber.onError(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
safeUnsubscribe(scheduleSubscription);
|
||||||
|
safeUnsubscribe(executeSubscription);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -26,6 +26,7 @@ import java.lang.reflect.Type;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
import ru.touchin.roboswag.core.log.LcGroup;
|
import ru.touchin.roboswag.core.log.LcGroup;
|
||||||
import ru.touchin.roboswag.core.observables.OnSubscribeRefCountWithCacheTime;
|
import ru.touchin.roboswag.core.observables.OnSubscribeRefCountWithCacheTime;
|
||||||
import ru.touchin.roboswag.core.observables.storable.builders.NonNullStorableBuilder;
|
import ru.touchin.roboswag.core.observables.storable.builders.NonNullStorableBuilder;
|
||||||
|
|
@ -35,6 +36,7 @@ import rx.Observable;
|
||||||
import rx.Scheduler;
|
import rx.Scheduler;
|
||||||
import rx.Single;
|
import rx.Single;
|
||||||
import rx.exceptions.OnErrorThrowable;
|
import rx.exceptions.OnErrorThrowable;
|
||||||
|
import rx.functions.Actions;
|
||||||
import rx.schedulers.Schedulers;
|
import rx.schedulers.Schedulers;
|
||||||
import rx.subjects.PublishSubject;
|
import rx.subjects.PublishSubject;
|
||||||
|
|
||||||
|
|
@ -293,12 +295,15 @@ public class Storable<TKey, TObject, TStoreObject> {
|
||||||
return internalSet(newValue, true).toObservable();
|
return internalSet(newValue, true).toObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCalm(@Nullable final TObject value) {
|
||||||
|
set(value).subscribe(Actions.empty(), Lc::assertion);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets value synchronously. You should NOT use this method normally. Use {@link #set(Object)} asynchronously instead.
|
* Sets value synchronously. You should NOT use this method normally. Use {@link #set(Object)} asynchronously instead.
|
||||||
*
|
*
|
||||||
* @param newValue Value to set;
|
* @param newValue Value to set;
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
//deprecation: it should be used for debug only and in very rare cases.
|
//deprecation: it should be used for debug only and in very rare cases.
|
||||||
public void setSync(@Nullable final TObject newValue) {
|
public void setSync(@Nullable final TObject newValue) {
|
||||||
set(newValue).toBlocking().subscribe();
|
set(newValue).toBlocking().subscribe();
|
||||||
|
|
@ -331,7 +336,6 @@ public class Storable<TKey, TObject, TStoreObject> {
|
||||||
*
|
*
|
||||||
* @return Returns value;
|
* @return Returns value;
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
//deprecation: it should be used for debug only and in very rare cases.
|
//deprecation: it should be used for debug only and in very rare cases.
|
||||||
@Nullable
|
@Nullable
|
||||||
public TObject getSync() {
|
public TObject getSync() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 RoboSwag (Gavriil Sitnikov, Vsevolod Ivanov)
|
||||||
|
*
|
||||||
|
* This file is part of RoboSwag library.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.touchin.roboswag.core.utils;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Ilia Kurtov on 25/05/2017 with a help from https://stackoverflow.com/a/21187003/4312184
|
||||||
|
* ThreadFactory that can change default thread priority. Suitable for creating Schedulers fo RxJava like this:
|
||||||
|
* final Scheduler scheduler = Schedulers.from(Executors.newSingleThreadExecutor(new ProcessPriorityThreadFactory(Thread.MIN_PRIORITY)));
|
||||||
|
*/
|
||||||
|
public final class ProcessPriorityThreadFactory implements ThreadFactory {
|
||||||
|
|
||||||
|
private final int threadPriority;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* threadPriority can be in a range from {@link Thread#MIN_PRIORITY} to {@link Thread#MAX_PRIORITY}
|
||||||
|
*
|
||||||
|
* @param threadPriority priority for the Thread.
|
||||||
|
*/
|
||||||
|
public ProcessPriorityThreadFactory(final int threadPriority) {
|
||||||
|
this.threadPriority = threadPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public Thread newThread(@NonNull final Runnable runnable) {
|
||||||
|
final Thread thread = new Thread(runnable);
|
||||||
|
thread.setPriority(threadPriority);
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue