1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.spdy.generator;
20
21 import java.nio.ByteBuffer;
22 import java.util.EnumMap;
23
24 import org.eclipse.jetty.spdy.ByteBufferPool;
25 import org.eclipse.jetty.spdy.CompressionFactory;
26 import org.eclipse.jetty.spdy.api.DataInfo;
27 import org.eclipse.jetty.spdy.frames.ControlFrame;
28 import org.eclipse.jetty.spdy.frames.ControlFrameType;
29
30 public class Generator
31 {
32 private final EnumMap<ControlFrameType, ControlFrameGenerator> generators = new EnumMap<>(ControlFrameType.class);
33 private final DataFrameGenerator dataFrameGenerator;
34
35 public Generator(ByteBufferPool bufferPool, CompressionFactory.Compressor compressor)
36 {
37 HeadersBlockGenerator headersBlockGenerator = new HeadersBlockGenerator(compressor);
38 generators.put(ControlFrameType.SYN_STREAM, new SynStreamGenerator(bufferPool, headersBlockGenerator));
39 generators.put(ControlFrameType.SYN_REPLY, new SynReplyGenerator(bufferPool, headersBlockGenerator));
40 generators.put(ControlFrameType.RST_STREAM, new RstStreamGenerator(bufferPool));
41 generators.put(ControlFrameType.SETTINGS, new SettingsGenerator(bufferPool));
42 generators.put(ControlFrameType.NOOP, new NoOpGenerator(bufferPool));
43 generators.put(ControlFrameType.PING, new PingGenerator(bufferPool));
44 generators.put(ControlFrameType.GO_AWAY, new GoAwayGenerator(bufferPool));
45 generators.put(ControlFrameType.HEADERS, new HeadersGenerator(bufferPool, headersBlockGenerator));
46 generators.put(ControlFrameType.WINDOW_UPDATE, new WindowUpdateGenerator(bufferPool));
47 generators.put(ControlFrameType.CREDENTIAL, new CredentialGenerator(bufferPool));
48
49 dataFrameGenerator = new DataFrameGenerator(bufferPool);
50 }
51
52 public ByteBuffer control(ControlFrame frame)
53 {
54 ControlFrameGenerator generator = generators.get(frame.getType());
55 return generator.generate(frame);
56 }
57
58 public ByteBuffer data(int streamId, int length, DataInfo dataInfo)
59 {
60 return dataFrameGenerator.generate(streamId, length, dataInfo);
61 }
62 }