Skip to content

Commit

Permalink
Simplification of the scheduler/controller operations for experiments
Browse files Browse the repository at this point in the history
This should contribute to loading experiments (headless ones in
particulier) faster.
- Now, headless experiments get a simplified controller w/o threads
- GUI experiments get a controller that contains its own scheduler
thread (in addition to the command thread)
- ExperimentScheduler is removed. All accessess are rerouted to
ExperimentController.
- Better management of the memory in StatusControlContribution (less
creation of garbage)
  • Loading branch information
AlexisDrogoul committed Feb 5, 2022
1 parent 7d8d211 commit f7c6f1e
Show file tree
Hide file tree
Showing 37 changed files with 1,226 additions and 1,356 deletions.
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* GamaSqlConnection.java, in irit.gaml.extensions.database, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* GamaSqlConnection.java, in irit.gaml.extensions.database, is part of the source code of the GAMA modeling and
* simulation platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gama.database.geosql;

Expand Down Expand Up @@ -55,34 +55,34 @@ public class GamaSqlConnection extends GamaGisFile {

/** The Constant MYSQL. */
private static final String MYSQL = "mysql";

/** The Constant POSTGRES. */
private static final String POSTGRES = "postgres";

/** The Constant POSTGIS. */
private static final String POSTGIS = "postgis";

/** The Constant MSSQL. */
private static final String MSSQL = "sqlserver";

/** The Constant SQLITE. */
private static final String SQLITE = "spatialite";

/** The dbtype. */
private String dbtype = "";

/** The host. */
private String host = "";

/** The port. */
private String port = "";

/** The database. */
private String database = "";

/** The user. */
private String user = "";

/** The passwd. */
private String passwd = "";

Expand All @@ -93,7 +93,8 @@ public class GamaSqlConnection extends GamaGisFile {
/**
* Instantiates a new gama sql connection.
*
* @param scope the scope
* @param scope
* the scope
*/
public GamaSqlConnection(final IScope scope) {
super(scope, FileUtils.constructAbsoluteFilePath(scope, "getfun.shp", false), 0);
Expand All @@ -103,8 +104,10 @@ public GamaSqlConnection(final IScope scope) {
/**
* Instantiates a new gama sql connection.
*
* @param scope the scope
* @param params the params
* @param scope
* the scope
* @param params
* the params
*/
private GamaSqlConnection(final IScope scope, final Map<String, Object> params) {
super(scope, FileUtils.constructAbsoluteFilePath(scope, "getfun.shp", false), 0);
Expand All @@ -115,7 +118,8 @@ private GamaSqlConnection(final IScope scope, final Map<String, Object> params)
/**
* Sets the params.
*
* @param scope the new params
* @param scope
* the new params
*/
private void setParams(final IScope scope) {
setConnectionParameters(scope);
Expand All @@ -124,7 +128,8 @@ private void setParams(final IScope scope) {
/**
* Sets the params.
*
* @param params the params
* @param params
* the params
*/
private void setParams(final Map<String, Object> params) {
setConnectionParameters(params);
Expand All @@ -133,7 +138,8 @@ private void setParams(final Map<String, Object> params) {
/**
* Sets the connection parameters.
*
* @param scope the new connection parameters
* @param scope
* the new connection parameters
*/
private void setConnectionParameters(final IScope scope) {
final Map<String, Object> params = (Map<String, Object>) scope.getArg("params", IType.MAP);
Expand All @@ -148,7 +154,8 @@ private void setConnectionParameters(final IScope scope) {
/**
* Sets the connection parameters.
*
* @param params the params
* @param params
* the params
*/
private void setConnectionParameters(final Map<String, Object> params) {
this.dbtype = (String) params.get("dbtype");
Expand All @@ -162,14 +169,15 @@ private void setConnectionParameters(final Map<String, Object> params) {
/**
* Creates the connection params.
*
* @param scope the scope
* @param scope
* the scope
* @return the map
*/
// Connect connection parameters with connection attributes of the object
private Map<String, Object> createConnectionParams(final IScope scope) {
final Map<String, Object> connectionParameters = new HashMap<>();

if (dbtype.equalsIgnoreCase(GamaSqlConnection.POSTGRES) || dbtype.equalsIgnoreCase(GamaSqlConnection.POSTGIS)) {
if (GamaSqlConnection.POSTGRES.equalsIgnoreCase(dbtype) || GamaSqlConnection.POSTGIS.equalsIgnoreCase(dbtype)) {
connectionParameters.put("host", host);
connectionParameters.put("dbtype", dbtype);
connectionParameters.put("port", port);
Expand All @@ -178,22 +186,22 @@ private Map<String, Object> createConnectionParams(final IScope scope) {
connectionParameters.put("passwd", passwd);
// advanced

} else if (dbtype.equalsIgnoreCase(GamaSqlConnection.MYSQL)) {
} else if (GamaSqlConnection.MYSQL.equalsIgnoreCase(dbtype)) {
connectionParameters.put(MySQLDataStoreFactory.DBTYPE.key, dbtype);
connectionParameters.put(JDBCDataStoreFactory.HOST.key, host);
connectionParameters.put(MySQLDataStoreFactory.PORT.key, Integer.valueOf(port));
connectionParameters.put(JDBCDataStoreFactory.DATABASE.key, database);
connectionParameters.put(JDBCDataStoreFactory.USER.key, user);
connectionParameters.put(JDBCDataStoreFactory.PASSWD.key, passwd);
} else if (dbtype.equalsIgnoreCase(GamaSqlConnection.MSSQL)) {
} else if (GamaSqlConnection.MSSQL.equalsIgnoreCase(dbtype)) {
connectionParameters.put("host", host);
connectionParameters.put("dbtype", dbtype);
connectionParameters.put("port", port);
connectionParameters.put("database", database);
connectionParameters.put("user", user);
connectionParameters.put("passwd", passwd);

} else if (dbtype.equalsIgnoreCase(GamaSqlConnection.SQLITE)) {
} else if (GamaSqlConnection.SQLITE.equalsIgnoreCase(dbtype)) {
final String DBRelativeLocation = FileUtils.constructAbsoluteFilePath(scope, database, true);
// String EXTRelativeLocation =
// GamaPreferences.LIB_SPATIALITE.value(scope).getPath();
Expand All @@ -207,9 +215,11 @@ private Map<String, Object> createConnectionParams(final IScope scope) {
/**
* Connect.
*
* @param scope the scope
* @param scope
* the scope
* @return the data store
* @throws Exception the exception
* @throws Exception
* the exception
*/
/*
* Create a connection to database with current connection parameter of the GamaSqlConnection object
Expand All @@ -227,32 +237,33 @@ public DataStore Connect(final IScope scope) throws Exception {
/**
* Close.
*
* @param scope the scope
* @throws GamaRuntimeException the gama runtime exception
* @param scope
* the scope
* @throws GamaRuntimeException
* the gama runtime exception
*/
/*
* Close the current connection of of the GamaSqlConnection object
*/
public void close(final IScope scope) throws GamaRuntimeException {
if (dataStore != null) {
dataStore.dispose();
} else
if (dataStore == null)
throw GamaRuntimeException.error("The connection to " + this.database + " is not opened ", scope);
dataStore.dispose();
}

/**
* Sets the data store.
*
* @param dataStore the new data store
* @param dataStore
* the new data store
*/
public void setDataStore(final DataStore dataStore) {
this.dataStore = dataStore;
}
public void setDataStore(final DataStore dataStore) { this.dataStore = dataStore; }

/**
* Read table.
*
* @param scope the scope
* @param scope
* the scope
*/
private void readTable(final IScope scope) {
final String tableName = (String) scope.getArg("table", IType.STRING);
Expand All @@ -263,9 +274,12 @@ private void readTable(final IScope scope) {
/**
* Read table.
*
* @param scope the scope
* @param tableName the table name
* @param filterStr the filter str
* @param scope
* the scope
* @param tableName
* the table name
* @param filterStr
* the filter str
*/
private void readTable(final IScope scope, final String tableName, final String filterStr) {

Expand All @@ -280,7 +294,7 @@ private void readTable(final IScope scope, final String tableName, final String
// reader = store.getFeatureReader();
// final int i = 0;
while (reader.hasNext()) {
scope.getGui().getStatus(scope).setSubStatusCompletion(index++ / (double) size);
scope.getGui().getStatus().setSubStatusCompletion(index++ / (double) size);
final Feature feature = reader.next();

// DEBUG.LOG("Record " + i++ + ": " +
Expand All @@ -299,7 +313,7 @@ private void readTable(final IScope scope, final String tableName, final String
} catch (final Exception e) {
throw GamaRuntimeException.create(e, scope);
} finally {
scope.getGui().getStatus(scope).endSubStatus("Reading table " + tableName);
scope.getGui().getStatus().endSubStatus("Reading table " + tableName);
}
}

Expand All @@ -316,7 +330,8 @@ protected void fillBuffer(final IScope scope) throws GamaRuntimeException {
/**
* Read.
*
* @param scope the scope
* @param scope
* the scope
*/
public void read(final IScope scope) {
fillBuffer(scope);
Expand All @@ -335,20 +350,24 @@ private static class QueryInfo {

/** The item number. */
private final int itemNumber; // Number of records

/** The env. */
private final Envelope3D env;

/** The features. */
private final SimpleFeatureCollection features; // data/recordsets

/**
* Instantiates a new query info.
*
* @param scope the scope
* @param dStore the d store
* @param tableName the table name
* @param filterStr the filter str
* @param scope
* the scope
* @param dStore
* the d store
* @param tableName
* the table name
* @param filterStr
* the filter str
*/
QueryInfo(final IScope scope, final DataStore dStore, final String tableName, final String filterStr) {

Expand Down Expand Up @@ -404,27 +423,21 @@ private static class QueryInfo {
*
* @return the size
*/
public int getSize() {
return itemNumber;
}
public int getSize() { return itemNumber; }

/**
* Gets the envelope.
*
* @return the envelope
*/
public Envelope3D getEnvelope() {
return env;
}
public Envelope3D getEnvelope() { return env; }

/**
* Gets the record set.
*
* @return the record set
*/
public SimpleFeatureCollection getRecordSet() {
return features;
}
public SimpleFeatureCollection getRecordSet() { return features; }
}// end of class QueryInfo

@Override
Expand Down
7 changes: 3 additions & 4 deletions msi.gama.core/src/msi/gama/common/interfaces/IGui.java
@@ -1,12 +1,11 @@
/*******************************************************************************************************
*
* IGui.java, in msi.gama.core, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* IGui.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gama.common.interfaces;

Expand Down Expand Up @@ -133,7 +132,7 @@ public interface IGui {
* the scope
* @return the status
*/
IStatusDisplayer getStatus(IScope scope);
IStatusDisplayer getStatus();

/**
* Gets the console.
Expand Down
4 changes: 2 additions & 2 deletions msi.gama.core/src/msi/gama/common/util/FileUtils.java
Expand Up @@ -533,7 +533,7 @@ public static String fetchToTempFile(final IScope scope, final URL url) {
String pathName = constructRelativeTempFilePath(scope, url);
final String urlPath = url.toExternalForm();
final String status = "Downloading file " + urlPath.substring(urlPath.lastIndexOf(SEPARATOR));
scope.getGui().getStatus(scope).beginSubStatus(status);
scope.getGui().getStatus().beginSubStatus(status);
final Webb web = WEB.get();
try {
try (InputStream in = web.get(urlPath).ensureSuccess()
Expand All @@ -550,7 +550,7 @@ public static String fetchToTempFile(final IScope scope, final URL url) {
} catch (final IOException | WebbException e) {
throw GamaRuntimeException.create(e, scope);
} finally {
scope.getGui().getStatus(scope).endSubStatus(status);
scope.getGui().getStatus().endSubStatus(status);
}
return pathName;
}
Expand Down

0 comments on commit f7c6f1e

Please sign in to comment.