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; 20 21 import org.eclipse.jetty.io.Buffer; 22 import org.eclipse.jetty.io.Buffers; 23 import org.eclipse.jetty.io.Buffers.Type; 24 import org.eclipse.jetty.io.BuffersFactory; 25 26 27 /* ------------------------------------------------------------ */ 28 /** The WebSocket Buffer Pool. 29 * 30 * The normal buffers are byte array buffers so that user processes 31 * can access directly. However the generator uses direct buffers 32 * for the final output stage as they are filled in bulk and are more 33 * efficient to flush. 34 */ 35 public class WebSocketBuffers 36 { 37 final private int _bufferSize; 38 final private Buffers _buffers; 39 40 public WebSocketBuffers(final int bufferSize) 41 { 42 _bufferSize=bufferSize; 43 _buffers = BuffersFactory.newBuffers(Type.DIRECT,bufferSize,Type.INDIRECT,bufferSize,Type.INDIRECT,-1); 44 } 45 46 public Buffer getBuffer() 47 { 48 return _buffers.getBuffer(); 49 } 50 51 public Buffer getDirectBuffer() 52 { 53 return _buffers.getHeader(); 54 } 55 56 public void returnBuffer(Buffer buffer) 57 { 58 _buffers.returnBuffer(buffer); 59 } 60 61 public int getBufferSize() 62 { 63 return _bufferSize; 64 } 65 }