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