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