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  import java.util.concurrent.TimeUnit;
22  
23  import org.eclipse.jetty.util.Fields;
24  
25  /**
26   * <p>A container for SYN_REPLY frames metadata and headers.</p>
27   */
28  public class ReplyInfo extends Info
29  {
30      /**
31       * <p>Flag that indicates that this {@link ReplyInfo} 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 Fields headers;
39      private final boolean close;
40  
41      /**
42       * <p>Creates a new {@link ReplyInfo} instance with empty headers and the given close flag.</p>
43       *
44       * @param close the value of the close flag
45       */
46      public ReplyInfo(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.</p>
53       *
54       * @param headers the {@link Fields}
55       * @param close   the value of the close flag
56       */
57      public ReplyInfo(Fields headers, boolean close)
58      {
59          this(0, TimeUnit.SECONDS, headers, close);
60      }
61  
62      /**
63       * <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag.</p>
64       *
65       * @param timeout the timeout
66       * @param unit    the time unit for the timeout
67       * @param headers the {@link Fields}
68       * @param close   the value of the close flag
69       */
70      public ReplyInfo(long timeout, TimeUnit unit, Fields headers, boolean close)
71      {
72          super(timeout, unit);
73          this.headers = headers;
74          this.close = close;
75      }
76  
77      /**
78       * @return the {@link Fields}
79       */
80      public Fields getHeaders()
81      {
82          return headers;
83      }
84  
85      /**
86       * @return the value of the close flag
87       */
88      public boolean isClose()
89      {
90          return close;
91      }
92  
93      /**
94       * @return the close and reset compression flags as integer
95       * @see #FLAG_CLOSE
96       */
97      public byte getFlags()
98      {
99          return isClose() ? FLAG_CLOSE : 0;
100     }
101 
102     @Override
103     public String toString()
104     {
105         return String.format("REPLY close=%b %s", close, headers);
106     }
107 }