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 PUSH_SYN_STREAM frames metadata and data.</p>
27   */
28  public class PushInfo extends Info
29  {
30      /**
31       * <p>Flag that indicates that this {@link PushInfo} 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 Fields headers;
40  
41      /**
42       * <p>Creates a {@link PushInfo} instance with the given headers and the given close flag,
43       * not unidirectional, without associated stream, and with default priority.</p>
44       *
45       * @param headers the {@link Fields}
46       * @param close the value of the close flag
47       */
48      public PushInfo(Fields headers, boolean close)
49      {
50          this(0, TimeUnit.SECONDS, headers, close);
51          // either builder or setters for timeout
52      }
53  
54      /**
55       * <p>
56       * Creates a {@link PushInfo} instance with the given headers, the given close flag and with the given priority.
57       * </p>
58       * @param timeout the timeout value
59       * @param unit the TimeUnit of the timeout
60       * @param headers
61   *            the {@link Fields}
62       * @param close
63       */
64      public PushInfo(long timeout, TimeUnit unit, Fields headers, boolean close)
65      {
66          super(timeout, unit);
67          this.close = close;
68          this.headers = headers;
69      }
70  
71      /**
72       * @return the value of the close flag
73       */
74      public boolean isClose()
75      {
76          return close;
77      }
78  
79      /**
80       * @return the {@link Fields}
81       */
82      public Fields getHeaders()
83      {
84          return headers;
85      }
86  
87      /**
88       * @return the close flag as integer
89       * @see #FLAG_CLOSE
90       */
91      public byte getFlags()
92      {
93          return isClose() ? FLAG_CLOSE : 0;
94      }
95  
96      @Override
97      public String toString()
98      {
99          return String.format("SYN push close=%b headers=%s", close, headers);
100     }
101 }