1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.spdy;
17
18 import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
19
20 import io.netty.util.internal.StringUtil;
21
22
23
24
25 public class DefaultSpdySynStreamFrame extends DefaultSpdyHeadersFrame
26 implements SpdySynStreamFrame {
27
28 private int associatedStreamId;
29 private byte priority;
30 private boolean unidirectional;
31
32
33
34
35
36
37
38
39 public DefaultSpdySynStreamFrame(int streamId, int associatedStreamId, byte priority) {
40 this(streamId, associatedStreamId, priority, true);
41 }
42
43
44
45
46
47
48
49
50
51 public DefaultSpdySynStreamFrame(int streamId, int associatedStreamId, byte priority, boolean validateHeaders) {
52 super(streamId, validateHeaders);
53 setAssociatedStreamId(associatedStreamId);
54 setPriority(priority);
55 }
56
57 @Override
58 public SpdySynStreamFrame setStreamId(int streamId) {
59 super.setStreamId(streamId);
60 return this;
61 }
62
63 @Override
64 public SpdySynStreamFrame setLast(boolean last) {
65 super.setLast(last);
66 return this;
67 }
68
69 @Override
70 public SpdySynStreamFrame setInvalid() {
71 super.setInvalid();
72 return this;
73 }
74
75 @Override
76 public int associatedStreamId() {
77 return associatedStreamId;
78 }
79
80 @Override
81 public SpdySynStreamFrame setAssociatedStreamId(int associatedStreamId) {
82 checkPositiveOrZero(associatedStreamId, "associatedStreamId");
83 this.associatedStreamId = associatedStreamId;
84 return this;
85 }
86
87 @Override
88 public byte priority() {
89 return priority;
90 }
91
92 @Override
93 public SpdySynStreamFrame setPriority(byte priority) {
94 if (priority < 0 || priority > 7) {
95 throw new IllegalArgumentException(
96 "Priority must be between 0 and 7 inclusive: " + priority);
97 }
98 this.priority = priority;
99 return this;
100 }
101
102 @Override
103 public boolean isUnidirectional() {
104 return unidirectional;
105 }
106
107 @Override
108 public SpdySynStreamFrame setUnidirectional(boolean unidirectional) {
109 this.unidirectional = unidirectional;
110 return this;
111 }
112
113 @Override
114 public String toString() {
115 StringBuilder buf = new StringBuilder()
116 .append(StringUtil.simpleClassName(this))
117 .append("(last: ")
118 .append(isLast())
119 .append("; unidirectional: ")
120 .append(isUnidirectional())
121 .append(')')
122 .append(StringUtil.NEWLINE)
123 .append("--> Stream-ID = ")
124 .append(streamId())
125 .append(StringUtil.NEWLINE);
126 if (associatedStreamId != 0) {
127 buf.append("--> Associated-To-Stream-ID = ")
128 .append(associatedStreamId())
129 .append(StringUtil.NEWLINE);
130 }
131 buf.append("--> Priority = ")
132 .append(priority())
133 .append(StringUtil.NEWLINE)
134 .append("--> Headers:")
135 .append(StringUtil.NEWLINE);
136 appendHeaders(buf);
137
138
139 buf.setLength(buf.length() - StringUtil.NEWLINE.length());
140 return buf.toString();
141 }
142 }