1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.websocket.common.extensions.mux.op;
20
21 import java.nio.ByteBuffer;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
26 import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
27
28 public class MuxDropChannel implements MuxControlBlock
29 {
30
31
32
33 public static enum Reason
34 {
35
36 NORMAL_CLOSURE(1000),
37
38
39 PHYSICAL_CONNECTION_FAILED(2000),
40 INVALID_ENCAPSULATING_MESSAGE(2001),
41 CHANNEL_ID_TRUNCATED(2002),
42 ENCAPSULATED_FRAME_TRUNCATED(2003),
43 UNKNOWN_MUX_CONTROL_OPC(2004),
44 UNKNOWN_MUX_CONTROL_BLOCK(2005),
45 CHANNEL_ALREADY_EXISTS(2006),
46 NEW_CHANNEL_SLOT_VIOLATION(2007),
47 NEW_CHANNEL_SLOT_OVERFLOW(2008),
48 BAD_REQUEST(2009),
49 UNKNOWN_REQUEST_ENCODING(2010),
50 BAD_RESPONSE(2011),
51 UNKNOWN_RESPONSE_ENCODING(2012),
52
53
54 LOGICAL_CHANNEL_FAILED(3000),
55 SEND_QUOTA_VIOLATION(3005),
56 SEND_QUOTA_OVERFLOW(3006),
57 IDLE_TIMEOUT(3007),
58 DROP_CHANNEL_ACK(3008),
59
60
61 USE_ANOTHER_PHYSICAL_CONNECTION(4001),
62 BUSY(4002);
63
64 private static final Map<Integer, Reason> codeMap;
65
66 static
67 {
68 codeMap = new HashMap<>();
69 for (Reason r : values())
70 {
71 codeMap.put(r.getValue(),r);
72 }
73 }
74
75 public static Reason valueOf(int code)
76 {
77 return codeMap.get(code);
78 }
79
80 private final int code;
81
82 private Reason(int code)
83 {
84 this.code = code;
85 }
86
87 public int getValue()
88 {
89 return code;
90 }
91 }
92
93 public static MuxDropChannel parse(long channelId, ByteBuffer payload)
94 {
95
96 return null;
97 }
98
99 private final long channelId;
100 private final Reason code;
101 private String phrase;
102 private int rsv;
103
104
105
106
107
108
109
110 public MuxDropChannel(long channelId)
111 {
112 this(channelId,Reason.NORMAL_CLOSURE,null);
113 }
114
115
116
117
118
119
120
121
122
123
124
125 public MuxDropChannel(long channelId, int code, String phrase)
126 {
127 this(channelId, Reason.valueOf(code), phrase);
128 }
129
130
131
132
133
134
135
136
137
138
139
140 public MuxDropChannel(long channelId, Reason code, String phrase)
141 {
142 this.channelId = channelId;
143 this.code = code;
144 this.phrase = phrase;
145 }
146
147 public ByteBuffer asReasonBuffer()
148 {
149
150 return null;
151 }
152
153 public long getChannelId()
154 {
155 return channelId;
156 }
157
158 public Reason getCode()
159 {
160 return code;
161 }
162
163 @Override
164 public int getOpCode()
165 {
166 return MuxOp.DROP_CHANNEL;
167 }
168
169 public String getPhrase()
170 {
171 return phrase;
172 }
173
174 public int getRsv()
175 {
176 return rsv;
177 }
178
179 public void setRsv(int rsv)
180 {
181 this.rsv = rsv;
182 }
183 }