KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > udp > SimpleBufferPool


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.transport.udp;
19
20 import java.nio.ByteBuffer JavaDoc;
21
22 /**
23  * A simple implementation of {@link BufferPool} which does no pooling and just
24  * creates new buffers each time
25  *
26  * @version $Revision: 426366 $
27  */

28 public class SimpleBufferPool implements ByteBufferPool {
29
30     private int defaultSize;
31     private boolean useDirect;
32
33     public SimpleBufferPool() {
34         this(false);
35     }
36
37     public SimpleBufferPool(boolean useDirect) {
38         this.useDirect = useDirect;
39     }
40
41     public synchronized ByteBuffer JavaDoc borrowBuffer() {
42         return createBuffer();
43     }
44
45     public void returnBuffer(ByteBuffer JavaDoc buffer) {
46     }
47
48     public void setDefaultSize(int defaultSize) {
49         this.defaultSize = defaultSize;
50     }
51
52     public boolean isUseDirect() {
53         return useDirect;
54     }
55
56     /**
57      * Sets whether direct buffers are used or not
58      */

59     public void setUseDirect(boolean useDirect) {
60         this.useDirect = useDirect;
61     }
62
63     public void start() throws Exception JavaDoc {
64     }
65
66     public void stop() throws Exception JavaDoc {
67     }
68
69     protected ByteBuffer JavaDoc createBuffer() {
70         if (useDirect) {
71             return ByteBuffer.allocateDirect(defaultSize);
72         }
73         else {
74             return ByteBuffer.allocate(defaultSize);
75         }
76     }
77
78 }
79
Popular Tags