use of io.reactivex.ObservableEmitter in project kripton by xcesco.
the class BindKripton180RawInsertSelectDataSource method execute.
public <T> Observable<T> execute(final ObservableTransaction<T> transaction) {
ObservableOnSubscribe<T> emitter = new ObservableOnSubscribe<T>() {
@Override
public void subscribe(ObservableEmitter<T> emitter) {
boolean needToOpened = !BindKripton180RawInsertSelectDataSource.this.isOpenInWriteMode();
boolean success = false;
@SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
currentDaoFactory.onSessionOpened();
try {
connection.beginTransaction();
if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
connection.setTransactionSuccessful();
success = true;
}
emitter.onComplete();
} catch (Throwable e) {
Logger.error(e.getMessage());
e.printStackTrace();
emitter.onError(e);
currentDaoFactory.onSessionClear();
} finally {
try {
connection.endTransaction();
} catch (Throwable e) {
}
if (needToOpened) {
close();
}
if (success) {
currentDaoFactory.onSessionClosed();
} else {
currentDaoFactory.onSessionClear();
}
}
return;
}
};
Observable<T> result = Observable.create(emitter);
if (globalSubscribeOn != null)
result.subscribeOn(globalSubscribeOn);
if (globalObserveOn != null)
result.observeOn(globalObserveOn);
return result;
}
use of io.reactivex.ObservableEmitter in project kripton by xcesco.
the class BindApp0DataSource method execute.
public <T> Observable<T> execute(final ObservableTransaction<T> transaction) {
ObservableOnSubscribe<T> emitter = new ObservableOnSubscribe<T>() {
@Override
public void subscribe(ObservableEmitter<T> emitter) {
boolean needToOpened = !BindApp0DataSource.this.isOpenInWriteMode();
boolean success = false;
@SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
currentDaoFactory.onSessionOpened();
try {
connection.beginTransaction();
if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
connection.setTransactionSuccessful();
success = true;
}
emitter.onComplete();
} catch (Throwable e) {
Logger.error(e.getMessage());
e.printStackTrace();
emitter.onError(e);
currentDaoFactory.onSessionClear();
} finally {
try {
connection.endTransaction();
} catch (Throwable e) {
}
if (needToOpened) {
close();
}
if (success) {
currentDaoFactory.onSessionClosed();
} else {
currentDaoFactory.onSessionClear();
}
}
return;
}
};
Observable<T> result = Observable.create(emitter);
if (globalSubscribeOn != null)
result.subscribeOn(globalSubscribeOn);
if (globalObserveOn != null)
result.observeOn(globalObserveOn);
return result;
}
use of io.reactivex.ObservableEmitter in project kripton by xcesco.
the class BindXenoDataSource method execute.
public <T> Observable<T> execute(final ObservableTransaction<T> transaction) {
ObservableOnSubscribe<T> emitter = new ObservableOnSubscribe<T>() {
@Override
public void subscribe(ObservableEmitter<T> emitter) {
boolean needToOpened = !BindXenoDataSource.this.isOpenInWriteMode();
boolean success = false;
@SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
currentDaoFactory.onSessionOpened();
try {
connection.beginTransaction();
if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
connection.setTransactionSuccessful();
success = true;
}
emitter.onComplete();
} catch (Throwable e) {
Logger.error(e.getMessage());
e.printStackTrace();
emitter.onError(e);
currentDaoFactory.onSessionClear();
} finally {
try {
connection.endTransaction();
} catch (Throwable e) {
}
if (needToOpened) {
close();
}
if (success) {
currentDaoFactory.onSessionClosed();
} else {
currentDaoFactory.onSessionClear();
}
}
return;
}
};
Observable<T> result = Observable.create(emitter);
if (globalSubscribeOn != null)
result.subscribeOn(globalSubscribeOn);
if (globalObserveOn != null)
result.observeOn(globalObserveOn);
return result;
}
use of io.reactivex.ObservableEmitter in project My-MVP by REBOOTERS.
the class RxJavaBaseActivity method thread.
private void thread() {
Observable mObservable = Observable.create(new ObservableOnSubscribe() {
@Override
public void subscribe(ObservableEmitter e) throws Exception {
Log.e(TAG, "subscribe: currentThreadName==" + Thread.currentThread().getName());
sb.append("\nsubscribe: currentThreadName==" + Thread.currentThread().getName());
e.onNext("1000");
}
});
Consumer mObserver = new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
Log.e(TAG, "accept: currentThreadName==" + Thread.currentThread().getName());
Log.e(TAG, "accept: s=" + s);
sb.append("\naccept: currentThreadName==" + Thread.currentThread().getName());
logContent.setText(sb.toString());
}
};
mObservable.subscribe(mObserver);
}
use of io.reactivex.ObservableEmitter in project MyJapanese by 54wall.
the class FavWordsFragmentModelImpl method getData.
@Override
public void getData(Consumer<List<Word>> consumer, Consumer<Throwable> throwable, final String lessonId) {
Disposable disposable = Observable.create(new ObservableOnSubscribe<List<Word>>() {
@Override
public void subscribe(ObservableEmitter<List<Word>> emitter) throws Exception {
List<Word> list;
list = DBManager.getInstance().getFav(lessonId);
if (list == null) {
Log.e(TAG, "list == null");
// emitter.onError(new Exception());//经常报这个错误io.reactivex.exceptions.OnErrorNotImplementedException
} else {
emitter.onNext(list);
}
emitter.onComplete();
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer, throwable);
mCompositeDisposable.add(disposable);
}
Aggregations