1 //
2 // ========================================================================
3 // Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.spdy.api;
20
21 import org.eclipse.jetty.util.Fields;
22
23 /**
24 * <p>A container for SYN_STREAM frames metadata and data.</p>
25 */
26 public class SynInfo
27 {
28 /**
29 * <p>Flag that indicates that this {@link DataInfo} is the last frame in the stream.</p>
30 *
31 * @see #isClose()
32 * @see #getFlags()
33 */
34 public static final byte FLAG_CLOSE = 1;
35
36 private final boolean close;
37 private final byte priority;
38 private final Fields headers;
39
40 /**
41 * <p>Creates a new {@link SynInfo} instance with empty headers and the given close flag,
42 * not unidirectional, without associated stream, and with default priority.</p>
43 *
44 * @param close the value of the close flag
45 */
46 public SynInfo(boolean close)
47 {
48 this(new Fields(), close);
49 }
50
51 /**
52 * <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag,
53 * not unidirectional, without associated stream, and with default priority.</p>
54 *
55 * @param headers the {@link Fields}
56 * @param close the value of the close flag
57 */
58 public SynInfo(Fields headers, boolean close)
59 {
60 this(headers, close, (byte)0);
61 }
62
63 /**
64 * <p>
65 * Creates a {@link ReplyInfo} instance with the given headers, the given close flag and with the given priority.
66 * </p>
67 *
68 * @param headers
69 * the {@link Fields}
70 * @param close
71 * the value of the close flag
72 * @param priority
73 * the priority
74 */
75 public SynInfo(Fields headers, boolean close, byte priority)
76 {
77 this.close = close;
78 this.priority = priority;
79 this.headers = headers;
80 }
81
82 /**
83 * @return the value of the close flag
84 */
85 public boolean isClose()
86 {
87 return close;
88 }
89
90 /**
91 * @return the priority
92 */
93 public byte getPriority()
94 {
95 return priority;
96 }
97
98 /**
99 * @return the {@link Fields}
100 */
101 public Fields getHeaders()
102 {
103 return headers;
104 }
105
106 /**
107 * @return the close flag as integer
108 * @see #FLAG_CLOSE
109 */
110 public byte getFlags()
111 {
112 return isClose() ? FLAG_CLOSE : 0;
113 }
114
115 @Override
116 public String toString()
117 {
118 return String.format("SYN close=%b headers=%s", close, headers);
119 }
120 }