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.io.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 final static boolean useDirectBuffers=false;
33 private final EnumMap<ControlFrameType, ControlFrameGenerator> generators = new EnumMap<>(ControlFrameType.class);
34 private final DataFrameGenerator dataFrameGenerator;
35
36 public Generator(ByteBufferPool bufferPool, CompressionFactory.Compressor compressor)
37 {
38 HeadersBlockGenerator headersBlockGenerator = new HeadersBlockGenerator(compressor);
39 generators.put(ControlFrameType.SYN_STREAM, new SynStreamGenerator(bufferPool, headersBlockGenerator));
40 generators.put(ControlFrameType.SYN_REPLY, new SynReplyGenerator(bufferPool, headersBlockGenerator));
41 generators.put(ControlFrameType.RST_STREAM, new RstStreamGenerator(bufferPool));
42 generators.put(ControlFrameType.SETTINGS, new SettingsGenerator(bufferPool));
43 generators.put(ControlFrameType.NOOP, new NoOpGenerator(bufferPool));
44 generators.put(ControlFrameType.PING, new PingGenerator(bufferPool));
45 generators.put(ControlFrameType.GO_AWAY, new GoAwayGenerator(bufferPool));
46 generators.put(ControlFrameType.HEADERS, new HeadersGenerator(bufferPool, headersBlockGenerator));
47 generators.put(ControlFrameType.WINDOW_UPDATE, new WindowUpdateGenerator(bufferPool));
48 generators.put(ControlFrameType.CREDENTIAL, new CredentialGenerator(bufferPool));
49
50 dataFrameGenerator = new DataFrameGenerator(bufferPool);
51 }
52
53 public ByteBuffer control(ControlFrame frame)
54 {
55 ControlFrameGenerator generator = generators.get(frame.getType());
56 return generator.generate(frame);
57 }
58
59 public ByteBuffer data(int streamId, int length, DataInfo dataInfo)
60 {
61 return dataFrameGenerator.generate(streamId, length, dataInfo);
62 }
63 }