Skip to content

Commit 68efa5c

Browse files
committed
添加命令参数
1 parent f5e3087 commit 68efa5c

File tree

4 files changed

+58
-11
lines changed

4 files changed

+58
-11
lines changed

AndroidExecLibrary/src/main/java/com/excellence/exec/Command.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public class Command {
2828
private int mParallelTaskCount = 0;
2929
private int mTimeOut = 0;
3030

31-
protected Command(int parallelTaskCount, int timeOut) {
31+
protected Command(CommanderOptions options) {
3232
mTaskQueue = new LinkedList<>();
33-
mParallelTaskCount = parallelTaskCount;
33+
mParallelTaskCount = options.mParallelTaskCount;
3434
if (mParallelTaskCount <= 0) {
3535
mParallelTaskCount = Integer.MAX_VALUE;
3636
}
37-
mTimeOut = timeOut;
37+
mTimeOut = options.mTimeOut;
3838
if (mTimeOut <= 0) {
3939
mTimeOut = DEFAULT_TIME_OUT;
4040
}

AndroidExecLibrary/src/main/java/com/excellence/exec/Commander.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,19 @@ public class Commander {
3030
* 默认:不限制并发线程数;指令超时10s终止
3131
*/
3232
public static void init() {
33-
init(Integer.MAX_VALUE, DEFAULT_TIME_OUT);
33+
init(new CommanderOptions.Builder().setParallelTaskCount(Integer.MAX_VALUE).setTimeOut(DEFAULT_TIME_OUT).build());
3434
}
3535

3636
/**
3737
* 初始化
38-
*
39-
* @param parallelTaskCount 并发线程数
40-
* @param timeOut 执行命令超时时间(存在某些命令会需要人为输入确认,此时命令会一直卡住等待),默认10s超时,终止指令
4138
*/
42-
public static void init(int parallelTaskCount, int timeOut) {
39+
public static void init(CommanderOptions options) {
4340
if (mInstance != null) {
4441
Log.i(TAG, "Commander initialized!!!");
4542
return;
4643
}
4744
mInstance = new Commander();
48-
mInstance.mCommand = new Command(parallelTaskCount, timeOut);
45+
mInstance.mCommand = new Command(options);
4946
}
5047

5148
private Commander() {
@@ -67,7 +64,8 @@ public static CommandTask addTask(@NonNull String command, IListener listener) {
6764
return addTask(new String[]{command}, listener);
6865
}
6966

70-
public static CommandTask addUniqueTask() {
67+
public static CommandTask addUniqueTask(@NonNull String command, IListener listener) {
68+
checkCommander();
7169
return null;
7270
}
7371

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.excellence.exec;
2+
3+
/**
4+
* <pre>
5+
* author : VeiZhang
6+
* blog : http://tiimor.cn
7+
* time : 2018/8/16
8+
* desc :
9+
* </pre>
10+
*/
11+
public class CommanderOptions {
12+
13+
protected int mParallelTaskCount = 0;
14+
protected int mTimeOut = 0;
15+
16+
private CommanderOptions(Builder builder) {
17+
mParallelTaskCount = builder.mParallelTaskCount;
18+
mTimeOut = builder.mTimeOut;
19+
}
20+
21+
public static class Builder {
22+
23+
private int mParallelTaskCount = 0;
24+
private int mTimeOut = 0;
25+
26+
/**
27+
*
28+
* @param parallelTaskCount 并发线程数
29+
*/
30+
public Builder setParallelTaskCount(int parallelTaskCount) {
31+
mParallelTaskCount = parallelTaskCount;
32+
return this;
33+
}
34+
35+
/**
36+
*
37+
* @param timeOut 执行命令超时时间(存在某些命令会需要人为输入确认,此时命令会一直卡住等待),默认10s超时,终止指令
38+
*/
39+
public Builder setTimeOut(int timeOut) {
40+
mTimeOut = timeOut;
41+
return this;
42+
}
43+
44+
public CommanderOptions build() {
45+
return new CommanderOptions(this);
46+
}
47+
}
48+
}

sample/src/main/java/com/excellence/exec/sample/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.excellence.exec.Command.CommandTask;
88
import com.excellence.exec.Commander;
9+
import com.excellence.exec.CommanderOptions;
910
import com.excellence.exec.IListener;
1011

1112
public class MainActivity extends AppCompatActivity {
@@ -17,7 +18,7 @@ protected void onCreate(Bundle savedInstanceState) {
1718
super.onCreate(savedInstanceState);
1819
setContentView(R.layout.activity_main);
1920

20-
Commander.init();
21+
Commander.init(new CommanderOptions.Builder().setTimeOut(1).build());
2122
final CommandTask task = Commander.addTask("ls", new IListener() {
2223
@Override
2324
public void onPre(String command) {

0 commit comments

Comments
 (0)