Skip to content

Commit

Permalink
Change admin console loading
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 17, 2024
1 parent b389a64 commit 3f006ec
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public final class AdminConsoleAdapter extends HttpHandler implements Adapter, P
static final String ADMIN_APP_NAME = ServerEnvironmentImpl.DEFAULT_ADMIN_CONSOLE_APP_NAME;
private volatile boolean isRestStarted;
private volatile boolean isRestBeingStarted;
private ConsoleLoadingOption loadingOption = ConsoleLoadingOption.DEFAULT;

/**
* Constructor.
Expand Down Expand Up @@ -438,12 +439,17 @@ AdapterState getStateMsg() {
return stateMsg;
}

ConsoleLoadingOption getLoadingOption() {
return loadingOption;
}

/**
*
*/
@Override
public void postConstruct() {
events.register(this);

//set up the environment properly
init();
}
Expand All @@ -463,6 +469,20 @@ public void event(@RestrictTo(EventTypes.SERVER_READY_NAME) Event<?> event) {
*
*/
private void init() {
// Get loading option
// FIXME : Use ServerTags, when this is finalized.
Property loadingOptionProperty = adminService.getProperty("adminConsoleStartup");
if (loadingOptionProperty != null) {
String loadingOptionValue = loadingOptionProperty.getValue();
if (loadingOptionValue != null) {
try {
loadingOption = ConsoleLoadingOption.valueOf(loadingOptionValue.toUpperCase());
} catch (IllegalArgumentException e) {
logger.log(Level.WARNING, "AdminConsoleAdapter: Illegal console loading option \"{0}\"", loadingOptionValue);
}
}
}

Property locProp = adminService.getProperty(ServerTags.ADMIN_CONSOLE_DOWNLOAD_LOCATION);
if (locProp == null || locProp.getValue() == null || locProp.getValue().equals("")) {
String iRoot = System.getProperty(INSTALL_ROOT) + "/lib/install/applications/admingui.war";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.sun.enterprise.v3.admin.adapter;



import com.sun.enterprise.config.serverbeans.*;
import java.io.File;
import java.io.IOException;
Expand All @@ -33,7 +31,6 @@
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.config.types.Property;


@Service(name = "AdminConsoleStartupService")
@RunLevel(PostStartupRunLevel.VAL)
public class AdminConsoleStartupService implements PostConstruct {
Expand Down Expand Up @@ -66,36 +63,33 @@ public void postConstruct() {
if (!env.isDas())
return;

// FIXME : Use ServerTags, when this is finalized.
Property initProp = adminService.getProperty("adminConsoleStartup");
String initPropVal = "DEFAULT";
if (initProp != null) {
initPropVal = initProp.getValue();
if ( !(initPropVal.equals("ALWAYS") || initPropVal.equals("NEVER") || initPropVal.equals("DEFAULT"))){
initPropVal="DEFAULT";
}
}
ConsoleLoadingOption loadingOption = adminConsoleAdapter.getLoadingOption();

if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "AdminConsoleStartupService, console loading option is {0}", initPropVal);
logger.log(Level.FINE, "AdminConsoleStartupService: Console loading option is {0}", loadingOption);
}

if (initPropVal.equalsIgnoreCase("DEFAULT")) {
handleDefault();
} else if (initPropVal.equalsIgnoreCase("ALWAYS")) {
handleHigh();
switch (loadingOption) {
case ALWAYS:
handleAlways();
break;
case RECENT:
handleRecent();
break;
case NEVER:
case DEFAULT:
handleDefault();
break;
default:
break;
}
}

private void handleDefault() {
/* if there are servers other than DAS */
if ((domain.getServers().getServer().size() > 1)) {
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "AdminConsoleStartup DAS usecase");
}
handleHigh();
return;
}
// Do nothing
}

private void handleRecent() {
// if last access was within a day
long currentTime = System.currentTimeMillis();
try {
Expand All @@ -104,20 +98,15 @@ private void handleDefault() {
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "AdminConsoleStartup frequent user, lastTime = ", lastTime);
}
handleHigh();
handleAlways();
}
} catch (IOException ex) {
logger.fine(ex.getMessage());
logger.fine(ex.getMessage());
}
}

private void handleLow() {
private void handleAlways() {
adminConsoleAdapter.initRest();
}


private void handleHigh() {
handleLow();
synchronized(this) {
if (!adminConsoleAdapter.isInstalling() && !adminConsoleAdapter.isApplicationLoaded()) {
adminConsoleAdapter.loadConsole();
Expand All @@ -131,6 +120,4 @@ private long getTimeStamp() throws IOException {
return 0L;
return f.lastModified();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.enterprise.v3.admin.adapter;

/**
* A package-private class that holds the startup policy of the admin console.
*/
enum ConsoleLoadingOption {

DEFAULT,
ALWAYS,
RECENT,
NEVER
}

0 comments on commit 3f006ec

Please sign in to comment.