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      public int getStreamID() {
47          return getStreamId();
48      }
49  
50      public int getStreamId() {
51          return streamId;
52      }
53  
54      public void setStreamID(int streamId) {
55          setStreamId(streamId);
56      }
57  
58      public void setStreamId(int streamId) {
59          if (streamId <= 0) {
60              throw new IllegalArgumentException(
61                      "Stream-ID must be positive: " + streamId);
62          }
63          this.streamId = streamId;
64      }
65  
66      public int getAssociatedToStreamID() {
67          return getAssociatedToStreamId();
68      }
69  
70      public int getAssociatedToStreamId() {
71          return associatedToStreamId;
72      }
73  
74      public void setAssociatedToStreamID(int associatedToStreamId) {
75          setAssociatedToStreamId(associatedToStreamId);
76      }
77  
78      public void setAssociatedToStreamId(int associatedToStreamId) {
79          if (associatedToStreamId < 0) {
80              throw new IllegalArgumentException(
81                      "Associated-To-Stream-ID cannot be negative: " +
82                      associatedToStreamId);
83          }
84          this.associatedToStreamId = associatedToStreamId;
85      }
86  
87      public byte getPriority() {
88          return priority;
89      }
90  
91      public void setPriority(byte priority) {
92          if (priority < 0 || priority > 7) {
93              throw new IllegalArgumentException(
94                      "Priority must be between 0 and 7 inclusive: " + priority);
95          }
96          this.priority = priority;
97      }
98  
99      public boolean isLast() {
100         return last;
101     }
102 
103     public void setLast(boolean last) {
104         this.last = last;
105     }
106 
107     public boolean isUnidirectional() {
108         return unidirectional;
109     }
110 
111     public void setUnidirectional(boolean unidirectional) {
112         this.unidirectional = unidirectional;
113     }
114 
115     @Override
116     public String toString() {
117         StringBuilder buf = new StringBuilder();
118         buf.append(getClass().getSimpleName());
119         buf.append("(last: ");
120         buf.append(isLast());
121         buf.append("; unidirectional: ");
122         buf.append(isUnidirectional());
123         buf.append(')');
124         buf.append(StringUtil.NEWLINE);
125         buf.append("--> Stream-ID = ");
126         buf.append(streamId);
127         buf.append(StringUtil.NEWLINE);
128         if (associatedToStreamId != 0) {
129             buf.append("--> Associated-To-Stream-ID = ");
130             buf.append(associatedToStreamId);
131             buf.append(StringUtil.NEWLINE);
132         }
133         buf.append("--> Priority = ");
134         buf.append(priority);
135         buf.append(StringUtil.NEWLINE);
136         buf.append("--> Headers:");
137         buf.append(StringUtil.NEWLINE);
138         appendHeaders(buf);
139 
140         // Remove the last newline.
141         buf.setLength(buf.length() - StringUtil.NEWLINE.length());
142         return buf.toString();
143     }
144 }