项目作者: JSpiner

项目描述 :
java fail safe executor
高级语言: Java
项目地址: git://github.com/JSpiner/SafeExecutor.git
创建时间: 2018-02-08T03:16:10Z
项目社区:https://github.com/JSpiner/SafeExecutor

开源协议:Apache License 2.0

下载


SafeExecutor

Build Status Coverage Status Download

SafeExecutor is event-based error handler.

find a bug?
hava a question?

STILL DEVELOPING !!!

now support

  • error listener
  • add event

support soon

  • retry policy
  • thread scheduler

Usage

Before you know SafeExecutor,

  1. private void bindData(CarModel carModel) {
  2. carNameTextView.setText(carModel.detail.carName);
  3. carPriceTextView.setText(carModel.detail.price.toString());
  4. carNumberTextView.setText(carModel.detail.number.toString());
  5. }

There are many problems.

  1. carModel or carModel.detail can be null
  2. carNameTextView can be null
  3. setText is may not be able to run on other thread
  4. etc….

Of course, you can use try-catch like below.

  1. private void bindData(CarModel carModel) {
  2. try {
  3. carNameTextView.setText(carModel.detail.carName);
  4. carPriceTextView.setText(carModel.detail.price.toString());
  5. carNumberTextView.setText(carModel.detail.number.toString());
  6. }
  7. catch(Exception exception){
  8. logException(exception);
  9. }
  10. }

But there are still some problems.

  1. If first setText fails, rests are not executed.
  2. You can use try-catch on every line, but it’s uncomfortable.

After you know SafeExecutor,

  1. private void bindData(CarModel carModel) {
  2. SafeExecutor.build()
  3. .add(() -> carNameTextView.setText(carModel.detail.carName))
  4. .add(() -> carPriceTextView.setText(carModel.detail.price.toString()))
  5. .add(() -> carNumberTextView.setText(carModel.detail.number.toString()))
  6. .executeOn(Scheduler.MainThread)
  7. .onError(throwable -> logException(throwable))
  8. .run();
  9. }

Simple and safe and… looks cool!!

Download

Download

Maven

  1. <dependency>
  2. <groupId>net.jspiner</groupId>
  3. <artifactId>safeexecutor</artifactId>
  4. <version>{VERSION_CODE_HERE}</version>
  5. <type>pom</type>
  6. </dependency>

Gradle

  1. compile 'net.jspiner:safeexecutor:{VERSION_CODE_HERE}'