PageRenderTime 318ms CodeModel.GetById 33ms RepoModel.GetById 7ms app.codeStats 0ms

/src/main/java/org/n3r/mina/listener/JCServerReceiveListener.java

https://github.com/AL-WUHC2/n3r-mina
Java | 36 lines | 26 code | 10 blank | 0 comment | 0 complexity | b9a4d509d82988d5e7aa58f0002a73cf MD5 | raw file
  1. package org.n3r.mina.listener;
  2. import org.apache.mina.core.session.IoSession;
  3. import org.n3r.beanbytes.ParseBean;
  4. import org.n3r.beanbytes.utils.BeanBytesUtils;
  5. import org.n3r.core.lang.RHex;
  6. import org.n3r.mina.JCBytesParserFactory;
  7. import org.n3r.mina.JCMessageListener;
  8. import org.n3r.mina.bean.JCMessage;
  9. import org.n3r.mina.utils.JCMessageUtils;
  10. import com.alibaba.fastjson.JSON;
  11. public class JCServerReceiveListener extends JCMessageListener {
  12. private IoSession session;
  13. public JCServerReceiveListener(IoSession session) {
  14. this.session = session;
  15. }
  16. @Override
  17. public Object process(Object message, JCBytesParserFactory parser) throws Exception {
  18. logger.info("--------------------------------------------------");
  19. byte[] bytes = (byte[]) message;
  20. logger.info("[Server Received Bytes]: " + RHex.encode(BeanBytesUtils.prependLen(bytes, 2)));
  21. ParseBean<JCMessage> jcMessage = JCMessageUtils.messageFromBytes(bytes, parser.getJobType(), true);
  22. logger.info("[Server Received Message]: " + JSON.toJSONString(jcMessage.getBean()));
  23. logger.info("--------------------------------------------------");
  24. return jcMessage.getBean();
  25. }
  26. }