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 final private int _maxBuffers=-1; 35 36 public WebSocketBuffers(final int bufferSize) 37 { 38 _bufferSize=bufferSize; 39 _buffers = BuffersFactory.newBuffers(Type.DIRECT,bufferSize,Type.INDIRECT,bufferSize,Type.INDIRECT,_maxBuffers); 40 } 41 42 public Buffer getBuffer() 43 { 44 return _buffers.getBuffer(); 45 } 46 47 public Buffer getDirectBuffer() 48 { 49 return _buffers.getHeader(); 50 } 51 52 public void returnBuffer(Buffer buffer) 53 { 54 _buffers.returnBuffer(buffer); 55 } 56 57 public int getBufferSize() 58 { 59 return _bufferSize; 60 } 61 }