Project

General

Profile

« Previous | Next » 

Revision 46765

Need synchronized next() method to avoid issues when collecting while getting the wf status/history

View differences:

modules/dnet-data-services/branches/saxonHE/src/main/java/eu/dnetlib/data/collector/ThreadSafeIterator.java
1
package eu.dnetlib.data.collector;
2

  
3
import java.util.Iterator;
4

  
5
/**
6
 * Created by Alessia Bardi on 10/04/17.
7
 *
8
 * Use this class instead of plain Iterator<String> when implementing new plugins in order to avoid problems when collecting while clicking on the workflow history.
9
 *
10
 * @author Alessia Bardi
11
 */
12
public abstract class ThreadSafeIterator implements Iterator<String> {
13

  
14
	@Override
15
	public boolean hasNext() {
16
		return doHasNext();
17
	}
18

  
19
	@Override
20
	public synchronized String next() {
21
		return doNext();
22
	}
23

  
24
	public abstract boolean doHasNext();
25
	public abstract String doNext();
26

  
27
	@Override
28
	public void remove() {
29
		throw new UnsupportedOperationException();
30
	}
31
}
modules/dnet-data-services/branches/saxonHE/src/main/java/eu/dnetlib/data/collector/plugins/sftp/SftpIterator.java
10 10
import java.util.*;
11 11

  
12 12
import com.jcraft.jsch.*;
13
import eu.dnetlib.data.collector.ThreadSafeIterator;
13 14
import eu.dnetlib.rmi.data.CollectorServiceRuntimeException;
14 15
import org.apache.commons.io.output.ByteArrayOutputStream;
15 16
import org.apache.commons.lang3.StringUtils;
......
19 20
/**
20 21
 * Created by andrea on 11/01/16.
21 22
 */
22
public class SftpIterator implements Iterator<String> {
23
public class SftpIterator extends ThreadSafeIterator {
23 24

  
24 25
	private static final Log log = LogFactory.getLog(SftpIterator.class);
25 26

  
......
214 215
	}
215 216

  
216 217
	@Override
217
	public boolean hasNext() {
218
	public boolean doHasNext() {
218 219
		return !queue.isEmpty();
219 220
	}
220 221

  
221 222
	@Override
222
	public String next() {
223
	public String doNext() {
224
		if(queue.isEmpty())
225
			throw new CollectorServiceRuntimeException("Unexpected empty queue in next()");
223 226
		String nextRemotePath = queue.remove();
224 227
		int nRepeat = 0;
225 228
		String fullPathFile = "";

Also available in: Unified diff