1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.websocket.mux.op;
20
21 import java.nio.ByteBuffer;
22 import java.nio.charset.StandardCharsets;
23
24 import org.eclipse.jetty.util.BufferUtil;
25 import org.eclipse.jetty.websocket.mux.MuxControlBlock;
26 import org.eclipse.jetty.websocket.mux.MuxOp;
27
28 public class MuxAddChannelResponse implements MuxControlBlock
29 {
30 public static final byte IDENTITY_ENCODING = (byte)0x00;
31 public static final byte DELTA_ENCODING = (byte)0x01;
32
33 private long channelId;
34 private byte encoding;
35 private byte rsv;
36 private boolean failed = false;
37 private ByteBuffer handshake;
38
39 public long getChannelId()
40 {
41 return channelId;
42 }
43
44 public byte getEncoding()
45 {
46 return encoding;
47 }
48
49 public ByteBuffer getHandshake()
50 {
51 return handshake;
52 }
53
54 public long getHandshakeSize()
55 {
56 if (handshake == null)
57 {
58 return 0;
59 }
60 return handshake.remaining();
61 }
62
63 @Override
64 public int getOpCode()
65 {
66 return MuxOp.ADD_CHANNEL_RESPONSE;
67 }
68
69 public byte getRsv()
70 {
71 return rsv;
72 }
73
74 public boolean isDeltaEncoded()
75 {
76 return (encoding == DELTA_ENCODING);
77 }
78
79 public boolean isFailed()
80 {
81 return failed;
82 }
83
84 public boolean isIdentityEncoded()
85 {
86 return (encoding == IDENTITY_ENCODING);
87 }
88
89 public void setChannelId(long channelId)
90 {
91 this.channelId = channelId;
92 }
93
94 public void setEncoding(byte enc)
95 {
96 this.encoding = enc;
97 }
98
99 public void setFailed(boolean failed)
100 {
101 this.failed = failed;
102 }
103
104 public void setHandshake(ByteBuffer handshake)
105 {
106 if (handshake == null)
107 {
108 this.handshake = null;
109 }
110 else
111 {
112 this.handshake = handshake.slice();
113 }
114 }
115
116 public void setHandshake(String responseHandshake)
117 {
118 setHandshake(BufferUtil.toBuffer(responseHandshake, StandardCharsets.UTF_8));
119 }
120
121 public void setRsv(byte rsv)
122 {
123 this.rsv = rsv;
124 }
125 }