Skip to content

Commit 7fd6772

Browse files
committed
Move performance marker to OpenmrsConstants and add documentation
1 parent 755648f commit 7fd6772

File tree

5 files changed

+39
-43
lines changed

5 files changed

+39
-43
lines changed

api/src/main/java/org/openmrs/module/ModuleUtil.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
import org.openmrs.util.OpenmrsUtil;
6161
import org.slf4j.Logger;
6262
import org.slf4j.LoggerFactory;
63-
import org.slf4j.Marker;
64-
import org.slf4j.MarkerFactory;
6563
import org.springframework.context.support.AbstractRefreshableApplicationContext;
6664

6765
/**
@@ -73,7 +71,6 @@ private ModuleUtil() {
7371
}
7472

7573
private static final Logger log = LoggerFactory.getLogger(ModuleUtil.class);
76-
private static final Marker PERFORMANCE_MARKER = MarkerFactory.getMarker("performance");
7774

7875
/**
7976
* Start up the module system with the given properties.
@@ -869,7 +866,7 @@ public static AbstractRefreshableApplicationContext refreshApplicationContext(Ab
869866
for (Module module : startedModules) {
870867
try {
871868
if (module.getModuleActivator() != null) {
872-
log.debug(PERFORMANCE_MARKER, "Run module willRefreshContext: {}", module.getModuleId());
869+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Run module willRefreshContext: {}", module.getModuleId());
873870
Thread.currentThread().setContextClassLoader(ModuleFactory.getModuleClassLoader(module));
874871
module.getModuleActivator().willRefreshContext();
875872
}
@@ -896,7 +893,7 @@ public static AbstractRefreshableApplicationContext refreshApplicationContext(Ab
896893
ctx.setClassLoader(OpenmrsClassLoader.getInstance());
897894
Thread.currentThread().setContextClassLoader(OpenmrsClassLoader.getInstance());
898895

899-
log.debug(PERFORMANCE_MARKER, "Refreshing context");
896+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Refreshing context");
900897
ServiceContext.getInstance().startRefreshingContext();
901898
try {
902899
ctx.refresh();
@@ -907,13 +904,13 @@ public static AbstractRefreshableApplicationContext refreshApplicationContext(Ab
907904
finally {
908905
ServiceContext.getInstance().doneRefreshingContext();
909906
}
910-
log.debug(PERFORMANCE_MARKER, "Done refreshing context");
907+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Done refreshing context");
911908

912909
ctx.setClassLoader(OpenmrsClassLoader.getInstance());
913910
Thread.currentThread().setContextClassLoader(OpenmrsClassLoader.getInstance());
914911

915912
OpenmrsClassLoader.restoreState();
916-
log.debug(PERFORMANCE_MARKER, "Startup scheduler");
913+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Startup scheduler");
917914
SchedulerUtil.startup(Context.getRuntimeProperties());
918915

919916
OpenmrsClassLoader.setThreadsToNewClassLoader();
@@ -937,20 +934,20 @@ public static AbstractRefreshableApplicationContext refreshApplicationContext(Ab
937934
ModuleFactory.passDaemonToken(module);
938935

939936
if (module.getModuleActivator() != null) {
940-
log.debug(PERFORMANCE_MARKER, "Run module contextRefreshed: {}", module.getModuleId());
937+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Run module contextRefreshed: {}", module.getModuleId());
941938
module.getModuleActivator().contextRefreshed();
942939
try {
943940
//if it is system start up, call the started method for all started modules
944941
if (isOpenmrsStartup) {
945-
log.debug(PERFORMANCE_MARKER, "Run module started: {}", module.getModuleId());
942+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Run module started: {}", module.getModuleId());
946943
module.getModuleActivator().started();
947944
}
948945
//if refreshing the context after a user started or uploaded a new module
949946
else if (!isOpenmrsStartup && module.equals(startedModule)) {
950-
log.debug(PERFORMANCE_MARKER, "Run module started: {}", module.getModuleId());
947+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Run module started: {}", module.getModuleId());
951948
module.getModuleActivator().started();
952949
}
953-
log.debug(PERFORMANCE_MARKER, "Done running module started: {}", module.getModuleId());
950+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Done running module started: {}", module.getModuleId());
954951
}
955952
catch (Error e) {
956953
log.warn("Unable to invoke started() method on the module's activator", e);

api/src/main/java/org/openmrs/util/OpenmrsConstants.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.openmrs.scheduler.SchedulerConstants;
3434
import org.slf4j.Logger;
3535
import org.slf4j.LoggerFactory;
36+
import org.slf4j.Marker;
37+
import org.slf4j.MarkerFactory;
3638

3739
import static java.util.Arrays.asList;
3840

@@ -45,6 +47,13 @@
4547
public final class OpenmrsConstants {
4648

4749
private static final Logger log = LoggerFactory.getLogger(OpenmrsConstants.class);
50+
51+
/**
52+
* Marker used for performance-related log entries.
53+
* To filter log files: grep "performance" openmrs.log
54+
* To find usages in source: Get-ChildItem -Recurse -Filter *.java | Select-String "PERFORMANCE_MARKER"
55+
*/
56+
public static final Marker PERFORMANCE_MARKER = MarkerFactory.getMarker("performance");
4857

