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  
23  import org.eclipse.jetty.util.BufferUtil;
24  import org.eclipse.jetty.util.StringUtil;
25  import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
26  import org.eclipse.jetty.websocket.common.extensions.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,StringUtil.__UTF8_CHARSET));
119     }
120 
121     public void setRsv(byte rsv)
122     {
123         this.rsv = rsv;
124     }
125 }