Skip to content

Commit

Permalink
Merge pull request #618 from renebock/shutdownhook
Browse files Browse the repository at this point in the history
Add property to disable ERXShutdownHook feature
  • Loading branch information
darkv committed Apr 27, 2015
2 parents 54359e2 + f99316a commit 263d4c9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import er.extensions.foundation.ERXRuntimeUtilities;
import er.extensions.foundation.ERXThreadStorage;
import er.extensions.foundation.ERXTimestampUtilities;
import er.extensions.foundation.ERXValueUtilities;
import er.extensions.localization.ERXLocalizer;
import er.extensions.migration.ERXMigrator;
import er.extensions.statistics.ERXStats;
Expand Down Expand Up @@ -138,6 +139,7 @@
* @property er.extensions.ERXApplication.StatisticsLogRotationFrequency
* @property er.extensions.ERXApplication.developmentMode
* @property er.extensions.ERXApplication.developmentMode
* @property er.extensions.ERXApplication.enableERXShutdownHook
* @property er.extensions.ERXApplication.fixCachingEnabled
* @property er.extensions.ERXApplication.lowMemBufferSize
* @property er.extensions.ERXApplication.memoryLowThreshold
Expand Down Expand Up @@ -854,6 +856,11 @@ private String stringFromJar(String jar, String path) {
}
}
}

// You should not use ERXShutdownHook when deploying as servlet.
protected static boolean enableERXShutdownHook() {
return ERXProperties.booleanForKeyWithDefault("er.extensions.ERXApplication.enableERXShutdownHook", true);
}

/**
* Called when the application starts up and saves the command line
Expand All @@ -863,6 +870,11 @@ private String stringFromJar(String jar, String path) {
*/
public static void main(String argv[], Class applicationClass) {
setup(argv);

if(enableERXShutdownHook()) {
ERXShutdownHook.initERXShutdownHook();
}

WOApplication.main(argv, applicationClass);
}

Expand Down Expand Up @@ -1034,6 +1046,17 @@ private void reportErrors() {
}
}

/**
* This heuristic to determine if an application is deployed as servlet relays on the fact,
* that contextClassName() is set WOServletContext or ERXWOServletContext
*
* @return true if the application is deployed as servlet.
*/
public boolean isDeployedAsServlet() {
return contextClassName().contains("Servlet"); // i.e one of WOServletContext or ERXWOServletContext
}


/**
* Called prior to actually initializing the app. Defines framework load
* order, class path order, checks patches etc.
Expand All @@ -1047,9 +1070,12 @@ public static void setup(String[] argv) {
ERXConfigurationManager.defaultManager().setCommandLineArguments(argv);
ERXFrameworkPrincipal.setUpFrameworkPrincipalClass(ERXExtensions.class);
// NSPropertiesCoordinator.loadProperties();
ERXShutdownHook.useMe();

if(enableERXShutdownHook()) {
ERXShutdownHook.useMe();
}
}

/**
* Installs several bugfixes and enhancements to WODynamicElements. Sets the
* Context class name to "er.extensions.ERXWOContext" if it is "WOContext".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
* }
* };
* </pre></blockquote></p>
*
*
* <b>CAUTION</b><br><br>
* You should not use this class when deploying the application as a J2EE servlet as it may interfere with other servlets running in the same VM.
* To disable this feature you have to provide the following start parameter to the java VM:
*
* <code>
* -Der.extensions.ERXApplication.enableERXShutdownHook=false
* </code><br>
*
* @author Maik Musall, maik@selbstdenker.ag
*
Expand All @@ -37,7 +46,8 @@ public abstract class ERXShutdownHook extends Thread {

static final Set<ERXShutdownHook> ALL_HOOKS = new HashSet<ERXShutdownHook>();

static {
public static void initERXShutdownHook() {
System.out.println( "WILL ADD SHUTDOWNHOOK" );
Runtime.getRuntime().addShutdownHook( new Thread() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public String hostName() {
}

/**
* Checks if the application is deployed as a servlet.
* Checks if the application <del>is</del> may be deployed as a servlet.
* <p>
* The current implementation only checks if the application
* is linked against <code>JavaWOJSPServlet.framework</code>.
Expand Down

0 comments on commit 263d4c9

Please sign in to comment.