1 /*
2 * Copyright (c) 2012 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.eclipse.jetty.spdy.api;
18
19 /**
20 * <p>A container for SYN_STREAM frames metadata and data.</p>
21 */
22 public class SynInfo
23 {
24 /**
25 * <p>Flag that indicates that this {@link DataInfo} is the last frame in the stream.</p>
26 *
27 * @see #isClose()
28 * @see #getFlags()
29 */
30 public static final byte FLAG_CLOSE = 1;
31
32 private final boolean close;
33 private final byte priority;
34 private final Headers headers;
35
36 /**
37 * <p>Creates a new {@link SynInfo} instance with empty headers and the given close flag,
38 * not unidirectional, without associated stream, and with default priority.</p>
39 *
40 * @param close the value of the close flag
41 */
42 public SynInfo(boolean close)
43 {
44 this(new Headers(), close);
45 }
46
47 /**
48 * <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag,
49 * not unidirectional, without associated stream, and with default priority.</p>
50 *
51 * @param headers the {@link Headers}
52 * @param close the value of the close flag
53 */
54 public SynInfo(Headers headers, boolean close)
55 {
56 this(headers, close, (byte)0);
57 }
58
59 /**
60 * <p>
61 * Creates a {@link ReplyInfo} instance with the given headers, the given close flag and with the given priority.
62 * </p>
63 *
64 * @param headers
65 * the {@link Headers}
66 * @param close
67 * the value of the close flag
68 * @param priority
69 * the priority
70 */
71 public SynInfo(Headers headers, boolean close, byte priority)
72 {
73 this.close = close;
74 this.priority = priority;
75 this.headers = headers;
76 }
77
78 /**
79 * @return the value of the close flag
80 */
81 public boolean isClose()
82 {
83 return close;
84 }
85
86 /**
87 * @return the priority
88 */
89 public byte getPriority()
90 {
91 return priority;
92 }
93
94 /**
95 * @return the {@link Headers}
96 */
97 public Headers getHeaders()
98 {
99 return headers;
100 }
101
102 /**
103 * @return the close flag as integer
104 * @see #FLAG_CLOSE
105 */
106 public byte getFlags()
107 {
108 return isClose() ? FLAG_CLOSE : 0;
109 }
110
111 @Override
112 public String toString()
113 {
114 return String.format("SYN close=%b headers=%s", close, headers);
115 }
116 }