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 * https://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 io.netty.handler.codec.spdy;
17
18 import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
19
20 import io.netty.util.internal.StringUtil;
21
22 /**
23 * The default {@link SpdyGoAwayFrame} implementation.
24 */
25 public class DefaultSpdyGoAwayFrame implements SpdyGoAwayFrame {
26
27 private int lastGoodStreamId;
28 private SpdySessionStatus status;
29
30 /**
31 * Creates a new instance.
32 *
33 * @param lastGoodStreamId the Last-good-stream-ID of this frame
34 */
35 public DefaultSpdyGoAwayFrame(int lastGoodStreamId) {
36 this(lastGoodStreamId, 0);
37 }
38
39 /**
40 * Creates a new instance.
41 *
42 * @param lastGoodStreamId the Last-good-stream-ID of this frame
43 * @param statusCode the Status code of this frame
44 */
45 public DefaultSpdyGoAwayFrame(int lastGoodStreamId, int statusCode) {
46 this(lastGoodStreamId, SpdySessionStatus.valueOf(statusCode));
47 }
48
49 /**
50 * Creates a new instance.
51 *
52 * @param lastGoodStreamId the Last-good-stream-ID of this frame
53 * @param status the status of this frame
54 */
55 public DefaultSpdyGoAwayFrame(int lastGoodStreamId, SpdySessionStatus status) {
56 setLastGoodStreamId(lastGoodStreamId);
57 setStatus(status);
58 }
59
60 @Override
61 public int lastGoodStreamId() {
62 return lastGoodStreamId;
63 }
64
65 @Override
66 public SpdyGoAwayFrame setLastGoodStreamId(int lastGoodStreamId) {
67 checkPositiveOrZero(lastGoodStreamId, "lastGoodStreamId");
68 this.lastGoodStreamId = lastGoodStreamId;
69 return this;
70 }
71
72 @Override
73 public SpdySessionStatus status() {
74 return status;
75 }
76
77 @Override
78 public SpdyGoAwayFrame setStatus(SpdySessionStatus status) {
79 this.status = status;
80 return this;
81 }
82
83 @Override
84 public String toString() {
85 return new StringBuilder()
86 .append(StringUtil.simpleClassName(this))
87 .append(StringUtil.NEWLINE)
88 .append("--> Last-good-stream-ID = ")
89 .append(lastGoodStreamId())
90 .append(StringUtil.NEWLINE)
91 .append("--> Status: ")
92 .append(status())
93 .toString();
94 }
95 }