Skip to content

Commit

Permalink
use its own variable configLastModified instead of using Play.startedAt
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev authored and xael-fry committed Nov 30, 2015
1 parent 3fbea9e commit 1a0f924
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion framework/src/play/ConfigurationChangeWatcherPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
* Plugin used for tracking for application.conf changes
*/
public class ConfigurationChangeWatcherPlugin extends PlayPlugin {
protected static long configLastModified;

@Override
public void onConfigurationRead() {
configLastModified = System.currentTimeMillis();
if (Play.mode.isProd()) {
Play.pluginCollection.disablePlugin(this);
}
Expand All @@ -16,7 +19,8 @@ public void onConfigurationRead() {
@Override
public void detectChange() {
for (VirtualFile conf : Play.confs) {
if (conf.lastModified() > Play.startedAt) {
if (conf.lastModified() > configLastModified) {
configLastModified = conf.lastModified();
onConfigurationFileChanged(conf);
}
}
Expand Down

3 comments on commit 1a0f924

@selangley
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes an erroneous log message in dev mode:
ERROR play - Restart: Need to restart Play because \application.conf has been changed

because when detectChange() is first executed the value of long configLastModified has not been properly initialized yet. It's value is 0. So the ConfigurationChangeWatcherPlugin will think a change has occurred to the application.conf when it it fact has not occurred. The value of configLastModified only gets initialized later when onConfigurationRead() is called.

@selangley
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a snippet from my log file showing the order in which these methods were called:

17:51:19,355 INFO play:308 - detectChange()
java.lang.Throwable
at play.ConfigurationChangeWatcherPlugin.detectChange(ConfigurationChangeWatcherPlugin.java:24)
at play.plugins.PluginCollection.detectChange(PluginCollection.java:598)
at play.Play.detectChanges(Play.java:641)
at play.Invoker$Invocation.init(Invoker.java:199)
at play.server.PlayHandler$NettyInvocation.init(PlayHandler.java:264)
at play.Invoker$Invocation.run(Invoker.java:285)

17:51:19,474 INFO play:308 - onConfigurationRead()
java.lang.Throwable
at play.ConfigurationChangeWatcherPlugin.onConfigurationRead(ConfigurationChangeWatcherPlugin.java:14)
at play.plugins.PluginCollection.onConfigurationRead(PluginCollection.java:610)
at play.Play.readConfiguration(Play.java:356)
at play.Play.start(Play.java:489)
at play.Play.detectChanges(Play.java:659)
at play.Invoker$Invocation.init(Invoker.java:199)
at play.server.PlayHandler$NettyInvocation.init(PlayHandler.java:264)
at play.Invoker$Invocation.run(Invoker.java:285)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:303)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

@xael-fry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an issue for this #1008. Thanks

Please sign in to comment.