4958
public static String KEY_OPENMRS_APPLICATION_DATA_DIRECTORY = "OPENMRS_APPLICATION_DATA_DIRECTORY";
5059

web/src/main/java/org/openmrs/module/web/WebModuleUtil.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@
6565
import org.openmrs.scheduler.SchedulerService;
6666
import org.openmrs.scheduler.TaskDefinition;
6767
import org.openmrs.util.OpenmrsUtil;
68+
import org.openmrs.util.OpenmrsConstants;
6869
import org.openmrs.util.PrivilegeConstants;
6970
import org.openmrs.web.DispatcherServlet;
7071
import org.openmrs.web.StaticDispatcherServlet;
7172
import org.slf4j.Logger;
7273
import org.slf4j.LoggerFactory;
73-
import org.slf4j.Marker;
74-
import org.slf4j.MarkerFactory;
7574
import org.springframework.web.context.support.WebApplicationContextUtils;
7675
import org.springframework.web.context.support.XmlWebApplicationContext;
7776
import org.w3c.dom.Document;
@@ -90,8 +89,6 @@ private WebModuleUtil() {
9089

9190
private static final Logger log = LoggerFactory.getLogger(WebModuleUtil.class);
9291

93-
private static final Marker PERFORMANCE_MARKER = MarkerFactory.getMarker("performance");
94-
9592
private static final Lock SERVLET_LOCK = new ReentrantLock();
9693

9794
private static final Lock FILTERS_LOCK = new ReentrantLock();
@@ -128,7 +125,7 @@ private WebModuleUtil() {
128125
*/
129126
public static boolean startModule(Module mod, ServletContext servletContext, boolean delayContextRefresh) {
130127

131-
log.debug(PERFORMANCE_MARKER, "Trying to start module {}", mod);
128+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Trying to start module {}", mod);
132129

133130
// only try and start this module if the api started it without a
134131
// problem.
@@ -318,11 +315,11 @@ public static boolean startModule(Module mod, ServletContext servletContext, boo
318315
// refresh the spring web context to get the just-created xml
319316
// files into it (if we copied an xml file)
320317
if (moduleNeedsContextRefresh && !delayContextRefresh) {
321-
log.debug(PERFORMANCE_MARKER, "Refreshing context for module {}", mod.getModuleId());
318+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Refreshing context for module {}", mod.getModuleId());
322319

323320
try {
324321
refreshWAC(servletContext, false, mod);
325-
log.debug(PERFORMANCE_MARKER, "Done refreshing context for module {}", mod.getModuleId());
322+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Done refreshing context for module {}", mod.getModuleId());
326323
}
327324
catch (Exception e) {
328325
String msg = "Unable to refresh the WebApplicationContext";
@@ -344,9 +341,9 @@ public static boolean startModule(Module mod, ServletContext servletContext, boo
344341
}
345342

346343
// try starting the application context again
347-
log.debug(PERFORMANCE_MARKER, "Refreshing context for module {} (re-trying)", mod.getModuleId());
344+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Refreshing context for module {} (re-trying)", mod.getModuleId());
348345
refreshWAC(servletContext, false, mod);
349-
log.debug(PERFORMANCE_MARKER, "Done refreshing context for module {} (re-trying)", mod.getModuleId());
346+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Done refreshing context for module {} (re-trying)", mod.getModuleId());
350347

351348
notifySuperUsersAboutModuleFailure(mod);
352349
}
@@ -936,7 +933,7 @@ public static XmlWebApplicationContext refreshWAC(ServletContext servletContext,
936933
Module startedModule) {
937934
XmlWebApplicationContext wac = (XmlWebApplicationContext) WebApplicationContextUtils
938935
.getWebApplicationContext(servletContext);
939-
log.debug(PERFORMANCE_MARKER, "Refreshing Web Application Context of class: {}", wac.getClass().getName());
936+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Refreshing Web Application Context of class: {}", wac.getClass().getName());
940937

941938
if (dispatcherServlet != null) {
942939
dispatcherServlet.stopAndCloseApplicationContext();

web/src/main/java/org/openmrs/web/Listener.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.owasp.csrfguard.CsrfGuardServletContextListener;
3333
import org.slf4j.LoggerFactory;
3434
import org.slf4j.MarkerFactory;
35-
import org.slf4j.Marker;
3635
import org.springframework.beans.factory.BeanCreationException;
3736
import org.springframework.util.StringUtils;
3837
import org.springframework.web.context.ContextLoader;
@@ -84,8 +83,6 @@ public final class Listener extends ContextLoader implements ServletContextListe
8483

8584
private static final org.slf4j.Logger log = LoggerFactory.getLogger(Listener.class);
8685

87-
private static final Marker PERFORMANCE_MARKER = MarkerFactory.getMarker("performance");
88-
8986
private static boolean runtimePropertiesFound = false;
9087

9188
private static Throwable errorAtStartup = null;
@@ -250,11 +247,11 @@ public void contextInitialized(ServletContextEvent event) {
250247
* This logic is from ContextLoader.initWebApplicationContext. Copied here instead
251248
* of calling that so that the context is not cached and hence not garbage collected
252249
*/
253-
log.debug(PERFORMANCE_MARKER, "Refreshing WAC");
250+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Refreshing WAC");
254251
XmlWebApplicationContext context = (XmlWebApplicationContext) createWebApplicationContext(servletContext);
255252
configureAndRefreshWebApplicationContext(context, servletContext);
256253
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
257-
log.debug(PERFORMANCE_MARKER, "Done refreshing WAC");
254+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Done refreshing WAC");
258255

259256
WebDaemon.startOpenmrs(event.getServletContext());
260257
} else {
@@ -346,7 +343,7 @@ public static void startOpenmrs(ServletContext servletContext) throws ServletExc
346343
// start openmrs
347344
try {
348345
// load bundled modules that are packaged into the webapp
349-
log.debug(PERFORMANCE_MARKER, "Loading bundled modules");
346+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Loading bundled modules");
350347
Listener.loadBundledModules(servletContext);
351348

352349
Context.startup(getRuntimeProperties());
@@ -361,7 +358,7 @@ public static void startOpenmrs(ServletContext servletContext) throws ServletExc
361358
// TODO catch openmrs errors here and drop the user back out to the setup screen
362359

363360
try {
364-
log.debug(PERFORMANCE_MARKER, "Performing start of modules");
361+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Performing start of modules");
365362
// web load modules
366363
Listener.performWebStartOfModules(servletContext);
367364

@@ -706,7 +703,7 @@ public static void performWebStartOfModules(Collection<Module> startedModules, S
706703

707704
boolean someModuleNeedsARefresh = false;
708705
for (Module mod : startedModules) {
709-
log.debug(PERFORMANCE_MARKER, "Staring module: {}", mod.getModuleId());
706+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Staring module: {}", mod.getModuleId());
710707
try {
711708
boolean thisModuleCausesRefresh = WebModuleUtil.startModule(mod, servletContext,
712709
/* delayContextRefresh */true);
@@ -719,9 +716,9 @@ public static void performWebStartOfModules(Collection<Module> startedModules, S
719716

720717
if (someModuleNeedsARefresh) {
721718
try {
722-
log.debug(PERFORMANCE_MARKER, "Refreshing WAC as required by some module");
719+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Refreshing WAC as required by some module");
723720
WebModuleUtil.refreshWAC(servletContext, true, null);
724-
log.debug(PERFORMANCE_MARKER, "Done refreshing WAC as required by some module");
721+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Done refreshing WAC as required by some module");
725722
}
726723
catch (ModuleMustStartException | BeanCreationException ex) {
727724
// pass this up to the calling method so that openmrs loading stops
@@ -751,9 +748,9 @@ public static void performWebStartOfModules(Collection<Module> startedModules, S
751748
}
752749
}
753750
}
754-
log.debug(PERFORMANCE_MARKER, "Retrying refreshing WebApplicationContext");
751+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Retrying refreshing WebApplicationContext");
755752
WebModuleUtil.refreshWAC(servletContext, true, null);
756-
log.debug(PERFORMANCE_MARKER, "Done refreshing WebApplicationContext");
753+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Done refreshing WebApplicationContext");
757754
}
758755
catch (MandatoryModuleException ex) {
759756
// pass this up to the calling method so that openmrs loading stops
@@ -772,7 +769,7 @@ public static void performWebStartOfModules(Collection<Module> startedModules, S
772769
// because we delayed the refresh, we need to load+start all servlets and filters now
773770
// (this is to protect servlets/filters that depend on their module's spring xml config being available)
774771
for (Module mod : ModuleFactory.getStartedModulesInOrder()) {
775-
log.debug(PERFORMANCE_MARKER, "Loading servlets and filters for module: {}", mod.getModuleId());
772+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Loading servlets and filters for module: {}", mod.getModuleId());
776773
WebModuleUtil.loadServlets(mod, servletContext);
777774
WebModuleUtil.loadFilters(mod, servletContext);
778775
}

web/src/main/java/org/openmrs/web/filter/initialization/InitializationFilter.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
import org.openmrs.web.filter.util.FilterUtil;
7979
import org.openmrs.web.filter.util.SessionModelUtils;
8080
import org.slf4j.LoggerFactory;
81-
import org.slf4j.Marker;
82-
import org.slf4j.MarkerFactory;
8381
import org.springframework.util.StringUtils;
8482
import org.springframework.web.context.ContextLoader;
8583

@@ -96,8 +94,6 @@ public class InitializationFilter extends StartupFilter {
9694

9795
private static final org.slf4j.Logger log = LoggerFactory.getLogger(InitializationFilter.class);
9896

99-
private static final Marker PERFORMANCE_MARKER = MarkerFactory.getMarker("performance");
100-
10197
private static final String DATABASE_POSTGRESQL = "postgresql";
10298

10399
private static final String DATABASE_MYSQL = "mysql";
@@ -217,7 +213,7 @@ protected synchronized void setInitializationComplete(boolean initializationComp
217213
@Override
218214
protected void doGet(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
219215
throws IOException {
220-
log.debug(PERFORMANCE_MARKER, "Entered initialization filter");
216+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Entered initialization filter");
221217

222218
SessionModelUtils.loadFromSession(httpRequest.getSession(), wizardModel);
223219
initializeWizardFromResolvedPropertiesIfPresent();
@@ -1349,7 +1345,7 @@ public synchronized String getMessage() {
13491345
}
13501346

13511347
public synchronized void setMessage(String message) {
1352-
log.debug(PERFORMANCE_MARKER, message);
1348+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, message);
13531349
this.message = message;
13541350
setStepsComplete(getStepsComplete() + 1);
13551351
}
@@ -1599,7 +1595,7 @@ public void executing(ChangeSet changeSet, int numChangeSetsToRun) {
15991595
}
16001596

16011597
if (wizardModel.createTables) {
1602-
log.debug(PERFORMANCE_MARKER, "Creating tables");
1598+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Creating tables");
16031599
// use liquibase to create core data + tables
16041600
try {
16051601
String liquibaseSchemaFileName = changeLogVersionFinder.getLatestSchemaSnapshotFilename()
@@ -1728,10 +1724,10 @@ public void executing(ChangeSet changeSet, int numChangeSetsToRun) {
17281724
// start spring
17291725
// after this point, all errors need to also call: contextLoader.closeWebApplicationContext(event.getServletContext())
17301726
// logic copied from org.springframework.web.context.ContextLoaderListener
1731-
log.debug(PERFORMANCE_MARKER, "Initializing WAC");
1727+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Initializing WAC");
17321728
ContextLoader contextLoader = new ContextLoader();
17331729
contextLoader.initWebApplicationContext(filterConfig.getServletContext());
1734-
log.debug(PERFORMANCE_MARKER, "Done initializing WAC");
1730+
log.debug(OpenmrsConstants.PERFORMANCE_MARKER, "Done initializing WAC");
17351731

17361732
// output properties to the openmrs runtime properties file so that this wizard is not run again
17371733
FileOutputStream fos = null;

0 commit comments

Comments
 (0)