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.frames;
20  
21  import org.eclipse.jetty.io.ByteBufferPool;
22  import org.eclipse.jetty.websocket.api.extensions.Frame;
23  import org.eclipse.jetty.websocket.common.OpCode;
24  import org.eclipse.jetty.websocket.common.WebSocketFrame;
25  
26  /**
27   * A Data Frame
28   */
29  public class DataFrame extends WebSocketFrame
30  {
31      private boolean isPooledBuffer = false;
32  
33      protected DataFrame(byte opcode)
34      {
35          super(opcode);
36      }
37  
38      /**
39       * Construct new DataFrame based on headers of provided frame.
40       * <p>
41       * Useful for when working in extensions and a new frame needs to be created.
42       */
43      public DataFrame(Frame basedOn)
44      {
45          this(basedOn,false);
46      }
47  
48      /**
49       * Construct new DataFrame based on headers of provided frame, overriding for continuations if needed.
50       * <p>
51       * Useful for when working in extensions and a new frame needs to be created.
52       */
53      public DataFrame(Frame basedOn, boolean continuation)
54      {
55          super(basedOn.getOpCode());
56          copyHeaders(basedOn);
57          if (continuation)
58          {
59              setOpCode(OpCode.CONTINUATION);
60          }
61      }
62  
63      @Override
64      public void assertValid()
65      {
66          /* no extra validation for data frames (yet) here */
67      }
68  
69      @Override
70      public boolean isControlFrame()
71      {
72          return false;
73      }
74  
75      @Override
76      public boolean isDataFrame()
77      {
78          return true;
79      }
80  
81      /**
82       * @return true if payload buffer is from a {@link ByteBufferPool} and can be released when appropriate to do so
83       */
84      public boolean isPooledBuffer()
85      {
86          return isPooledBuffer;
87      }
88  
89      /**
90       * Set the data frame to continuation mode
91       */
92      public void setIsContinuation()
93      {
94          setOpCode(OpCode.CONTINUATION);
95      }
96  
97      /**
98       * Sets a flag indicating that the underlying payload is from a {@link ByteBufferPool} and can be released when appropriate to do so
99       */
100     public void setPooledBuffer(boolean isPooledBuffer)
101     {
102         this.isPooledBuffer = isPooledBuffer;
103     }
104 }