删掉AsyncHandler, 采用CompletionHandler代替
This commit is contained in:
@@ -9,12 +9,12 @@ import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiConsumer;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.util.AsyncHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -28,11 +28,11 @@ public interface HttpResponseDesc {
|
||||
//增加Cookie值
|
||||
public HttpResponse addCookie(Collection<HttpCookie> cookies);
|
||||
|
||||
//创建AsyncHandler实例,将非字符串对象以JSON格式输出,字符串以文本输出
|
||||
public AsyncHandler createAsyncHandler();
|
||||
//创建CompletionHandler实例,将非字符串对象以JSON格式输出,字符串以文本输出
|
||||
public CompletionHandler createAsyncHandler();
|
||||
|
||||
//传入的AsyncHandler子类必须是public,且保证其子类可被继承且completed、failed可被重载且包含空参数的构造函数
|
||||
public <H extends AsyncHandler> H createAsyncHandler(Class<H> handlerClass);
|
||||
//传入的CompletionHandler子类必须是public,且保证其子类可被继承且completed、failed可被重载且包含空参数的构造函数
|
||||
public <H extends CompletionHandler> H createAsyncHandler(Class<H> handlerClass);
|
||||
|
||||
//设置状态码
|
||||
public void setStatus(int status);
|
||||
@@ -66,10 +66,10 @@ public interface HttpResponseDesc {
|
||||
public HttpResponse skipHeader();
|
||||
|
||||
//异步输出指定内容
|
||||
public <A> void sendBody(ByteBuffer buffer, A attachment, AsyncHandler<Integer, A> handler);
|
||||
public <A> void sendBody(ByteBuffer buffer, A attachment, CompletionHandler<Integer, A> handler);
|
||||
|
||||
//异步输出指定内容
|
||||
public <A> void sendBody(ByteBuffer[] buffers, A attachment, AsyncHandler<Integer, A> handler);
|
||||
public <A> void sendBody(ByteBuffer[] buffers, A attachment, CompletionHandler<Integer, A> handler);
|
||||
|
||||
//关闭HTTP连接,如果是keep-alive则不强制关闭
|
||||
public void finish();
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
*/
|
||||
package org.redkale.test.rest;
|
||||
|
||||
import org.redkale.util.AsyncHandler;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class HelloAsyncHandler implements AsyncHandler {
|
||||
public class HelloAsyncHandler implements CompletionHandler {
|
||||
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.redkale.test.rest;
|
||||
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import javax.annotation.Resource;
|
||||
@@ -96,7 +97,7 @@ public class HelloService implements Service {
|
||||
|
||||
//异步查询单个
|
||||
@RestMapping(name = "asyncfind2")
|
||||
public void asyncFindHello(AsyncHandler hander, @RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
public void asyncFindHello(CompletionHandler hander, @RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
if (source != null) source.findAsync(HelloEntity.class, id);
|
||||
System.out.println("-----------进入asyncfind2--------" + hander);
|
||||
hander.completed(new HelloEntity(id), id);
|
||||
|
||||
@@ -8,7 +8,7 @@ package org.redkale.test.service;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.AsynchronousChannelGroup;
|
||||
import java.nio.channels.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.logging.*;
|
||||
@@ -165,8 +165,8 @@ public class ABMainService implements Service {
|
||||
}
|
||||
|
||||
@RestMapping(name = "asyncabtime")
|
||||
public void abCurrentTime(final AsyncHandler<String, Void> handler, @RestParam(name = "#") final String name) {
|
||||
bcService.bcCurrentTime(AsyncHandler.create((v, a) -> {
|
||||
public void abCurrentTime(final CompletionHandler<String, Void> handler, @RestParam(name = "#") final String name) {
|
||||
bcService.bcCurrentTime(Utility.createAsyncHandler((v, a) -> {
|
||||
System.out.println("执行了 ABMainService.abCurrentTime----异步方法");
|
||||
String rs = "异步abCurrentTime: " + v;
|
||||
if (handler != null) handler.completed(rs, a);
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
*/
|
||||
package org.redkale.test.service;
|
||||
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import javax.annotation.Resource;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.AsyncHandler;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -24,8 +25,8 @@ public class BCService implements Service {
|
||||
return rs;
|
||||
}
|
||||
|
||||
public void bcCurrentTime(final AsyncHandler<String, Void> handler, final String name) {
|
||||
cService.ccCurrentTime(AsyncHandler.create((v, a) -> {
|
||||
public void bcCurrentTime(final CompletionHandler<String, Void> handler, final String name) {
|
||||
cService.ccCurrentTime(Utility.createAsyncHandler((v, a) -> {
|
||||
System.out.println("执行了 BCService.bcCurrentTime----异步方法");
|
||||
String rs = "异步bcCurrentTime: " + (v == null ? null : v.getResult());
|
||||
if (handler != null) handler.completed(rs, null);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package org.redkale.test.service;
|
||||
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
@@ -20,7 +21,7 @@ public class CService implements Service {
|
||||
return new RetResult(rs);
|
||||
}
|
||||
|
||||
public void ccCurrentTime(final AsyncHandler<RetResult<String>, Void> handler, final String name) {
|
||||
public void ccCurrentTime(final CompletionHandler<RetResult<String>, Void> handler, final String name) {
|
||||
String rs = "异步ccCurrentTime: " + name + ": " + Utility.formatTime(System.currentTimeMillis());
|
||||
System.out.println("执行了 CService.ccCurrentTime----异步方法");
|
||||
if (handler != null) handler.completed(new RetResult(rs), null);
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
*/
|
||||
package org.redkale.test.service;
|
||||
|
||||
import org.redkale.util.AsyncHandler;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public abstract class MyAsyncInnerHandler<V, A> implements AsyncHandler<V, A> {
|
||||
public abstract class MyAsyncInnerHandler<V, A> implements CompletionHandler<V, A> {
|
||||
|
||||
protected abstract int id2();
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package org.redkale.test.service;
|
||||
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.*;
|
||||
@@ -19,7 +20,7 @@ public class TestService implements Service {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public void change(AsyncHandler<Boolean, TestBean> handler, TestBean bean, String name, int id) {
|
||||
public void change(CompletionHandler<Boolean, TestBean> handler, TestBean bean, String name, int id) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.redkale.test.sncp;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.util.concurrent.*;
|
||||
import org.redkale.net.TransportFactory;
|
||||
import org.redkale.net.sncp.*;
|
||||
@@ -97,7 +98,7 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
return "result: " + bean;
|
||||
}
|
||||
|
||||
public void queryResult(AsyncHandler<String, SncpTestBean> handler, @RpcAttachment SncpTestBean bean) {
|
||||
public void queryResult(CompletionHandler<String, SncpTestBean> handler, @RpcAttachment SncpTestBean bean) {
|
||||
System.out.println(Thread.currentThread().getName() + " handler 运行了queryResult方法");
|
||||
if (handler != null) handler.completed("result: " + bean, bean);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user