View Javadoc

1   /*
2    * Copyright 2013 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package org.jboss.netty.handler.codec.spdy;
17  
18  import org.jboss.netty.util.internal.StringUtil;
19  
20  /**
21   * The default {@link SpdySynStreamFrame} implementation.
22   */
23  public class DefaultSpdySynStreamFrame extends DefaultSpdyHeadersFrame
24          implements SpdySynStreamFrame {
25  
26      private int associatedToStreamId;
27      private byte priority;
28      private boolean unidirectional;
29  
30      /**
31       * Creates a new instance.
32       *
33       * @param streamId             the Stream-ID of this frame
34       * @param associatedToStreamId the Associated-To-Stream-ID of this frame
35       * @param priority             the priority of the stream
36       */
37      public DefaultSpdySynStreamFrame(
38              int streamId, int associatedToStreamId, byte priority) {
39          super(streamId);
40          setAssociatedToStreamId(associatedToStreamId);
41          setPriority(priority);
42      }
43  
44      public int getAssociatedToStreamId() {
45          return associatedToStreamId;
46      }
47  
48      public void setAssociatedToStreamId(int associatedToStreamId) {
49          if (associatedToStreamId < 0) {
50              throw new IllegalArgumentException(
51                      "Associated-To-Stream-ID cannot be negative: " +
52                      associatedToStreamId);
53          }
54          this.associatedToStreamId = associatedToStreamId;
55      }
56  
57      public byte getPriority() {
58          return priority;
59      }
60  
61      public void setPriority(byte priority) {
62          if (priority < 0 || priority > 7) {
63              throw new IllegalArgumentException(
64                      "Priority must be between 0 and 7 inclusive: " + priority);
65          }
66          this.priority = priority;
67      }
68  
69      public boolean isUnidirectional() {
70          return unidirectional;
71      }
72  
73      public void setUnidirectional(boolean unidirectional) {
74          this.unidirectional = unidirectional;
75      }
76  
77      @Override
78      public String toString() {
79          StringBuilder buf = new StringBuilder();
80          buf.append(getClass().getSimpleName());
81          buf.append("(last: ");
82          buf.append(isLast());
83          buf.append("; unidirectional: ");
84          buf.append(isUnidirectional());
85          buf.append(')');
86          buf.append(StringUtil.NEWLINE);
87          buf.append("--> Stream-ID = ");
88          buf.append(getStreamId());
89          buf.append(StringUtil.NEWLINE);
90          if (associatedToStreamId != 0) {
91              buf.append("--> Associated-To-Stream-ID = ");
92              buf.append(getAssociatedToStreamId());
93              buf.append(StringUtil.NEWLINE);
94          }
95          buf.append("--> Priority = ");
96          buf.append(getPriority());
97          buf.append(StringUtil.NEWLINE);
98          buf.append("--> Headers:");
99          buf.append(StringUtil.NEWLINE);
100         appendHeaders(buf);
101 
102         // Remove the last newline.
103         buf.setLength(buf.length() - StringUtil.NEWLINE.length());
104         return buf.toString();
105     }
106 }