DefaultLexicalDataFactory.class, "reloadResources");
final IResourceLocator classpathLocator = Location.CONTEXT_CLASS_LOADER.locator;
// Create pooling controller, use tempDir1
final Controller ctrl1 = ControllerFactory.createPooling();
final ILexicalData data1;
{
ctrl1.init(ImmutableMap.<String, Object> of(
resourceLookupKey,
new ResourceLookup(new DirLocator(tempDir1), classpathLocator)));
final ProcessingResult result = ctrl1.process(
Collections.<String, Object> emptyMap(), TestComponent.class);
data1 = result.getAttribute("english");
assertTrue(data1.isCommonWord(new MutableCharArray("uniquea")));
}
// Create another pooling controller, same folder, but different resource lookup.
final Controller ctrl2 = ControllerFactory.createPooling();
final ILexicalData data2;
{
ctrl2.init(ImmutableMap.<String, Object> of(
resourceLookupKey,
new ResourceLookup(new DirLocator(tempDir1), classpathLocator)));
final ProcessingResult result = ctrl2.process(
Collections.<String, Object> emptyMap(), TestComponent.class);
data2 = result.getAttribute("english");
assertTrue(data2.isCommonWord(new MutableCharArray("uniquea")));
assertSame(data1, data2);
}
/*
* Now force reloading of resources from that path on ctrl1. The new stop word resource
* should contain 'uniqueb'.
*/
FileUtils.writeStringToFile(new File(tempDir1, "stopwords.en"), "uniqueb");
final ILexicalData data3 = ctrl1.process(
ImmutableMap.<String, Object> of(reloadResourcesKey, true), TestComponent.class)
.getAttribute("english");
assertNotSame(data1, data3);
assertFalse(data3.isCommonWord(new MutableCharArray("uniquea")));
assertTrue(data3.isCommonWord(new MutableCharArray("uniqueb")));
/*
* But since it's the same location, all other controllers should now see updated resources
* (and share the same lexical data).
*/
final ILexicalData data4 = ctrl2.process(
Collections.<String, Object> emptyMap(), TestComponent.class).getAttribute("english");
assertSame(data3, data4);
}