Commit eaf27c6c authored by gmantele's avatar gmantele
Browse files

[UWS,TAP] Add clean release of all resources (e.g. Threads, Timers, DB...

[UWS,TAP] Add clean release of all resources (e.g. Threads, Timers, DB connections) allocated in a UWS and a TAP service. Small changes of the UWS API...but only if ExecutionManager, DestructionManager and UWS have been implemented by library users rather than using the default implementation.
parent 2cb0054b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -215,6 +215,7 @@ public abstract class AbstractTAPFactory extends TAPFactory {
	public UWSService createUWS() throws TAPException{
		try{
			UWSService uws = new UWSService(this, this.service.getFileManager(), this.service.getLogger());
			uws.setName("TAP/async");
			uws.setErrorWriter(errorWriter);
			return uws;
		}catch(UWSException ue){
+17 −1
Original line number Diff line number Diff line
@@ -91,7 +91,8 @@ public interface ServiceConnection {

	/**
	 * <i><b>[MANDATORY]</b></i>
	 * <p>This function controls the state of the whole TAP service.</p>
	 * <p>This function tells whether the TAP service is available
	 * (that's to say, "able to execute requests" ; resources like /availability, /capabilities and /tables may still work).</p>
	 * 
	 * <p>
	 * 	A message explaining the current state of the TAP service could be provided thanks to {@link #getAvailability()}.
@@ -111,6 +112,21 @@ public interface ServiceConnection {
	 */
	public String getAvailability();

	/**
	 * <i><b>[MANDATORY]</b></i>
	 * <p>This function sets the state of the whole TAP service.
	 * 	If true, all TAP resources will be able to execute resources.
	 * 	If false, /sync and /async won't answer any more to requests and a HTTP-503 (Service unavailable)
	 * 	error will be returned.
	 * </p>
	 * 
	 * @param isAvailable	<i>true</i> to enable all resources, <i>false</i> to forbid /sync and /async (all other resources will still be available).
	 * @param message		A message describing the current state of the service. If NULL, a default message may be set by the library.
	 * 
	 * @since 2.0
	 */
	public void setAvailable(final boolean isAvailable, final String message);

	/**
	 * <i>[OPTIONAL]</i>
	 * <p>Get the limit of the retention period.</p>
+20 −2
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ import adql.query.ADQLQuery;
 * </ul>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (11/2014)
 * @version 2.0 (12/2014)
 */
public abstract class TAPFactory implements UWSFactory {

@@ -90,7 +90,7 @@ public abstract class TAPFactory implements UWSFactory {
	 * 
	 * @return	The error writer to use.
	 * 
	 * @since 4.1
	 * @since 2.0
	 */
	public abstract ServiceErrorWriter getErrorWriter();

@@ -125,6 +125,8 @@ public abstract class TAPFactory implements UWSFactory {
	 * @return	A new and free connection to the database. <b>MUST BE NOT NULL, or otherwise a TAPException should be returned.</b>
	 * 
	 * @throws TAPException	If there is any error while getting a free connection.
	 * 
	 * @since 2.0
	 */
	public abstract DBConnection getConnection(final String jobID) throws TAPException;

@@ -142,6 +144,8 @@ public abstract class TAPFactory implements UWSFactory {
	 * </i></p>
	 * 
	 * @param conn	The connection to close.
	 * 
	 * @since 2.0
	 */
	public abstract void freeConnection(final DBConnection conn);

@@ -163,9 +167,23 @@ public abstract class TAPFactory implements UWSFactory {
	 * 
	 * @return	The number of connections still available,
	 *        	or <=0 in case of problem (<i>note: in this case, the error must be logged in the implementation of this function</i>).
	 * 
	 * @since 2.0
	 */
	public abstract int countFreeConnections();

	/**
	 * <p>Destroy all resources (and particularly DB connections and JDBC driver) allocated in this factory.</p>
	 * 
	 * <p><i>Note:
	 * 	This function is called when the TAP service is shutting down.
	 * 	After this call, the factory may not be able to provide any closed resources ; its behavior may be unpredictable.
	 * </i></p>
	 * 
	 * @since 2.0
	 */
	public abstract void destroy();

	/* *************** */
	/* ADQL MANAGEMENT */
	/* *************** */
+2 −1
Original line number Diff line number Diff line
@@ -175,7 +175,8 @@ public class ASync implements TAPResource {

	@Override
	public void destroy(){
		;
		if (uws != null)
			uws.destroy();
	}

	@Override
+10 −0
Original line number Diff line number Diff line
@@ -154,8 +154,18 @@ public class TAP implements VOSIResource {
	 * @see TAPResource#destroy()
	 */
	public void destroy(){
		// Set the availability to "false" and the reason to "The application server is stopping!":
		service.setAvailable(false, "The application server is stopping!");

		// Destroy all web resources:
		for(TAPResource res : resources.values())
			res.destroy();

		// Destroy also all resources allocated in the factory:
		service.getFactory().destroy();

		// Log the end:
		getLogger().logTAP(LogLevel.INFO, this, "STOP", "TAP Service stopped!", null);
	}

	/**
Loading