summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-03-11 10:15:39 (EDT)
committerEike Stepper2007-03-11 10:15:39 (EDT)
commit843ed0827ae3be04973549c3c6760c4da3871694 (patch)
treec0fa8d684465392a1a5d48cc03a2ab905d8338f1
parentb6103732fdb64f10c1cab2d87c87f3702bd7026d (diff)
downloadcdo-843ed0827ae3be04973549c3c6760c4da3871694.zip
cdo-843ed0827ae3be04973549c3c6760c4da3871694.tar.gz
cdo-843ed0827ae3be04973549c3c6760c4da3871694.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestBufferPool.java92
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportUtil.java2
2 files changed, 93 insertions, 1 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestBufferPool.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestBufferPool.java
new file mode 100644
index 0000000..895d27c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestBufferPool.java
@@ -0,0 +1,92 @@
+/***************************************************************************
+ * Copyright (c) 2004-2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.transport.IBuffer;
+import org.eclipse.net4j.transport.IBufferPool;
+import org.eclipse.net4j.transport.TransportUtil;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author Eike Stepper
+ */
+public class TestBufferPool
+{
+ private static IBufferPool bufferPool = TransportUtil.createBufferPool();
+
+ private static Collection memory = new ArrayList();
+
+ public static void main(String[] args) throws InterruptedException
+ {
+ OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+ OMPlatform.INSTANCE.setDebugging(true);
+ LifecycleUtil.activate(bufferPool);
+
+ IBuffer[] buffers = new IBuffer[10];
+ for (int i = 0; i < buffers.length; i++)
+ {
+ buffers[i] = bufferPool.provideBuffer();
+ }
+
+ for (int i = 0; i < buffers.length; i++)
+ {
+ bufferPool.retainBuffer(buffers[i]);
+ buffers[i] = null;
+ }
+
+ while (TransportUtil.getPooledBuffers(bufferPool) > 0 && allocate())
+ {
+ Thread.sleep(200);
+ ReflectUtil.dump(bufferPool);
+ }
+
+ LifecycleUtil.deactivate(bufferPool);
+ }
+
+ private static void msg()
+ {
+ System.out.println("pooledBuffers = " + TransportUtil.getPooledBuffers(bufferPool));
+ }
+
+ private static boolean allocate()
+ {
+ try
+ {
+ System.out.println("allocating from " + Runtime.getRuntime().freeMemory());
+ for (int i = 0; i < 10; i++)
+ {
+ memory.add(new byte[1000000]);
+ }
+
+ msg();
+ return true;
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
+ }
+
+ @SuppressWarnings("unused")
+ private static void gc()
+ {
+ msg();
+ System.out.println("collecting garbage");
+ System.gc();
+ msg();
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportUtil.java
index 61733e8..053232e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportUtil.java
@@ -31,7 +31,7 @@ public final class TransportUtil
public static IBufferProvider createBufferFactory()
{
- return new BufferFactory(DEFAULT_BUFFER_CAPACITY);
+ return createBufferFactory(DEFAULT_BUFFER_CAPACITY);
}
public static IBufferPool createBufferPool(IBufferProvider factory)