1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package testcase;
21
22 import org.apache.mina.core.buffer.IoBuffer;
23 import org.apache.mina.core.session.IoSession;
24 import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
25 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import static testcase.MinaRegressionTest.MSG_SIZE;
29 import static testcase.MinaRegressionTest.OPEN;
30
31
32
33
34
35 public class MyRequestDecoder extends CumulativeProtocolDecoder {
36 private static final Logger logger = LoggerFactory.getLogger(MyRequestDecoder.class);
37
38 @Override
39 protected boolean doDecode(final IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
40 if (!session.containsAttribute(OPEN)) {
41 logger.error("!decoding for closed session {}", session.getId());
42 }
43
44 new Thread(new Runnable() {
45 public void run() {
46 try {
47 logger.debug( "Sleep for 500 ms for session {}", session.getId() );
48 Thread.sleep(500);
49 logger.debug( "Wake up now from a 500 ms sleep for session {}", session.getId() );
50 } catch (InterruptedException ignore) {}
51 session.close(true);
52 }
53 }).start();
54
55
56 logger.debug( "Sleep for 1000 ms for session {}", session.getId() );
57 Thread.sleep(1000);
58 logger.debug( "Wake up now from a 1000 ms sleep for session {}", session.getId() );
59
60 if (!session.containsAttribute(OPEN)) {
61 logger.error("!session {} closed before decoding completes!", session.getId());
62 int i = 0;
63
64 try
65 {
66 int j = 2 / i;
67 }
68 catch ( Exception e )
69 {
70
71 }
72 }
73
74
75 if (in.remaining() < MSG_SIZE) return false;
76
77 logger.info("Done decoding for session {}", session.getId());
78
79 if (in.hasRemaining() && !session.isClosing() && session.isConnected()) {
80 IoBuffer tmp = IoBuffer.allocate(in.remaining());
81 tmp.put(in);
82 tmp.flip();
83 out.write(tmp);
84 return true;
85 }
86
87 return false;
88 }
89 }