-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathSimpleHttpServer.java
More file actions
49 lines (45 loc) · 1.27 KB
/
SimpleHttpServer.java
File metadata and controls
49 lines (45 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package fun.lib.actor.example;
import fun.lib.actor.api.cb.CbHttpServer;
import fun.lib.actor.api.http.DFHttpSvrReq;
import fun.lib.actor.core.DFActor;
import fun.lib.actor.core.DFActorDefine;
import fun.lib.actor.core.DFActorManager;
import fun.lib.actor.po.ActorProp;
import fun.lib.actor.po.DFActorManagerConfig;
import fun.lib.actor.po.DFTcpServerCfg;
/**
* 简单httpserver示例
* @author lostsky
*
*/
public final class SimpleHttpServer {
public static void main(String[] args) {
DFActorManager.get()
.start(EntryActor.class); //启动入口actor,开始消息循环
}
private static class EntryActor extends DFActor{
@Override
public void onStart(Object param) {
net.httpSvr(8080, new CbHttpServer() {
@Override
public int onHttpRequest(Object msg) {
DFHttpSvrReq req = (DFHttpSvrReq) msg;
//response
req.response("echo from server, uri="+req.getUri())
.send();
return MSG_AUTO_RELEASE;
}
@Override
public void onListenResult(boolean isSucc, String errMsg) {
log.info("listen result: isSucc="+isSucc+", err="+errMsg);
if(!isSucc){
sys.shutdown();
}
}
}); //start http server
}
public EntryActor(Integer id, String name, Boolean isBlockActor) {
super(id, name, isBlockActor);
}
}
}