From 5c35bdd82275dc597f84ca33b4d7ba7eec133b12 Mon Sep 17 00:00:00 2001 From: lyr90329 Date: Wed, 13 Aug 2014 16:49:42 +0800 Subject: [PATCH] handling read and write request --- MemcachedClient/src/server/webSession.java | 92 +++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/MemcachedClient/src/server/webSession.java b/MemcachedClient/src/server/webSession.java index 5ac3704..28ef368 100644 --- a/MemcachedClient/src/server/webSession.java +++ b/MemcachedClient/src/server/webSession.java @@ -49,7 +49,7 @@ public class webSession implements Runnable public void start() { - //DBSession.getInstance().start(); + //DBSession.getInstance().start(); 数据库连接 new Thread(session).start(); System.out.println("session start"); } @@ -147,7 +147,95 @@ public class webSession implements Runnable nr_Connected_mem_back msgLite= msg.getMessageLite(); addClientChannel(msgLite.getMemID(), e.getChannel()); } - break; + break; + case nr_read_res: + { + nr_Read_res msgBody = msg.getMessageLite(); +// System.out.println("key:"+msgBody.getKey()+" value:"+msgBody.getValue()); + +// System.out.println(String.valueOf((System.nanoTime()-msgBody.getTime())/1000000.0)); +// log.log(Priority.INFO, String.valueOf((System.nanoTime()-msgBody.getTime())/1000000.0)); +// log.log(Level.INFO, String.valueOf((System.nanoTime()-msgBody.getTime())/1000000.0)); +// System.err.println((System.nanoTime()-msgBody.getTime())/1000000.0); +// if (ticks==0) +// { +// totalTime = System.currentTimeMillis(); +// } + +// totalTime += System.nanoTime()-msgBody.getTime(); +// ticks++; +// if (ticks == 1000) +// { +// System.out.println(totalTime/1000000000.0f); +// +// totalTime = 0; +// ticks = 0; +// } +// if (msgBody.getValue().isEmpty()) //读数据库 +// { +// DBMessage dbMsg=new DBMessage(); +// dbMsg.mode = DBMessage.mode_query; +// dbMsg.key = msgBody.getKey(); +// +// DBSession.getInstance().addDBMessage(dbMsg); +// } +// else +// { +// nc_ReadRes.Builder builder = nc_ReadRes.newBuilder(); +// builder.setKey(msgBody.getKey()); +// builder.setValue(msgBody.getValue()); +// +// NetMsg send = NetMsg.newMessage(); +// send.setMessageLite(builder); +// send.setMsgID(EMSGID.nc_read_res); +// +// //sendMsg(getRequestChannel(msgBody.getClientid()), send); +// } + } + break; + case nr_write_res: + { + nr_write_res msgBody = msg.getMessageLite(); +// System.out.println("key:"+msgBody.getKey()+" value:"+msgBody.getValue()); + + //DBMessage dbMsg = new DBMessage(); //异步写数据库 + //dbMsg.mode = DBMessage.mode_set; + //dbMsg.key = msgBody.getKey(); + //dbMsg.value = msgBody.getValue(); + //DBSession.getInstance().addDBMessage(dbMsg); + + +// log.log(Level.INFO, String.valueOf((System.nanoTime()-msgBody.getTime())/1000000.0)); + //System.err.println(); + +// System.out.println(String.valueOf((System.nanoTime()-msgBody.getTime())/1000000.0)); +// +// if (ticks==0) +// { +// totalTime = System.currentTimeMillis(); +// } + +// totalTime += System.nanoTime()-msgBody.getTime(); +// ticks++; +// if (ticks == 1000) +// { +// System.out.println(totalTime/1000000000.0f); +// +// totalTime = 0; +// ticks = 0; +// } + +// nc_WriteRes.Builder builder = nc_WriteRes.newBuilder(); +// builder.setKey(msgBody.getKey()); +// builder.setValue(msgBody.getValue()); +// +// NetMsg send = NetMsg.newMessage(); +// send.setMessageLite(builder); +// send.setMsgID(EMSGID.nc_write_res); + + //sendMsg(getRequestChannel(msgBody.getClientid()), send); + } + break; default: System.err.println(msg.getMsgID().toString()); break;