改下类名

This commit is contained in:
wuweifeng10 2019-12-26 15:38:57 +08:00
parent f0ea3f1e1c
commit 52ace25d40
7 changed files with 6 additions and 134 deletions

View File

@ -1,42 +0,0 @@
package com.tianyalei.test;
import com.tianyalei.async.callback.ICallback;
import com.tianyalei.async.callback.IWorker;
import com.tianyalei.async.executor.timer.SystemClock;
import com.tianyalei.async.worker.WorkResult;
/**
* @author wuweifeng wrote on 2019-11-20.
*/
public class MyWorker implements IWorker<String, String>, ICallback<String, String> {
@Override
public String action(String object) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "result = " + SystemClock.now() + "---param = " + object + " from 0";
}
@Override
public String defaultValue() {
return "worker0--default";
}
@Override
public void begin() {
//System.out.println(Thread.currentThread().getName() + "- start --" + System.currentTimeMillis());
}
@Override
public void result(boolean success, String param, WorkResult<String> workResult) {
if (success) {
System.out.println("callback worker0 success--" + SystemClock.now() + "----" + workResult.getResult());
} else {
System.err.println("callback worker0 failure--" + SystemClock.now() + "----" + workResult.getResult());
}
}
}

View File

@ -1,43 +0,0 @@
package com.tianyalei.test;
import com.tianyalei.async.callback.ICallback;
import com.tianyalei.async.callback.IWorker;
import com.tianyalei.async.executor.timer.SystemClock;
import com.tianyalei.async.worker.WorkResult;
/**
* @author wuweifeng wrote on 2019-11-20.
*/
public class MyWorker1 implements IWorker<String, String>, ICallback<String, String> {
@Override
public String action(String object) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "result = " + SystemClock.now() + "---param = " + object + " from 1";
}
@Override
public String defaultValue() {
return "worker1--default";
}
@Override
public void begin() {
//System.out.println(Thread.currentThread().getName() + "- start --" + System.currentTimeMillis());
}
@Override
public void result(boolean success, String param, WorkResult<String> workResult) {
if (success) {
System.out.println("callback worker1 success--" + SystemClock.now() + "----" + workResult.getResult());
} else {
System.err.println("callback worker1 failure--" + SystemClock.now() + "----" + workResult.getResult());
}
}
}

View File

@ -1,43 +0,0 @@
package com.tianyalei.test;
import com.tianyalei.async.callback.ICallback;
import com.tianyalei.async.callback.IWorker;
import com.tianyalei.async.executor.timer.SystemClock;
import com.tianyalei.async.worker.WorkResult;
/**
* @author wuweifeng wrote on 2019-11-20.
*/
public class MyWorker2 implements IWorker<String, String>, ICallback<String, String> {
@Override
public String action(String object) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "result = " + SystemClock.now() + "---param = " + object + " from 2";
}
@Override
public String defaultValue() {
return Thread.currentThread().getName() + "--default";
}
@Override
public void begin() {
//System.out.println(Thread.currentThread().getName() + "- start --" + System.currentTimeMillis());
}
@Override
public void result(boolean success, String param, WorkResult<String> workResult) {
if (success) {
System.out.println("callback worker2 success--" + SystemClock.now() + "----" + workResult.getResult());
} else {
System.err.println("callback worker2 failure--" + SystemClock.now() + "----" + workResult.getResult());
}
}
}

View File

@ -9,7 +9,7 @@ import com.tianyalei.async.worker.WorkResult;
/**
* @author wuweifeng wrote on 2019-11-20.
*/
public class ParWorker implements IWorker<String, User>, ICallback<String, User> {
public class DeWorker implements IWorker<String, User>, ICallback<String, User> {
@Override
public User action(String object) {

View File

@ -8,7 +8,7 @@ import com.tianyalei.async.worker.WorkResult;
/**
* @author wuweifeng wrote on 2019-11-20.
*/
public class ParWorker1 implements IWorker<WorkResult<User>, User>, ICallback<WorkResult<User>, User> {
public class DeWorker1 implements IWorker<WorkResult<User>, User>, ICallback<WorkResult<User>, User> {
@Override
public User action(WorkResult<User> result) {

View File

@ -8,7 +8,7 @@ import com.tianyalei.async.worker.WorkResult;
/**
* @author wuweifeng wrote on 2019-11-20.
*/
public class ParWorker2 implements IWorker<WorkResult<User>, String>, ICallback<WorkResult<User>, String> {
public class DeWorker2 implements IWorker<WorkResult<User>, String>, ICallback<WorkResult<User>, String> {
@Override
public String action(WorkResult<User> result) {

View File

@ -15,9 +15,9 @@ import java.util.concurrent.ExecutionException;
public class Test {
public static void main(String[] args) throws ExecutionException, InterruptedException {
ParWorker w = new ParWorker();
ParWorker1 w1 = new ParWorker1();
ParWorker2 w2 = new ParWorker2();
DeWorker w = new DeWorker();
DeWorker1 w1 = new DeWorker1();
DeWorker2 w2 = new DeWorker2();
WorkerWrapper<String, User> workerWrapper = new WorkerWrapper<>(w, "0", w);
//虽然尚未执行但是也可以先取得结果的引用作为下一个任务的入参