1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.eclipse.jetty.spdy.generator;
18
19 import java.nio.ByteBuffer;
20
21 import org.eclipse.jetty.spdy.ByteBufferPool;
22 import org.eclipse.jetty.spdy.api.SPDY;
23 import org.eclipse.jetty.spdy.frames.ControlFrame;
24 import org.eclipse.jetty.spdy.frames.GoAwayFrame;
25
26 public class GoAwayGenerator extends ControlFrameGenerator
27 {
28 public GoAwayGenerator(ByteBufferPool bufferPool)
29 {
30 super(bufferPool);
31 }
32
33 @Override
34 public ByteBuffer generate(ControlFrame frame)
35 {
36 GoAwayFrame goAway = (GoAwayFrame)frame;
37
38 int frameBodyLength = 8;
39 int totalLength = ControlFrame.HEADER_LENGTH + frameBodyLength;
40 ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
41 generateControlFrameHeader(goAway, frameBodyLength, buffer);
42
43 buffer.putInt(goAway.getLastStreamId() & 0x7F_FF_FF_FF);
44 writeStatusCode(goAway, buffer);
45
46 buffer.flip();
47 return buffer;
48 }
49
50 private void writeStatusCode(GoAwayFrame goAway, ByteBuffer buffer)
51 {
52 switch (goAway.getVersion())
53 {
54 case SPDY.V2:
55 break;
56 case SPDY.V3:
57 buffer.putInt(goAway.getStatusCode());
58 break;
59 default:
60 throw new IllegalStateException();
61 }
62 }
63 }