Commit 1a698ff6 authored by gmantele's avatar gmantele
Browse files

[TAP] Check ADQLExecutor behavior + Review/Add/Complete Javadoc in all classes...

[TAP] Check ADQLExecutor behavior + Review/Add/Complete Javadoc in all classes of this commit except AsyncThread and TAPParameters + Remake the upload management
parent 68f6acdf
Loading
Loading
Loading
Loading
+392 −46

File changed.

Preview size limit exceeded, changes collapsed.

+0 −13
Original line number Diff line number Diff line
@@ -33,19 +33,6 @@ public class AsyncThread extends JobThread {
		this.executor = executor;
	}

	@Override
	public void interrupt(){
		if (isAlive()){
			try{
				executor.closeDBConnection();
			}catch(TAPException e){
				if (job != null && job.getLogger() != null)
					job.getLogger().error("Can not close the DBConnection for the executing job \"" + job.getJobId() + "\" ! => the job will be probably not totally aborted.", e);
			}
		}
		super.interrupt();
	}

	@Override
	protected void jobWork() throws UWSException, InterruptedException{
		try{
+34 −9
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ import com.oreilly.servlet.multipart.ExceededSizeException;
 * </p>
 * 
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 2.0 (07/2014)
 * @version 2.0 (08/2014)
 * @since 2.0
 */
public class LimitedTableIterator implements TableIterator {
@@ -73,7 +73,7 @@ public class LimitedTableIterator implements TableIterator {
	private boolean overflow = false;

	/**
	 * Wrap the given {@link TableIterator} so that limiting the number of rows to read to the given value.
	 * Wrap the given {@link TableIterator} so that limiting the number of rows to read.
	 * 
	 * @param it		The iterator to wrap. <i>MUST NOT be NULL</i>
	 * @param maxNbRows	Maximum number of rows that can be read. There is overflow if more than this number of rows is asked. <i>A negative value means "no limit".</i>
@@ -86,20 +86,45 @@ public class LimitedTableIterator implements TableIterator {
	}

	/**
	 * Wrap the given {@link TableIterator} so that limiting the number of rows to read to the given value.
	 * <p>Build the specified {@link TableIterator} instance and wrap it so that limiting the number of rows OR bytes to read.</p>
	 * 
	 * @param it		The iterator to wrap. <i>MUST NOT be NULL</i>
	 * @param maxNbRows	Maximum number of rows that can be read. There is overflow if more than this number of rows is asked. <i>A negative value means "no limit".</i>
	 * <p>
	 * 	If the limit is on the <b>number of bytes</b>, the given input stream will be first wrapped inside a {@link LimitedSizeInputStream}.
	 * 	Then, it will be given as only parameter of the constructor of the specified {@link TableIterator} instance.
	 * </p>
	 * 
	 * <p>If the limit is on the <b>number of rows</b>, this {@link LimitedTableIterator} will count and limit itself the number of rows.</p>
	 * 
	 * <p><i><b>IMPORTANT:</b> The specified class must:</i></p>
	 * <i><ul>
	 * 	<li>extend {@link TableIterator},</li>
	 * 	<li>be a concrete class,</li>
	 * 	<li>have at least one constructor with only one parameter of type {@link InputStream}.</li>
	 * </ul></i>
	 * 
	 * <p><i>Note:
	 * 	If the given limit type is NULL (or different from ROWS and BYTES), or the limit value is <=0, no limit will be set.
	 * 	All rows and bytes will be read until the end of input is reached.
	 * </i></p>
	 * 
	 * @param classIt	Class of the {@link TableIterator} implementation to create and whose the output must be limited.
	 * @param input		Input stream toward the table to read.
	 * @param type		Type of the limit: ROWS or BYTES. <i>MAY be NULL</i>
	 * @param limit		Limit in rows or bytes, depending of the "type" parameter. <i>MAY BE <=0</i>
	 * 
	 * @throws DataReadException	If no instance of the given class can be created,
	 *                          	or if the {@link TableIterator} instance can not be initialized,
	 *                          	or if the limit (in rows or bytes) has been reached.
	 */
	public < T extends TableIterator > LimitedTableIterator(final Class<T> classIt, final InputStream input, final LimitUnit type, final int limit) throws DataReadException{
		try{
			Constructor<T> construct = classIt.getConstructor(InputStream.class);
			if (type == LimitUnit.bytes){
			if (type == LimitUnit.bytes && limit > 0){
				maxNbRows = -1;
				innerIt = construct.newInstance(new LimitedSizeInputStream(input, limit));
			}else{
				innerIt = construct.newInstance(input);
				maxNbRows = (type == null) ? -1 : limit;
				maxNbRows = (type == null || type != LimitUnit.rows) ? -1 : limit;
			}
		}catch(InvocationTargetException ite){
			Throwable t = ite.getCause();
@@ -154,7 +179,7 @@ public class LimitedTableIterator implements TableIterator {
	public boolean nextRow() throws DataReadException{
		// Test the overflow flag and proceed only if not overflowed:
		if (overflow)
			throw new DataReadException("Data read overflow: the limit has been reached! No more data can be read.");
			throw new DataReadException("Data read overflow: the limit has already been reached! No more data can be read.");

		// Read the next row:
		boolean nextRow;
@@ -206,7 +231,7 @@ public class LimitedTableIterator implements TableIterator {
	 */
	private void testOverflow() throws IllegalStateException{
		if (overflow)
			throw new IllegalStateException("Data read overflow: the limit has been reached! No more data can be read.");
			throw new IllegalStateException("Data read overflow: the limit has already been reached! No more data can be read.");
	}

	/**
+1 −1
Original line number Diff line number Diff line
@@ -288,7 +288,7 @@ public class TAPParameters extends UWSParameters {
		for(int i = 0; i < pairs.length; i++){
			String[] table = pairs[i].split(",");
			if (table.length != 2)
				throw new TAPException("Bad syntax ! An UPLOAD parameter must contain a list of pairs separated by a ';'. Each pair is composed of 2 parts, a table name and a URI separated by a ','.");
				throw new TAPException("UPLOAD parameter incorrect: bad syntax! An UPLOAD parameter must contain a list of pairs separated by a ';'. Each pair is composed of 2 parts, a table name and a URI separated by a ','.");
			loaders[i] = new TableLoader(table[0], table[1], multipart);
		}

+53 −4
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@ package tap.upload;
 * You should have received a copy of the GNU Lesser General Public License
 * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Copyright 2012 - UDS/Centre de Données astronomiques de Strasbourg (CDS)
 * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

import java.io.IOException;
@@ -25,15 +26,34 @@ import java.security.InvalidParameterException;

import com.oreilly.servlet.multipart.ExceededSizeException;

/**
 * Let limit the number of bytes that can be read from a given input stream.
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (08/2014)
 */
public final class LimitedSizeInputStream extends InputStream {

	/** Input stream whose the number of bytes that can be read must be limited. */
	private final InputStream input;
	/** Maximum number of bytes that can be read. */
	private final long sizeLimit;

	/** Number of bytes currently read. */
	private long counter = 0;

	/** Indicate whether the byte limit has already been reached. If <i>true</i> no more byte can be read ;
	 * all read(...) function will throw an {@link ExceededSizeException}. */
	private boolean exceed = false;

	/**
	 * Wrap the given input stream so that limiting the number of bytes that can be read.
	 * 
	 * @param stream	Stream to limit.
	 * @param sizeLimit	Maximum number of bytes that can be read. <i>If <=0 an {@link InvalidParameterException} will be thrown.</i>
	 * 
	 * @throws NullPointerException	If the input stream is missing.
	 */
	public LimitedSizeInputStream(final InputStream stream, final long sizeLimit) throws NullPointerException{
		if (stream == null)
			throw new NullPointerException("The given input stream is NULL !");
@@ -44,6 +64,26 @@ public final class LimitedSizeInputStream extends InputStream {
		this.sizeLimit = sizeLimit;
	}

	/**
	 * Get the input stream wrapped by this instance of {@link LimitedSizeInputStream}.
	 * 
	 * @return	The wrapped input stream.
	 * @since 2.0
	 */
	public final InputStream getInnerStream(){
		return input;
	}

	/**
	 * <p>Update the number of bytes currently read and them check whether the limit has been exceeded.
	 * If the limit has been exceeded, an {@link ExceededSizeException} is thrown.</p>
	 * 
	 * <p>Besides, the flag {@link #exceed} is set to true in order to forbid the further reading of bytes.</p>
	 * 
	 * @param nbReads	Number of bytes read.
	 * 
	 * @throws ExceededSizeException	If, after update, the limit of bytes has been exceeded.
	 */
	private void updateCounter(final long nbReads) throws ExceededSizeException{
		if (nbReads > 0){
			counter += nbReads;
@@ -54,6 +94,15 @@ public final class LimitedSizeInputStream extends InputStream {
		}
	}

	/**
	 * <p>Tell whether the limit has already been exceeded or not.</p>
	 * 
	 * <p><i>Note:
	 * 	If <i>true</i> is returned, no more read will be allowed, and any attempt to read a byte will throw an {@link ExceededSizeException}.
	 * </i></p>
	 * 
	 * @return	<i>true</i> if the byte limit has been exceeded, <i>false</i> otherwise.
	 */
	public final boolean sizeExceeded(){
		return exceed;
	}
@@ -98,17 +147,17 @@ public final class LimitedSizeInputStream extends InputStream {

	@Override
	public synchronized void mark(int readlimit) throws UnsupportedOperationException{
		throw new UnsupportedOperationException("mark() not supported in a LimitedSizeInputStream !");
		input.mark(readlimit);
	}

	@Override
	public boolean markSupported(){
		return false;
		return input.markSupported();
	}

	@Override
	public synchronized void reset() throws IOException, UnsupportedOperationException{
		throw new UnsupportedOperationException("mark() not supported in a LimitedSizeInputStream !");
		input.reset();
	}

}
Loading