View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2011 Intalio, Inc.
3    * ======================================================================
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the Eclipse Public License v1.0
6    * and Apache License v2.0 which accompanies this distribution.
7    *
8    *   The Eclipse Public License is available at
9    *   http://www.eclipse.org/legal/epl-v10.html
10   *
11   *   The Apache License v2.0 is available at
12   *   http://www.opensource.org/licenses/apache2.0.php
13   *
14   * You may elect to redistribute this code under either of these licenses.
15   *******************************************************************************/
16  // ========================================================================
17  // Copyright (c) 2010 Mort Bay Consulting Pty. Ltd.
18  // ------------------------------------------------------------------------
19  // All rights reserved. This program and the accompanying materials
20  // are made available under the terms of the Eclipse Public License v1.0
21  // and Apache License v2.0 which accompanies this distribution.
22  // The Eclipse Public License is available at
23  // http://www.eclipse.org/legal/epl-v10.html
24  // The Apache License v2.0 is available at
25  // http://www.opensource.org/licenses/apache2.0.php
26  // You may elect to redistribute this code under either of these licenses.
27  // ========================================================================
28  
29  package org.eclipse.jetty.websocket;
30  
31  import org.eclipse.jetty.io.Buffer;
32  import org.eclipse.jetty.io.Buffers;
33  import org.eclipse.jetty.io.Buffers.Type;
34  import org.eclipse.jetty.io.BuffersFactory;
35  
36  
37  /* ------------------------------------------------------------ */
38  /** The WebSocket Buffer Pool.
39   *
40   * The normal buffers are byte array buffers so that user processes
41   * can access directly.   However the generator uses direct buffers
42   * for the final output stage as they are filled in bulk and are more
43   * efficient to flush.
44   */
45  public class WebSocketBuffers
46  {
47      final private int _bufferSize;
48      final private Buffers _buffers;
49  
50      public WebSocketBuffers(final int bufferSize)
51      {
52          _bufferSize=bufferSize;
53          _buffers = BuffersFactory.newBuffers(Type.DIRECT,bufferSize,Type.INDIRECT,bufferSize,Type.INDIRECT,-1);
54      }
55  
56      public Buffer getBuffer()
57      {
58          return _buffers.getBuffer();
59      }
60  
61      public Buffer getDirectBuffer()
62      {
63          return _buffers.getHeader();
64      }
65  
66      public void returnBuffer(Buffer buffer)
67      {
68          _buffers.returnBuffer(buffer);
69      }
70  
71      public int getBufferSize()
72      {
73          return _bufferSize;
74      }
75  }