Mentions légales du service

Skip to content
Snippets Groups Projects
Commit a5993b64 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

Got rid of Object.finalize() deprecated in Java 9

parent 3a853065
No related branches found
No related tags found
No related merge requests found
......@@ -122,117 +122,127 @@ public class AlignmentService extends CommonCLI {
public static void main( String[] args ) {
try { new AlignmentService().run( args ); }
catch ( Exception ex ) { logger.error( "FATAL error", ex ); };
catch ( Exception ex ) { logger.error( "FATAL error", ex ); }
}
public void run( String[] args ) throws Exception {
services = new Vector<AlignmentServiceProfile>();
directories = new Hashtable<String,Directory>();
// Read parameters
readParameters( args );
// In principle, this is useless
if ( outputfilename != null ) {
// This redirects error outout to log file given by -o
System.setErr( new PrintStream( outputfilename, StandardCharsets.UTF_8.name() ) );
}
logger.debug("Parameter parsed");
// Shut down hook
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run() { close(); } });
// Connect database
// It may be useful to create a switch to use a simple volatilCache: nodb
// This requires simple but deeper changes
// (do not put as default for compatibility)
if ( DBMS.equals("postgres") ) {
logger.debug("postgres driver");
if ( DBPORT == null ) DBPORT = "5432";
connection = new DBServiceImpl( "org.postgresql.Driver", "jdbc:postgresql", DBPORT, OPTION );
} else if ( DBMS.equals("mysql") ) {
logger.debug("mysql driver");
if ( DBPORT == null ) DBPORT = "3306";
connection = new DBServiceImpl( "com.mysql.jc.jdbc.Driver", "jdbc:mysql", DBPORT, OPTION );
} else {
logger.error( "Unsupported JDBC driver: {}", DBMS );
usage(-1);
}
try {
logger.debug("Connecting to database");
connection.init();
connection.connect( DBHOST, DBPORT, DBUSER, DBPASS, DBBASE );
} catch ( Exception ex ) {
logger.error( "Cannot connect to database : {}", ex.getMessage() );
System.exit(-1);
}
logger.debug("Database connected");
// Create a AServProtocolManager
manager = new AServProtocolManager( directories );
manager.init( connection, parameters );
logger.debug("Manager created");
// Launch services
for ( AlignmentServiceProfile serv : services ) {
try {
serv.init( parameters, manager );
} catch ( AServException ex ) { // This should rather be the job of the caller
logger.warn( "Cannot start {} service on {}:{}", serv );
services = new Vector<AlignmentServiceProfile>();
directories = new Hashtable<String,Directory>();
// Read parameters
readParameters( args );
// In principle, this is useless
if ( outputfilename != null ) {
// This redirects error outout to log file given by -o
System.setErr( new PrintStream( outputfilename, StandardCharsets.UTF_8.name() ) );
}
logger.debug("Parameter parsed");
// Shut down hook
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run() { close(); } });
// Connect database
// It may be useful to create a switch to use a simple volatilCache: nodb
// This requires simple but deeper changes
// (do not put as default for compatibility)
if ( DBMS.equals("postgres") ) {
logger.debug("postgres driver");
if ( DBPORT == null ) DBPORT = "5432";
connection = new DBServiceImpl( "org.postgresql.Driver", "jdbc:postgresql", DBPORT, OPTION );
} else if ( DBMS.equals("mysql") ) {
logger.debug("mysql driver");
if ( DBPORT == null ) DBPORT = "3306";
connection = new DBServiceImpl( "com.mysql.jc.jdbc.Driver", "jdbc:mysql", DBPORT, OPTION );
} else {
logger.error( "Unsupported JDBC driver: {}", DBMS );
usage(-1);
}
}
logger.debug("Services launched");
// Register to directories
for ( Directory dir : directories.values() ) {
try {
dir.open( parameters );
logger.debug("{} connected.", dir);
} catch ( AServException ex ) {
logger.warn( "Cannot connect to {} directory", dir );
logger.debug( "IGNORED Connection exception", ex );
// JE: this has to be done
//directories.remove( name, dir );
logger.debug("Connecting to database");
connection.init();
connection.connect( DBHOST, DBPORT, DBUSER, DBPASS, DBBASE );
} catch ( Exception ex ) {
logger.error( "Cannot connect to database : {}", ex.getMessage() );
System.exit(-1);
}
}
logger.debug("Directories registered");
logger.debug("Database connected");
// Create a AServProtocolManager
manager = new AServProtocolManager( directories );
manager.init( connection, parameters );
logger.debug("Manager created");
// Launch services
for ( AlignmentServiceProfile serv : services ) {
try {
serv.init( parameters, manager );
} catch ( AServException ex ) { // This should rather be the job of the caller
logger.warn( "Cannot start {} service on {}:{}", serv );
}
}
logger.debug("Services launched");
// Register to directories
for ( Directory dir : directories.values() ) {
try {
dir.open( parameters );
logger.debug("{} connected.", dir);
} catch ( AServException ex ) {
logger.warn( "Cannot connect to {} directory", dir );
logger.debug( "IGNORED Connection exception", ex );
// JE: this has to be done
//directories.remove( name, dir );
}
}
logger.debug("Directories registered");
init( parameters );
init( parameters );
// Enables transports (here only HTTP)
if ( parameters.getProperty( "http" ) != null ) { // Possible to have http-less server
try {
transport = new HTTPTransport();
transport.init( parameters, manager, services );
} catch ( AServException ex ) {
logger.error( "Cannot start HTTP transport on {}:{}", parameters.getProperty( "host" ), parameters.getProperty( "http" ) );
usage(-1);
// Enables transports (here only HTTP)
if ( parameters.getProperty( "http" ) != null ) { // Possible to have http-less server
try {
transport = new HTTPTransport();
transport.init( parameters, manager, services );
} catch ( AServException ex ) {
logger.error( "Cannot start HTTP transport on {}:{}", parameters.getProperty( "host" ), parameters.getProperty( "http" ) );
usage(-1);
}
logger.debug("Transport enabled");
}
logger.debug("Transport enabled");
}
// Wait loop
logger.info("Alignment server running");
while ( true ) {
// do not exhaust CPU
Thread.sleep(1000);
// Wait loop
logger.info("Alignment server running");
while ( true ) {
// do not exhaust CPU
Thread.sleep(1000);
}
}
// JE2020: This is added when suppressing the deprecated finalize()
// Now close is called by both shutdownhhok and here
// Which may cause useless warnings in loggers
finally { close(); }
}
protected void init( Properties parameters ) {
}
protected void close(){
logger.debug("Shuting down server");
// Disable transport
if ( transport != null ) transport.close();
if ( transport != null ) {
transport.close();
transport = null;
}
// [Directory]: unregister to directories
for ( Directory dir : directories.values() ) {
try { dir.close(); }
catch ( AServException ex ) {
try {
dir.close();
} catch ( AServException ex ) {
logger.warn("Cannot unregister from {}", dir);
logger.debug("IGNORED", ex);
}
......@@ -248,18 +258,19 @@ public class AlignmentService extends CommonCLI {
// Shut down database connection
logger.debug("Stopping manager");
if ( manager != null ) manager.close();
if ( manager != null ) {
manager.close();
manager = null;
}
logger.debug("Closing database connection");
connection.close();
logger.info("Alignment server stopped");
if ( connection != null ) {
connection.close();
connection = null;
logger.info("Alignment server stopped");
}
System.err.close();
}
protected void finalize() throws Throwable {
try { close(); }
finally { super.finalize(); }
}
protected Object loadInstance( String className ) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?> cl = Class.forName( className );
java.lang.reflect.Constructor<?> constructor = cl.getConstructor( (Class[])null );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment