@@ -35,29 +35,39 @@ public class CommandTask {
3535 private Command mManager = null ;
3636 private Executor mResponsePoster = null ;
3737 private List <String > mCommand = null ;
38- private int mTimeOut = 0 ;
38+ private TimeUnit mTimeUnit = null ;
39+ private long mTimeOut = 0 ;
40+ private long mTimeDelay = 0 ;
3941
4042 private Process mProcess = null ;
4143 private int mStatus = STATUS_WAITING ;
4244 private CommandTaskListener mIListener = null ;
4345 private Disposable mTimer = null ;
4446 private String mCmd = null ;
4547
46- private CommandTask (List < String > command , int timeOut ) {
48+ private CommandTask (Builder builder ) {
4749 mManager = Commander .getCommand ();
48- mCommand = command ;
49- mTimeOut = timeOut ;
50+
51+ mCommand = builder .mCommand ;
52+ mTimeUnit = builder .mTimeUnit ;
53+ mTimeOut = builder .mTimeOut ;
5054 if (mTimeOut <= 0 ) {
5155 mTimeOut = mManager .getTimeOut ();
5256 }
57+ mTimeDelay = builder .mTimeDelay ;
58+ if (mTimeDelay < 0 ) {
59+ mTimeDelay = 0 ;
60+ }
5361 mResponsePoster = mManager .getResponsePoster ();
5462 mIListener = new CommandTaskListener ();
5563 }
5664
5765 public static class Builder {
5866
5967 private List <String > mCommand = null ;
60- private int mTimeOut = 0 ;
68+ private TimeUnit mTimeUnit = TimeUnit .MILLISECONDS ;
69+ private long mTimeOut = 0 ;
70+ private long mTimeDelay = 0 ;
6171
6272 /**
6373 * 任务命令
@@ -71,18 +81,40 @@ public Builder command(List<String> command) {
7181 }
7282
7383 /**
74- * 单独设置任务超时时间:ms
84+ * 延时、超时的时间单位,默认:ms {@link TimeUnit#MILLISECONDS}
85+ *
86+ * @param timeUnit
87+ * @return
88+ */
89+ public Builder timeUnit (TimeUnit timeUnit ) {
90+ mTimeUnit = timeUnit ;
91+ return this ;
92+ }
93+
94+ /**
95+ * 单独设置任务超时时间,默认:10 * 1000ms {@link Command#DEFAULT_TIME_OUT}
7596 *
7697 * @param timeOut
7798 * @return
7899 */
79- public Builder timeOut (int timeOut ) {
100+ public Builder timeOut (long timeOut ) {
80101 mTimeOut = timeOut ;
81102 return this ;
82103 }
83104
105+ /**
106+ * 设置任务延时启动,默认:0ms
107+ *
108+ * @param timeDelay
109+ * @return
110+ */
111+ public Builder timeDelay (long timeDelay ) {
112+ mTimeDelay = timeDelay ;
113+ return this ;
114+ }
115+
84116 public CommandTask build () {
85- return new CommandTask (mCommand , mTimeOut );
117+ return new CommandTask (this );
86118 }
87119 }
88120
@@ -164,7 +196,7 @@ private void resetTimer() {
164196
165197 private void restartTimer () {
166198 resetTimer ();
167- mTimer = Observable .timer (mTimeOut , TimeUnit . MILLISECONDS ).subscribe (new Consumer <Long >() {
199+ mTimer = Observable .timer (mTimeOut , mTimeUnit ).subscribe (new Consumer <Long >() {
168200 @ Override
169201 public void accept (Long aLong ) throws Exception {
170202 mIListener .onError (new Throwable ("Time out : " + mCmd ));
0 commit comments