Skip to content

Commit

Permalink
Remove 'recent' console loading option
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Pinčuk <alexander.v.pinchuk@gmail.com>
  • Loading branch information
avpinchuk committed Feb 21, 2024
1 parent 30042c3 commit c296971
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -38,8 +36,6 @@ public class AdminConsoleStartupService {

private static final Logger logger = KernelLoggerInfo.getLogger();

private static final long ONE_DAY = 24 * 60 * 60 * 1000;

@Inject
@Optional
private AdminConsoleAdapter adminConsoleAdapter;
Expand All @@ -62,38 +58,10 @@ public void postConstruct() {

ConsoleLoadingOption loadingOption = adminConsoleAdapter.getLoadingOption();

logger.log(Level.FINE, () -> "AdminConsoleStartupService: Console loading option is " + loadingOption);

switch (loadingOption) {
case ALWAYS:
handleAlways();
break;
case RECENT:
handleRecent();
break;
case DEFAULT:
handleDefault();
break;
default:
break;
}
}

private void handleDefault() {
// Do nothing
}
logger.log(Level.FINE, "AdminConsoleStartupService: Console loading option is {0}", loadingOption);

private void handleRecent() {
// If last access was within a day
long currentTime = System.currentTimeMillis();
try {
long lastTime = getTimeStamp();
if (currentTime - lastTime < ONE_DAY) {
logger.log(Level.FINER, () -> "AdminConsoleStartup: Recent user, lastTime = " + lastTime);
handleAlways();
}
} catch (IOException ex) {
logger.fine(ex.getMessage());
if (loadingOption == ConsoleLoadingOption.ALWAYS) {
handleAlways();
}
}

Expand All @@ -105,12 +73,4 @@ private void handleAlways() {
}
}
}

private long getTimeStamp() throws IOException {
File stateFile = new File(serverEnvironment.getConfigDirPath(), ".consolestate");
if (!stateFile.exists()) {
return 0L;
}
return stateFile.lastModified();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@
*/
enum ConsoleLoadingOption {

DEFAULT,
ALWAYS,
RECENT,
NEVER
DEFAULT, ALWAYS, NEVER
}

0 comments on commit c296971

Please sign in to comment.