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