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.common.extensions.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.util.StringUtil;
26  import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
27  import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
28  
29  public class MuxAddChannelRequest implements MuxControlBlock
30  {
31      public static final byte IDENTITY_ENCODING = (byte)0x00;
32      public static final byte DELTA_ENCODING = (byte)0x01;
33  
34      private long channelId = -1;
35      private byte encoding;
36      private ByteBuffer handshake;
37      private byte rsv;
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_REQUEST;
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 isIdentityEncoded()
80      {
81          return (encoding == IDENTITY_ENCODING);
82      }
83  
84      public void setChannelId(long channelId)
85      {
86          this.channelId = channelId;
87      }
88  
89      public void setEncoding(byte enc)
90      {
91          this.encoding = enc;
92      }
93  
94      public void setHandshake(ByteBuffer handshake)
95      {
96          if (handshake == null)
97          {
98              this.handshake = null;
99          }
100         else
101         {
102             this.handshake = handshake.slice();
103         }
104     }
105 
106     public void setHandshake(String rawstring)
107     {
108         setHandshake(BufferUtil.toBuffer(rawstring, StandardCharsets.UTF_8));
109     }
110 
111     public void setRsv(byte rsv)
112     {
113         this.rsv = rsv;
114     }
115 }