1 //
2 // ========================================================================
3 // Copyright (c) 1995-2013 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 java.util.concurrent.TimeUnit;
22
23 import org.eclipse.jetty.util.Fields;
24
25 /**
26 * <p>A container for SYN_STREAM frames metadata and data.</p>
27 */
28 public class SynInfo extends Info
29 {
30 /**
31 * <p>Flag that indicates that this {@link SynInfo} is the last frame in the stream.</p>
32 *
33 * @see #isClose()
34 * @see #getFlags()
35 */
36 public static final byte FLAG_CLOSE = 1;
37
38 private final boolean close;
39 private final byte priority;
40 private final Fields headers;
41
42 /**
43 * <p>Creates a {@link SynInfo} instance with the given headers and the given close flag,
44 * not unidirectional, without associated stream, and with default priority.</p>
45 *
46 * @param headers the {@link Fields}
47 * @param close the value of the close flag
48 */
49 public SynInfo(Fields headers, boolean close)
50 {
51 this(0, TimeUnit.SECONDS, headers, close, (byte)0);
52 // either builder or setters for timeout
53 }
54
55 /**
56 * <p>
57 * Creates a {@link SynInfo} instance with the given headers, the given close flag and with the given priority.
58 * </p>
59 * @param headers
60 * the {@link Fields}
61 * @param close
62 * the value of the close flag
63 * @param priority
64 */
65 public SynInfo(Fields headers, boolean close, byte priority)
66 {
67 this(0, TimeUnit.SECONDS, headers, close, priority);
68 }
69
70 /**
71 * <p>
72 * Creates a {@link SynInfo} instance with the given headers, the given close flag and with the given priority.
73 * </p>
74 * @param timeout the timeout value
75 * @param unit the TimeUnit of the timeout
76 * @param headers
77 * the {@link Fields}
78 * @param close
79 * the value of the close flag
80 * @param priority
81 */
82 public SynInfo(long timeout, TimeUnit unit, Fields headers, boolean close, byte priority)
83 {
84 super(timeout, unit);
85 this.close = close;
86 this.priority = priority;
87 this.headers = headers;
88 }
89
90 /**
91 * @return the value of the close flag
92 */
93 public boolean isClose()
94 {
95 return close;
96 }
97
98 /**
99 * @return the priority
100 */
101 public byte getPriority()
102 {
103 return priority;
104 }
105
106 /**
107 * @return the {@link Fields}
108 */
109 public Fields getHeaders()
110 {
111 return headers;
112 }
113
114 /**
115 * @return the close flag as integer
116 * @see #FLAG_CLOSE
117 */
118 public byte getFlags()
119 {
120 return isClose() ? FLAG_CLOSE : 0;
121 }
122
123 @Override
124 public String toString()
125 {
126 return String.format("SYN close=%b headers=%s", close, headers);
127 }
128 }