java - Business Logic in Netty? -
i'm developing server based on netty libraby , i'm having problem how construction application regards business logic.
currenty have business logic in lastly handler , that's access database. thing can't wrap head around latency of accessing database(blocking code). advisable in handler or there alternative? code below:
public void channelread(channelhandlercontext ctx, object msg) throws exception { super.channelread(ctx, msg); msg message = (msg)msg; switch(message.messagetype){ case mtype.sign_up: userreg.signup(message.user);// blocking database access break; } }
you should execute blocking calls in defaulteventexecutorgroup or custom threadpool can added when handler added
pipeline.addlast(new defaulteventexecutorgroup(50),"bussiness_logic_handler", new bhandler());
ctx.executor().execute(new runnable() { @override public void run() { //blocking phone call }}); java network-programming netty
No comments:
Post a Comment