Changeset 7899


Ignore:
Timestamp:
Jan 20, 2021, 1:18:30 PM (2 years ago)
Author:
Nicklas Nordborg
Message:

References #2238: Mark sessions without a logout time as inactive when BASE is starting

Re-factored the Application.start() methods to make it easier to add implement more options without adding more variants of the Application.start() method. Existing options have been ported to all places that use them.

The StartupOptions.autoLogoutSessions() has not been implemented yet.

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/jobagent/net/sf/basedb/clients/jobagent/Agent.java

    r7517 r7899  
    5252import net.sf.basedb.core.Project;
    5353import net.sf.basedb.core.SessionControl;
     54import net.sf.basedb.core.Application.StartupOptions;
    5455import net.sf.basedb.core.authentication.LoginRequest;
    5556import net.sf.basedb.util.SocketUtil;
     
    885886      // Disable database cleanup script, it is only needed on the web client
    886887      Config.setProperty("db.cleanup.interval", "0");
    887       Application.start(false);
     888      Application.start(new StartupOptions()
     889          .disableInternalJobQueue(true)
     890          );
    888891      sc = Application.newSessionControl("net.sf.basedb.clients.jobagent",
    889892        SocketUtil.getLocalHost().toString(), null);
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/StartStopServlet.java

    r7108 r7899  
    2626import net.sf.basedb.clients.web.extensions.ExtensionsControl;
    2727import net.sf.basedb.core.Application;
     28import net.sf.basedb.core.Application.StartupOptions;
    2829
    2930/**
     
    5354    try
    5455    {
    55       Application.start();
     56      Application.start(new StartupOptions().autoLogoutSessions(true));
    5657      ExtensionsControl.init(ctx.getServletContext());
    5758    }
  • trunk/src/core/net/sf/basedb/core/Application.java

    r7715 r7899  
    405405    throws BaseException
    406406  {
    407     start(false, true, null);
     407    start(StartupOptions.DEFAULT);
    408408  }
    409409 
     
    418418    @see #stop()
    419419    @see #isRunning()
    420   */
     420    @deprecated In BASE 3.18; use {@link #start(StartupOptions)} instead
     421  */
     422  @Deprecated
    421423  public static synchronized void start(boolean useInternalJobQueue)
    422424  {
    423     start(false, true, useInternalJobQueue);
     425    start(new StartupOptions().disableInternalJobQueue(!useInternalJobQueue));
    424426  }
    425427
     
    431433    @see #start()
    432434  */
    433   static synchronized void start(boolean installation, boolean verifySchemaVersion, Boolean useInternalJobQueue)
     435  public static synchronized void start(StartupOptions options)
    434436    throws BaseException
    435437  {
     
    519521      EmailUtil.init();
    520522 
    521       if (verifySchemaVersion)
     523      if (options.verifySchemaVersion)
    522524      {
    523525        int schemaVersion = getSchemaVersion();
     
    553555      }
    554556     
    555       if (!installation)
     557      if (!options.installation)
    556558      {
    557559        SystemItems.init();
    558560        Keyring.init();
    559         if (verifySchemaVersion) HibernateUtil.testTransactions();
     561        if (options.verifySchemaVersion) HibernateUtil.testTransactions();
    560562        RawDataTypes.initPlatforms(null);
    561563 
     
    564566       
    565567        // Initialize extensions system
    566         boolean extensionsAreDisabled = Config.getBoolean("extensions.disabled");
     568        boolean disableExtensions = Config.getBoolean("extensions.disabled") || options.disableExtensions;
    567569        Registry xtRegistry = new Registry();
    568570        java.io.File xtSettings = new java.io.File(userFilesDirectory, "extension-settings.xml");
     
    574576        xtManager.addURI(Application.class.getResource("/core-plugins.xml").toURI());
    575577        // Add plugins directory to the manager (unless disabled)
    576         if (!extensionsAreDisabled) xtManager.addDirectory(pluginsDirectory);
     578        if (!disableExtensions) xtManager.addDirectory(pluginsDirectory);
    577579       
    578580        // Register and load core extensions only
     
    607609        }
    608610       
    609         if (useInternalJobQueue == null) useInternalJobQueue = Config.getBoolean("jobqueue.internal.enabled");
     611        boolean useInternalJobQueue = Config.getBoolean("jobqueue.internal.enabled") && !options.disableInternalJobQueue;
    610612        log.info("jobqueue.internal.enabled = " + useInternalJobQueue);
    611613        if (useInternalJobQueue)
     
    10821084  }
    10831085 
     1086  /**
     1087    Startup optins when starting the BASE application.
     1088    Some options are internal and can only be changed
     1089    specific BASE routines (such as for installtion and upgrading).
     1090    <p>
     1091    In most cases, the {@link #DEFAULT} should be used.
     1092   
     1093    @since 3.18
     1094  */
     1095  public static final class StartupOptions
     1096  {
     1097   
     1098    /**
     1099      Default startup options that will start BASE for normal
     1100      operations using the options specified in "base.config".
     1101      The options in this instance can't be changed.
     1102    */
     1103    public static final StartupOptions DEFAULT = new StartupOptions().lock();
     1104   
     1105    private boolean locked = false;
     1106    private boolean installation = false;
     1107    private boolean verifySchemaVersion = true;
     1108    private Boolean disableInternalJobQueue = false;
     1109    private boolean disableExtensions = false;
     1110    private boolean autoLogoutSessions = false;
     1111   
     1112    public StartupOptions()
     1113    {}
     1114   
     1115    private void checkLocked(String msg)
     1116    {
     1117      if (locked) throw new PermissionDeniedException(msg);
     1118    }
     1119   
     1120    /**
     1121      Lock the options for additional modifications.
     1122      @return The same instance
     1123    */
     1124    public StartupOptions lock()
     1125    {
     1126      this.locked = true;
     1127      return this;
     1128    }
     1129   
     1130    /**
     1131      Set to TRUE when starting a new installation.
     1132      Default is FALSE.
     1133    */
     1134    StartupOptions installation(boolean installation)
     1135    {
     1136      checkLocked("installation()");
     1137      this.installation = installation;
     1138      return this;
     1139    }
     1140   
     1141    /**
     1142      Set to FALSE when starting a new installation
     1143      or upgrade. Default is TRUE.
     1144    */
     1145    StartupOptions verifySchemaVersion(boolean verifySchemaVersion)
     1146    {
     1147      checkLocked("verifySchemaVersion()");
     1148      this.verifySchemaVersion = verifySchemaVersion;
     1149      return this;
     1150    }
     1151   
     1152    /**
     1153      Set to TRUE to disable the internal job queue. Overrides
     1154      the "jobqueue.internal.enabled" setting in base.config.
     1155      Default is FALSE.
     1156    */
     1157    public StartupOptions disableInternalJobQueue(boolean disableInternalJobQueue)
     1158    {
     1159      checkLocked("disableInternalJobQueue()");
     1160      this.disableInternalJobQueue = disableInternalJobQueue;
     1161      return this;
     1162    }
     1163   
     1164    /**
     1165      Set to TRUE to disable loading external extensions.
     1166      Overrides the "extensions.disabled" setting in base.config.
     1167      Default is FALSE.
     1168    */
     1169    public StartupOptions disableExtensions(boolean disableExtensions)
     1170    {
     1171      checkLocked("disableExtensions()");
     1172      this.disableExtensions = disableExtensions;
     1173      return this;
     1174    }
     1175   
     1176    /**
     1177      Set to TRUE to automatically set a logout time for all
     1178      sessions that doesn't have one. Normally this is not needed
     1179      since BASE will automatically logout session when shutting
     1180      down. However, sometimes a system crash may leave sessions
     1181      without a logout time. Default is FALSE.
     1182    */
     1183    public StartupOptions autoLogoutSessions(boolean autoLogoutSessions)
     1184    {
     1185      checkLocked("autoLogoutSessions()");
     1186      this.autoLogoutSessions = autoLogoutSessions;
     1187      return this;
     1188    }
     1189  }
     1190 
    10841191  private static class SessionControlCacheCleaner
    10851192    extends TimerTask
  • trunk/src/core/net/sf/basedb/core/Install.java

    r7881 r7899  
    2525package net.sf.basedb.core;
    2626
     27import net.sf.basedb.core.Application.StartupOptions;
    2728import net.sf.basedb.core.authentication.LoginRequest;
    2829import net.sf.basedb.core.data.BioPlateEventTypeData;
     
    128129    try
    129130    {
    130       Application.start(true, false, false);
     131      Application.start(new StartupOptions()
     132          .installation(true)
     133          .verifySchemaVersion(false)
     134          .disableInternalJobQueue(true)
     135          .disableExtensions(true)
     136          );
    131137     
    132138      if (mode == SchemaGenerator.Mode.UPDATE)
     
    177183    {
    178184      Config.setProperty("extensions.disabled", "true");
    179       Application.start(false, false, false);
     185      Application.start(new StartupOptions()
     186          .installation(false)
     187          .verifySchemaVersion(false)
     188          .disableInternalJobQueue(true)
     189          .disableExtensions(true)
     190          );
    180191      session = HibernateUtil.newSession();
    181192      boolean update = mode == SchemaGenerator.Mode.UPDATE;
  • trunk/src/core/net/sf/basedb/core/Migration.java

    r7714 r7899  
    5656import java.util.zip.GZIPOutputStream;
    5757
     58import net.sf.basedb.core.Application.StartupOptions;
    5859import net.sf.basedb.core.data.VirtualDbData;
    5960import net.sf.basedb.core.dbengine.DbEngine;
     
    117118      throw new FileNotFoundException("Destination path is not a directory: " + path);
    118119    }
    119     Application.start(false, true, false);
     120    Application.start(new StartupOptions()
     121      .disableInternalJobQueue(true)
     122      .disableExtensions(true)
     123      );
    120124    Session session = null;
    121125    Transaction tx = null;
     
    157161      throw new FileNotFoundException("Import path is not a directory: " + path);
    158162    }
    159     Application.start(true, false, false);
     163    Application.start(new StartupOptions()
     164      .installation(true)
     165      .verifySchemaVersion(false)
     166      .disableExtensions(true)
     167      .disableInternalJobQueue(true)
     168      );
     169   
    160170    Session session = null;
    161171    Transaction tx = null;
  • trunk/src/core/net/sf/basedb/core/Update.java

    r7883 r7899  
    3838import org.hibernate.resource.transaction.spi.TransactionStatus;
    3939
     40import net.sf.basedb.core.Application.StartupOptions;
    4041import net.sf.basedb.core.authentication.LoginRequest;
    4142import net.sf.basedb.core.data.AnnotatableData;
     
    487488    try
    488489    {
    489       Config.setProperty("extensions.disabled", "true");
    490       Application.start(false, false, false);
     490      Application.start(new StartupOptions()
     491        .installation(false)
     492        .verifySchemaVersion(false)
     493        .disableExtensions(true)
     494        .disableInternalJobQueue(true)
     495        );
    491496
    492497      // Test root user account
     
    945950    try
    946951    {
    947       Config.setProperty("extensions.disabled", "true");
    948       Application.start(false, false, false);
     952      Application.start(new StartupOptions()
     953          .installation(false)
     954          .verifySchemaVersion(false)
     955          .disableExtensions(true)
     956          .disableInternalJobQueue(true)
     957          );
    949958
    950959      if (progress != null) progress.display(50, "Checking existing items...");
  • trunk/src/install/net/sf/basedb/install/InitDB.java

    r7522 r7899  
    3737import net.sf.basedb.core.Update;
    3838import net.sf.basedb.core.Version;
     39import net.sf.basedb.core.Application.StartupOptions;
    3940import net.sf.basedb.core.hibernate.SchemaGenerator;
    4041import net.sf.basedb.util.ConsoleProgressReporter;
     
    9596      {
    9697        showDbInfo(null);
    97         Application.start(false);
     98        Application.start(new StartupOptions()
     99            .disableExtensions(true)
     100            .disableInternalJobQueue(true)
     101            );
    98102        HibernateUtil.dbIndexes(true, false, false, false);
    99103        Application.stop();
     
    103107        boolean verbose = args.length >= 2 ? args[1].equals("-v") : false;
    104108        showDbInfo(null);
    105         Application.start(false);
     109        Application.start(new StartupOptions()
     110            .disableExtensions(true)
     111            .disableInternalJobQueue(true)
     112            );
    106113        HibernateUtil.dbIndexes(verbose, false, false, true);
    107114        Application.stop();
     
    111118        boolean verbose = args.length >= 2 ? args[1].equals("-v") : false;
    112119        showDbInfo(null);
    113         Application.start(false);
     120        Application.start(new StartupOptions()
     121            .disableExtensions(true)
     122            .disableInternalJobQueue(true)
     123            );
    114124        HibernateUtil.dbIndexes(verbose, false, true, false);
    115125        Application.stop();
     
    121131        boolean verbose = opt.contains("-v");
    122132        boolean drop = opt.contains("-dropindexes");
    123         Application.start(false);
     133        Application.start(new StartupOptions()
     134            .disableExtensions(true)
     135            .disableInternalJobQueue(true)
     136            );
    124137        HibernateUtil.dynamicDbIndexes(verbose, false, drop);
    125138        Application.stop();
  • trunk/src/install/net/sf/basedb/install/OneTimeFix.java

    r7521 r7899  
    3232import net.sf.basedb.core.SessionControl;
    3333import net.sf.basedb.core.Update;
     34import net.sf.basedb.core.Application.StartupOptions;
    3435import net.sf.basedb.core.authentication.LoginRequest;
    3536import net.sf.basedb.util.ConsoleProgressReporter;
     
    7273        InitDB.showDbInfo(null);
    7374        System.out.println("Starting BASE. Please wait...");
    74         Application.start(false);
     75        Application.start(new StartupOptions()
     76            .disableExtensions(true)
     77            .disableInternalJobQueue(true)
     78            );
    7579        SessionControl sc = Application.newSessionControl(null, null, null);
    7680        sc.login(new LoginRequest(login, pwd));
     
    96100        InitDB.showDbInfo(null);
    97101        System.out.println("Starting BASE. Please wait...");
    98         Application.start(false);
     102        Application.start(new StartupOptions()
     103            .disableExtensions(true)
     104            .disableInternalJobQueue(true)
     105            );
    99106        SessionControl sc = Application.newSessionControl(null, null, null);
    100107        sc.login(new LoginRequest(login, pwd));
  • trunk/src/install/net/sf/basedb/install/Webclient.java

    r7403 r7899  
    2626import net.sf.basedb.core.Config;
    2727import net.sf.basedb.core.SessionControl;
     28import net.sf.basedb.core.Application.StartupOptions;
    2829import net.sf.basedb.clients.web.Base;
    2930import net.sf.basedb.core.Application;
     
    9293    throws BaseException
    9394  {
    94     Config.setProperty("extensions.disabled", "true");
    95     Application.start(false);
     95    Application.start(new StartupOptions()
     96        .disableExtensions(true)
     97        .disableInternalJobQueue(true)
     98        );
    9699    SessionControl sc = Application.newSessionControl(null, null, null);
    97100    LoginRequest loginRequest = new LoginRequest(login, password);
  • trunk/src/test/TestUtil.java

    r7522 r7899  
    2828import net.sf.basedb.core.Permission;
    2929import net.sf.basedb.core.Version;
     30import net.sf.basedb.core.Application.StartupOptions;
    3031import net.sf.basedb.core.authentication.LoginRequest;
    3132
     
    153154    {
    154155      Config.setProperty("plugins.dir", System.getProperty("user.dir"));
    155       Config.setProperty("extensions.disabled", "true");
    156156      showDbInfo();
    157       Application.start(false);
     157      Application.start(new StartupOptions()
     158          .disableExtensions(true)
     159          .disableInternalJobQueue(true)
     160          );
    158161      Application.getStaticCache().cleanUp(new FileFilter()
    159162      {
  • trunk/src/test/net/sf/basedb/test/TestUtil.java

    r7522 r7899  
    3939import net.sf.basedb.core.SessionControl;
    4040import net.sf.basedb.core.Version;
     41import net.sf.basedb.core.Application.StartupOptions;
    4142import net.sf.basedb.core.authentication.LoginRequest;
    4243
     
    9091        startTime = System.currentTimeMillis();
    9192      }
    92       Application.start(false);
     93      Application.start(new StartupOptions()
     94          .disableExtensions(true)
     95          .disableInternalJobQueue(true)
     96          );
    9397      write("done.\n");
    9498      write("--Cleaning static cache from old items\n");
Note: See TracChangeset for help on using the changeset viewer.