View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
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 MuxAddChannelRequest 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 = -1;
34      private byte encoding;
35      private ByteBuffer handshake;
36      private byte rsv;
37  
38      public long getChannelId()
39      {
40          return channelId;
41      }
42  
43      public byte getEncoding()
44      {
45          return encoding;
46      }
47  
48      public ByteBuffer getHandshake()
49      {
50          return handshake;
51      }
52  
53      public long getHandshakeSize()
54      {
55          if (handshake == null)
56          {
57              return 0;
58          }
59          return handshake.remaining();
60      }
61  
62      @Override
63      public int getOpCode()
64      {
65          return MuxOp.ADD_CHANNEL_REQUEST;
66      }
67  
68      public byte getRsv()
69      {
70          return rsv;
71      }
72  
73      public boolean isDeltaEncoded()
74      {
75          return (encoding == DELTA_ENCODING);
76      }
77  
78      public boolean isIdentityEncoded()
79      {
80          return (encoding == IDENTITY_ENCODING);
81      }
82  
83      public void setChannelId(long channelId)
84      {
85          this.channelId = channelId;
86      }
87  
88      public void setEncoding(byte enc)
89      {
90          this.encoding = enc;
91      }
92  
93      public void setHandshake(ByteBuffer handshake)
94      {
95          if (handshake == null)
96          {
97              this.handshake = null;
98          }
99          else
100         {
101             this.handshake = handshake.slice();
102         }
103     }
104 
105     public void setHandshake(String rawstring)
106     {
107         setHandshake(BufferUtil.toBuffer(rawstring, StandardCharsets.UTF_8));
108     }
109 
110     public void setRsv(byte rsv)
111     {
112         this.rsv = rsv;
113     }
114 }