changeset 774:c3e5932e8411

Allocator support
author Devel 2
date Mon, 18 Dec 2017 15:03:41 +0100
parents 5fd3d7d7a21e
children c55915d92f35
files stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataReader.java stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java stress-tester/src/main/java/com/passus/st/source/NcEventSource.java
diffstat 3 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataReader.java	Mon Dec 18 14:39:16 2017 +0100
+++ b/stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataReader.java	Mon Dec 18 15:03:41 2017 +0100
@@ -1,9 +1,12 @@
 package com.passus.st.reader.nc;
 
+import com.passus.commons.Assert;
+import com.passus.data.Allocator;
 import com.passus.data.ByteBuff;
 import com.passus.data.ByteBuffDataSource;
 import com.passus.data.ByteString;
 import com.passus.data.DataSource;
+import com.passus.data.DefaultAllocator;
 import com.passus.data.HeapByteBuff;
 import com.passus.net.http.HttpCachedHeadersImpl;
 import com.passus.net.http.HttpConsts;
@@ -30,6 +33,17 @@
 
     private final NcDataHelper ncDataHelper = NcDataHelper.getInstance();
 
+    private Allocator allocator = new DefaultAllocator();
+
+    public Allocator getAllocator() {
+        return allocator;
+    }
+
+    public void setAllocator(Allocator allocator) {
+        Assert.notNull(allocator, "allocator");
+        this.allocator = allocator;
+    }
+
     private void skipRequest(ByteBuff buffer) throws IOException {
         ncDataHelper.skipByteStringNullTerminated(buffer);
         ncDataHelper.skipByteStringNullTerminated(buffer);
@@ -138,7 +152,7 @@
             return null;
         } else if (contentSize <= Integer.MAX_VALUE) {
             int contentSizeInt = (int) contentSize;
-            ByteBuff data = new HeapByteBuff(contentSizeInt);
+            ByteBuff data = allocator.allocate();
             buffer.read(data, contentSizeInt);
             return new ByteBuffDataSource(data);
         } else {
@@ -214,6 +228,7 @@
             }
         }
 
+        buffer.release();
         return new HttpReqResp(req, resp);
     }
 
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java	Mon Dec 18 14:39:16 2017 +0100
+++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java	Mon Dec 18 15:03:41 2017 +0100
@@ -341,8 +341,9 @@
         if (!skipData) {
             if (payloadBlock.dataSize() <= Integer.MAX_VALUE) {
                 int dataSize = (int) payloadBlock.dataSize();
+                //System.out.println("allocator: " + allocator.getClass());
                 ByteBuff data = allocator.allocate(dataSize);
-
+                //System.out.println("data: " + System.identityHashCode(data));
                 //TODO - Mozna zoptymalizowac. Mozna kopiowac bufor bezposrednio do data
                 readSessionPayloadBlockContent(data, dataSize);
                 payloadBlock.data(data);
--- a/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java	Mon Dec 18 14:39:16 2017 +0100
+++ b/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java	Mon Dec 18 15:03:41 2017 +0100
@@ -131,6 +131,8 @@
             reader.setAllocator(allocator);
             reader.open();
 
+            httpReader.setAllocator(allocator);
+            
             if (parallel) {
                 readerThread = new ReaderThread();
                 readerThread.start();