use of org.apache.commons.vfs2.provider.FileReplicator in project spoofax by metaborg.
the class ResourceService method close.
@Override
public void close() throws Exception {
if (fileSystemManager instanceof DefaultFileSystemManager) {
final DefaultFileSystemManager defaultFileSystemManager = (DefaultFileSystemManager) fileSystemManager;
final FileReplicator replicator = defaultFileSystemManager.getReplicator();
if (replicator instanceof DefaultFileReplicator) {
final DefaultFileReplicator defaultFileReplicator = (DefaultFileReplicator) replicator;
defaultFileReplicator.close();
} else {
logger.warn("File replicator {} does not support cleaning up generated temporary files", replicator);
}
} else {
logger.warn("File system manager {} does not support cleaning up generated temporary files", fileSystemManager);
}
}
use of org.apache.commons.vfs2.provider.FileReplicator in project accumulo by apache.
the class AccumuloVFSClassLoader method close.
public static void close() {
for (WeakReference<DefaultFileSystemManager> vfsInstance : vfsInstances) {
DefaultFileSystemManager ref = vfsInstance.get();
if (ref != null) {
FileReplicator replicator;
try {
replicator = ref.getReplicator();
if (replicator instanceof UniqueFileReplicator) {
((UniqueFileReplicator) replicator).close();
}
} catch (FileSystemException e) {
log.error("FileSystemException", e);
}
ref.close();
}
}
try {
FileUtils.deleteDirectory(computeTopCacheDir());
} catch (IOException e) {
log.error("IOException", e);
}
}
use of org.apache.commons.vfs2.provider.FileReplicator in project accumulo by apache.
the class AccumuloVFSClassLoaderTest method testDefaultCacheDirectory.
@Test
public void testDefaultCacheDirectory() throws Exception {
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
File conf = folder1.newFile("accumulo-site.xml");
FileWriter out = new FileWriter(conf);
out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
out.append("<configuration>\n");
out.append("<property>\n");
out.append("<name>general.classpaths</name>\n");
out.append("<value></value>\n");
out.append("</property>\n");
out.append("<property>\n");
out.append("<name>general.vfs.classpaths</name>\n");
out.append("<value></value>\n");
out.append("</property>\n");
out.append("</configuration>\n");
out.close();
Whitebox.setInternalState(AccumuloClassLoader.class, "accumuloConfigUrl", conf.toURI().toURL());
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
AccumuloVFSClassLoader.getClassLoader();
FileSystemManager manager = AccumuloVFSClassLoader.generateVfs();
UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator");
File tempDir = Whitebox.getInternalState(replicator, "tempDir");
String tempDirParent = tempDir.getParent();
String tempDirName = tempDir.getName();
String javaIoTmpDir = System.getProperty("java.io.tmpdir");
// trim off any final separator, because java.io.File does the same.
if (javaIoTmpDir.endsWith(File.separator)) {
javaIoTmpDir = javaIoTmpDir.substring(0, javaIoTmpDir.length() - File.separator.length());
}
Assert.assertTrue(javaIoTmpDir.equals(tempDirParent));
Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-"));
Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser")));
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
}
use of org.apache.commons.vfs2.provider.FileReplicator in project accumulo by apache.
the class AccumuloVFSClassLoaderTest method testCacheDirectoryConfigured.
@Test
public void testCacheDirectoryConfigured() throws Exception {
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
String cacheDir = "/some/random/cache/dir";
File conf = folder1.newFile("accumulo-site.xml");
FileWriter out = new FileWriter(conf);
out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
out.append("<configuration>\n");
out.append("<property>\n");
out.append("<name>general.classpaths</name>\n");
out.append("<value></value>\n");
out.append("</property>\n");
out.append("<property>\n");
out.append("<name>" + AccumuloVFSClassLoader.VFS_CACHE_DIR + "</name>\n");
out.append("<value>" + cacheDir + "</value>\n");
out.append("</property>\n");
out.append("</configuration>\n");
out.close();
Whitebox.setInternalState(AccumuloClassLoader.class, "accumuloConfigUrl", conf.toURI().toURL());
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
AccumuloVFSClassLoader.getClassLoader();
FileSystemManager manager = AccumuloVFSClassLoader.generateVfs();
UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator");
File tempDir = Whitebox.getInternalState(replicator, "tempDir");
String tempDirParent = tempDir.getParent();
String tempDirName = tempDir.getName();
Assert.assertTrue(cacheDir.equals(tempDirParent));
Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-"));
Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser")));
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
}
Aggregations