Skip to content

Commit

Permalink
MONDRIAN: Refactors the DynamicContentFinder to use a simple java.uti…
Browse files Browse the repository at this point in the history
…l.Timer isntead of a thread pool. Also modifies the return type of DynamicContentFinder.reloadDatasources() to void.

[git-p4: depot-paths = "//open/mondrian/": change = 14743]
  • Loading branch information
lucboudreau committed Nov 8, 2011
1 parent 3f63b11 commit 81e40b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
40 changes: 15 additions & 25 deletions src/main/mondrian/server/DynamicContentFinder.java
Expand Up @@ -19,7 +19,8 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;
import java.util.Timer;
import java.util.TimerTask;

/**
* Implementation of
Expand All @@ -45,12 +46,7 @@ public class DynamicContentFinder
private static final Logger LOGGER =
Logger.getLogger(MondrianServer.class);

private final static ScheduledExecutorService executorService =
Util.getScheduledExecutorService(
1,
"mondrian.server.DynamicContentFinder$executorService");

private final ScheduledFuture<?> scheduledTask;
private final Timer timer;

/**
* Creates a DynamicContentFinder.
Expand All @@ -61,51 +57,45 @@ public DynamicContentFinder(
{
super(dataSourcesConfigUrl);
reloadDataSources();
scheduledTask = executorService.scheduleWithFixedDelay(
new Runnable() {
timer = new Timer(
"mondrian.server.DynamicContentFinder$timer",
true);
timer.scheduleAtFixedRate(
new TimerTask() {
public void run() {
Object result;
try {
result = reloadDataSources();
} catch (Throwable e) {
result = e;
}
Util.discard(result); // for debug
reloadDataSources();
}
},
0,
MondrianProperties.instance().XmlaSchemaRefreshInterval.get(),
TimeUnit.MILLISECONDS);
MondrianProperties.instance().XmlaSchemaRefreshInterval.get());
}

/**
* Cleans up all background updating jobs.
*/
public void shutdown() {
scheduledTask.cancel(true);
super.shutdown();
timer.cancel();
}

/**
* Checks for updates to datasources content, flushes obsolete catalogs.
*
* @return Whether anything changed
*/
public synchronized boolean reloadDataSources() {
public synchronized void reloadDataSources() {
try {
String dataSourcesConfigString = getContent();
if (!hasDataSourcesContentChanged(dataSourcesConfigString)) {
return false;
return;
}
DataSourcesConfig.DataSources newDataSources =
XmlaSupport.parseDataSources(
dataSourcesConfigString, LOGGER);
if (newDataSources == null) {
return false;
return;
}
flushObsoleteCatalogs(newDataSources);
this.dataSources = newDataSources;
this.lastDataSourcesConfigString = dataSourcesConfigString;
return true;
} catch (Exception e) {
throw Util.newError(
e,
Expand Down
Expand Up @@ -233,7 +233,7 @@ public void testReloadDataSources() throws Exception {
out.write(ds2.toXML().getBytes());
out.close();

final boolean b1 = finder.reloadDataSources();
finder.reloadDataSources();
assertTrue(
finder.containsCatalog(DATASOURCE_1_NAME, CATALOG_1_NAME));
assertTrue(
Expand All @@ -245,7 +245,7 @@ public void testReloadDataSources() throws Exception {
out.write(ds1.toXML().getBytes());
out.flush();

final boolean b2 = finder.reloadDataSources();
finder.reloadDataSources();
assertTrue(
finder.containsCatalog(DATASOURCE_1_NAME, CATALOG_0_NAME));
assertTrue(
Expand Down Expand Up @@ -277,7 +277,7 @@ public void testAutoReloadDataSources() throws Exception {
out.write(ds2.toXML().getBytes());
out.close();

final boolean b = finder.reloadDataSources();
finder.reloadDataSources();
assertTrue(
finder.containsCatalog(DATASOURCE_1_NAME, CATALOG_1_NAME));
assertTrue(
Expand Down

0 comments on commit 81e40b5

Please sign in to comment.