Skip to content

Commit

Permalink
MONDRIAN: [MONDRIAN-965]
Browse files Browse the repository at this point in the history
Fixes a bug in DynamicContentFinder and FileRepository where the thread pools were initiated with a core size of 0. (Should be 1.)

[git-p4: depot-paths = "//open/mondrian/": change = 14462]
  • Loading branch information
lucboudreau committed Jul 16, 2011
1 parent 8cc3617 commit d7a136c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 29 deletions.
25 changes: 25 additions & 0 deletions src/main/mondrian/olap/Util.java
Expand Up @@ -201,6 +201,31 @@ public Thread newThread(Runnable r) {
);
}

/**
* Creates an {@link ScheduledExecutorService} object backed by a
* thread pool with a fixed number of threads..
* @param maxNbThreads Maximum number of concurrent
* threads.
* @param name The name of the threads.
* @return An scheduled executor service preconfigured.
*/
public static ScheduledExecutorService getScheduledExecutorService(
final int maxNbThreads,
final String name)
{
return Executors.newScheduledThreadPool(
maxNbThreads,
new ThreadFactory() {
public Thread newThread(Runnable r) {
final Thread thread =
Executors.defaultThreadFactory().newThread(r);
thread.setDaemon(true);
thread.setName(name);
return thread;
}
}
);
}
/**
* Creates an {@link ExecutorService} object backed by an expanding
* cached thread pool.
Expand Down
18 changes: 3 additions & 15 deletions src/main/mondrian/server/DynamicContentFinder.java
Expand Up @@ -19,7 +19,6 @@

import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

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

private static AtomicInteger threadNumber = new AtomicInteger(0);

private final static ScheduledExecutorService executorService =
Executors.newScheduledThreadPool(
0,
new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
t.setName(
"mondrian.DynamicContentFinderUpdaterThread"
+ threadNumber.addAndGet(1));
return t;
}
});
Util.getScheduledExecutorService(
1,
"mondrian.server.DynamicContentFinder$executorService");

private final ScheduledFuture<?> scheduledTask;

Expand Down
18 changes: 4 additions & 14 deletions src/main/mondrian/server/FileRepository.java
Expand Up @@ -21,10 +21,8 @@

import java.sql.*;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -49,18 +47,10 @@ public class FileRepository implements Repository {
private static AtomicInteger threadNumber = new AtomicInteger(0);

private final static ScheduledExecutorService executorService =
Executors.newScheduledThreadPool(
0,
new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
t.setName(
"mondrian.FileRepositoryUpdaterThread"
+ threadNumber.addAndGet(1));
return t;
}
});
Util.getScheduledExecutorService(
1,
"mondrian.server.DynamicContentFinder$executorService");

private final ScheduledFuture<?> scheduledFuture;

public FileRepository(RepositoryContentFinder repositoryContentFinder) {
Expand Down
Expand Up @@ -9,6 +9,7 @@
package mondrian.xmla.impl;

import junit.framework.TestCase;
import mondrian.olap.MondrianProperties;
import mondrian.server.DynamicContentFinder;
import mondrian.xmla.DataSourcesConfig;
import org.eigenbase.xom.DOMWrapper;
Expand Down Expand Up @@ -264,6 +265,62 @@ public void testReloadDataSources() throws Exception {
}
}

public void testAutoReloadDataSources() throws Exception {
DataSourcesConfig.DataSources ds1 =
getDataSources(CATALOG_0_DEFINITION, CATALOG_1_DEFINITION);
DataSourcesConfig.DataSources ds2 =
getDataSources(CATALOG_1_DEFINITION, CATALOG_2_DEFINITION);

File dsFile = null;
try {
dsFile = File.createTempFile(
Long.toString(System.currentTimeMillis()), null);
dsFile.deleteOnExit();

OutputStream out = new FileOutputStream(dsFile);
out.write(ds1.toXML().getBytes());
out.flush();

final MockDynamicContentFinder finder =
new MockDynamicContentFinder(
dsFile.toURL().toString());

out = new FileOutputStream(dsFile);
out.write(ds2.toXML().getBytes());
out.flush();

finder.reloadDataSources();

assertTrue(
finder.containsCatalog(DATASOURCE_1_NAME, CATALOG_1_NAME));
assertTrue(
finder.containsCatalog(DATASOURCE_1_NAME, CATALOG_2_NAME));
assertFalse(
finder.containsCatalog(DATASOURCE_1_NAME, CATALOG_0_NAME));

out = new FileOutputStream(dsFile);
out.write(ds1.toXML().getBytes());
out.flush();

// Wait for it to auto-reload.
Thread.sleep(
MondrianProperties.instance()
.XmlaSchemaRefreshInterval.get() + 1000);

assertTrue(
finder.containsCatalog(DATASOURCE_1_NAME, CATALOG_0_NAME));
assertTrue(
finder.containsCatalog(DATASOURCE_1_NAME, CATALOG_1_NAME));
assertFalse(
finder.containsCatalog(DATASOURCE_1_NAME, CATALOG_2_NAME));
finder.shutdown();
} finally {
if (dsFile != null) {
dsFile.delete();
}
}
}

private static class MockDynamicContentFinder extends DynamicContentFinder
{
private List<String> flushCatalogList = new ArrayList<String>();
Expand Down

0 comments on commit d7a136c

Please sign in to comment.