View Javadoc

1   /*
2    * Copyright 2012 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 DefaultSpdyHeaderBlock
24          implements SpdySynStreamFrame {
25  
26      private int streamId;
27      private int associatedToStreamId;
28      private byte priority;
29      private boolean last;
30      private boolean unidirectional;
31  
32      /**
33       * Creates a new instance.
34       *
35       * @param streamID             the Stream-ID of this frame
36       * @param associatedToStreamId the Associated-To-Stream-ID of this frame
37       * @param priority             the priority of the stream
38       */
39      public DefaultSpdySynStreamFrame(
40              int streamID, int associatedToStreamId, byte priority) {
41          setStreamId(streamID);
42          setAssociatedToStreamId(associatedToStreamId);
43          setPriority(priority);
44      }
45  
46      @Deprecated
47      public int getStreamID() {
48          return getStreamId();
49      }
50  
51      public int getStreamId() {
52          return streamId;
53      }
54  
55      @Deprecated
56      public void setStreamID(int streamId) {
57          setStreamId(streamId);
58      }
59  
60      public void setStreamId(int streamId) {
61          if (streamId <= 0) {
62              throw new IllegalArgumentException(
63                      "Stream-ID must be positive: " + streamId);
64          }
65          this.streamId = streamId;
66      }
67  
68      @Deprecated
69      public int getAssociatedToStreamID() {
70          return getAssociatedToStreamId();
71      }
72  
73      public int getAssociatedToStreamId() {
74          return associatedToStreamId;
75      }
76  
77      @Deprecated
78      public void setAssociatedToStreamID(int associatedToStreamId) {
79          setAssociatedToStreamId(associatedToStreamId);
80      }
81  
82      public void setAssociatedToStreamId(int associatedToStreamId) {
83          if (associatedToStreamId < 0) {
84              throw new IllegalArgumentException(
85                      "Associated-To-Stream-ID cannot be negative: " +
86                      associatedToStreamId);
87          }
88          this.associatedToStreamId = associatedToStreamId;
89      }
90  
91      public byte getPriority() {
92          return priority;
93      }
94  
95      public void setPriority(byte priority) {
96          if (priority < 0 || priority > 7) {
97              throw new IllegalArgumentException(
98                      "Priority must be between 0 and 7 inclusive: " + priority);
99          }
100         this.priority = priority;
101     }
102 
103     public boolean isLast() {
104         return last;
105     }
106 
107     public void setLast(boolean last) {
108         this.last = last;
109     }
110 
111     public boolean isUnidirectional() {
112         return unidirectional;
113     }
114 
115     public void setUnidirectional(boolean unidirectional) {
116         this.unidirectional = unidirectional;
117     }
118 
119     @Override
120     public String toString() {
121         StringBuilder buf = new StringBuilder();
122         buf.append(getClass().getSimpleName());
123         buf.append("(last: ");
124         buf.append(isLast());
125         buf.append("; unidirectional: ");
126         buf.append(isUnidirectional());
127         buf.append(')');
128         buf.append(StringUtil.NEWLINE);
129         buf.append("--> Stream-ID = ");
130         buf.append(streamId);
131         buf.append(StringUtil.NEWLINE);
132         if (associatedToStreamId != 0) {
133             buf.append("--> Associated-To-Stream-ID = ");
134             buf.append(associatedToStreamId);
135             buf.append(StringUtil.NEWLINE);
136         }
137         buf.append("--> Priority = ");
138         buf.append(priority);
139         buf.append(StringUtil.NEWLINE);
140         buf.append("--> Headers:");
141         buf.append(StringUtil.NEWLINE);
142         appendHeaders(buf);
143 
144         // Remove the last newline.
145         buf.setLength(buf.length() - StringUtil.NEWLINE.length());
146         return buf.toString();
147     }
148 }