View Javadoc

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