INT-3164: Fix Scripting Refresh
Previously, there was no logic to check, if a JSR223 script was modified should be refreshed from the external resource. * Fix `RefreshableResourceScriptSource` to take care of refreshing on call `isModified()` * Add `scriptSource.isModified()` before getting script text * Introduce `ScriptSourceFactoryBean` to avoid I/O operations, when there is need to refresh script resource - `refreshDelay < 0` JIRA: https://jira.springsource.org/browse/INT-3164 INT-3164: change the refresh mutation logic Remove factory bean - no longer needed.
This commit is contained in:
committed by
Gary Russell
parent
90d5a2fb98
commit
a7a722a59e
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.scripting.support.ResourceScriptSource;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class RefreshableResourceScriptSource implements ScriptSource {
|
||||
@@ -51,7 +52,10 @@ public class RefreshableResourceScriptSource implements ScriptSource {
|
||||
}
|
||||
|
||||
public String getScriptAsString() throws IOException {
|
||||
this.script = source.getScriptAsString();
|
||||
if (this.script == null || this.isModified()) {
|
||||
this.lastModifiedChecked.set(System.currentTimeMillis());
|
||||
this.script = source.getScriptAsString();
|
||||
}
|
||||
return this.script;
|
||||
}
|
||||
|
||||
@@ -60,15 +64,14 @@ public class RefreshableResourceScriptSource implements ScriptSource {
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
if (this.refreshDelay < 0) {
|
||||
return false;
|
||||
}
|
||||
long time = System.currentTimeMillis();
|
||||
if (this.refreshDelay == 0 || (time - this.lastModifiedChecked.get()) > this.refreshDelay) {
|
||||
this.lastModifiedChecked.set(time);
|
||||
return this.source.isModified();
|
||||
}
|
||||
return false;
|
||||
return this.refreshDelay >= 0 &&
|
||||
(System.currentTimeMillis() - this.lastModifiedChecked.get()) > this.refreshDelay &&
|
||||
this.source.isModified();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.source.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base Class for {@link ScriptExecutor}
|
||||
*
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author Mark Fisher
|
||||
* @since 2.1
|
||||
@@ -44,9 +44,9 @@ abstract class AbstractScriptExecutor implements ScriptExecutor {
|
||||
public AbstractScriptExecutor(String language) {
|
||||
Assert.hasText(language, "language must not be empty");
|
||||
this.language = language;
|
||||
|
||||
|
||||
scriptEngine = new ScriptEngineManager().getEngineByName(this.language);
|
||||
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
if (scriptEngine == null) {
|
||||
|
||||
Reference in New Issue
Block a user