Skip to content

Commit

Permalink
Memory improvement : uses Queue when reading a collection from WS to
Browse files Browse the repository at this point in the history
allow items cleaning during the step
  • Loading branch information
jrrdev committed Jun 18, 2016
1 parent d67baff commit 0e3cb19
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/
package com.github.jrrdev.mantisbtsync.core.common.readers;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

import org.apache.axis.client.Stub;
import org.apache.axis.transport.http.HTTPConstants;
import org.springframework.batch.item.ItemReader;
Expand Down Expand Up @@ -52,14 +56,14 @@ public class AxisAuthItemsArrayReader<T> extends
private Stub clientStub;

/**
* Index of the last read item.
* Results array got from the WS.
*/
private int i = -1;
private final Queue<T> items = new LinkedList<T>();

/**
* Results array got from the WS.
* Boolean indicating if the WS call have already been made or not.
*/
private T[] items;
private boolean isCallPerformed = false;


/**
Expand Down Expand Up @@ -104,17 +108,12 @@ public T read() throws Exception {
authManager.getAuthCookie());
}

if (i < 0) {
items = invokeDelegateMethod();
i = -1;
if (!isCallPerformed) {
final T[] itemsArray = invokeDelegateMethod();
isCallPerformed = true;
items.addAll(Arrays.asList(itemsArray));
}

i++;
if (items != null && i < items.length) {
return items[i];
} else {
items = null;
return null;
}
return items.poll();
}
}

0 comments on commit 0e3cb19

Please sign in to comment.