Strabon

changeset 1354:a4c6d008a576

Fixes Bug #40: StrabonBeanWrapper now registers a handler for SIGTERM signal, so as if Strabon Endpoint is run from the command-line (endpoint-exec), then the closing of the connection will be ultimately called.
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Sep 11 15:20:14 2014 +0300 (2014-09-11)
parents 7c0e94008b62
children c4055a32472c
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Wed Sep 10 11:46:14 2014 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Thu Sep 11 15:20:14 2014 +0300
     1.3 @@ -152,7 +152,8 @@
     1.4  					// use PostGIS as the default database backend
     1.5  					this.strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, user, password, port, serverName, checkForLockTable);	
     1.6  				}
     1.7 -				
     1.8 +
     1.9 +				installSIGTERMHandler(this.strabon);
    1.10  				
    1.11  			} catch (Exception e) {
    1.12  				logger.error("[StrabonEndpoint] Exception occured while creating Strabon. {}\n{}", e.getMessage(), this.getDetails());
    1.13 @@ -163,6 +164,33 @@
    1.14  		return true;
    1.15  	}
    1.16  
    1.17 +	/**
    1.18 +	 * Registers a handler for SIGTERM signals, like Ctrl-C. One may send such a signal
    1.19 +	 * at the command prompt, when running Strabon Endpoint from the command line, i.e.,
    1.20 +	 * using the endpoint-exec module.   
    1.21 +	 * 
    1.22 +	 * @param strabon The strabon instance
    1.23 +	 */
    1.24 +	private static void installSIGTERMHandler(final Strabon strabon) {
    1.25 +		if (logger.isDebugEnabled()) {
    1.26 +			logger.info("[StrabonEndpoint] Installing handler for SIGTERM signals...");
    1.27 +		}
    1.28 +		
    1.29 +		// register the handler
    1.30 +		Runtime.getRuntime().addShutdownHook(new Thread() {
    1.31 +			
    1.32 +			@Override
    1.33 +			public void run() {
    1.34 +				// just call the Strabon.close() method
    1.35 +				strabon.close();
    1.36 +			}
    1.37 +		});
    1.38 +		
    1.39 +		if (logger.isDebugEnabled()) {
    1.40 +			logger.info("[StrabonEndpoint] Handler for SIGTERM signals installed successfully.");
    1.41 +		}
    1.42 +	}
    1.43 +	
    1.44  	public Strabon getStrabon() {
    1.45  		return strabon;
    1.46  	}