Search in sources :

Example 1 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.

the class VFSTransportSenderTest method getSoftReferenceMap.

private Map<?, ?> getSoftReferenceMap(VFSTransportSender vfsTransportSender) throws NoSuchFieldException, IllegalAccessException {
    Field field = VFSTransportSender.class.getDeclaredField("fsManager");
    field.setAccessible(true);
    FileSystemManager fsm = (FileSystemManager) field.get(vfsTransportSender);
    FilesCache fileCache = fsm.getFilesCache();
    SoftRefFilesCache softRefFilesCache = (SoftRefFilesCache) fileCache;
    Field field1 = SoftRefFilesCache.class.getDeclaredField("refReverseMap");
    field1.setAccessible(true);
    return (Map<?, ?>) (Map) field1.get(softRefFilesCache);
}
Also used : Field(java.lang.reflect.Field) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Map(java.util.Map) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) FilesCache(org.apache.commons.vfs2.FilesCache)

Example 2 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.

the class VFSUtils method isFailRecord.

public static boolean isFailRecord(FileSystemManager fsManager, FileObject fo) {
    try {
        String fullPath = fo.getName().getURI();
        int pos = fullPath.indexOf("?");
        if (pos > -1) {
            fullPath = fullPath.substring(0, pos);
        }
        FileObject failObject = fsManager.resolveFile(fullPath + ".fail");
        if (failObject.exists()) {
            return true;
        }
    } catch (FileSystemException e) {
        log.error("Couldn't release the fail for the file : " + maskURLPassword(fo.getName().getURI()));
    }
    return false;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject)

Example 3 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.

the class VFSUtils method markFailRecord.

public static synchronized void markFailRecord(FileSystemManager fsManager, FileObject fo) {
    // generate a random fail value to ensure that there are no two parties
    // processing the same file
    byte[] failValue = (Long.toString((new Date()).getTime())).getBytes();
    try {
        String fullPath = fo.getName().getURI();
        int pos = fullPath.indexOf("?");
        if (pos != -1) {
            fullPath = fullPath.substring(0, pos);
        }
        FileObject failObject = fsManager.resolveFile(fullPath + ".fail");
        if (!failObject.exists()) {
            failObject.createFile();
        }
        // write a lock file before starting of the processing, to ensure that the
        // item is not processed by any other parties
        OutputStream stream = failObject.getContent().getOutputStream();
        try {
            stream.write(failValue);
            stream.flush();
            stream.close();
        } catch (IOException e) {
            failObject.delete();
            log.error("Couldn't create the fail file before processing the file " + maskURLPassword(fullPath), e);
        } finally {
            failObject.close();
        }
    } catch (FileSystemException fse) {
        log.error("Cannot get the lock for the file : " + maskURLPassword(fo.getName().getURI()) + " before processing");
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) OutputStream(java.io.OutputStream) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) Date(java.util.Date)

Example 4 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project pentaho-platform by pentaho.

the class PentahoXmlaServlet method makeCatalogLocator.

@Override
protected CatalogLocator makeCatalogLocator(ServletConfig servletConfig) {
    return new ServletContextCatalogLocator(servletConfig.getServletContext()) {

        @Override
        public String locate(String catalogPath) {
            if (catalogPath.startsWith("mondrian:")) {
                // $NON-NLS-1$
                try {
                    FileSystemManager fsManager = VFS.getManager();
                    SolutionRepositoryVfsFileObject catalog = (SolutionRepositoryVfsFileObject) fsManager.resolveFile(catalogPath);
                    catalogPath = "solution:" + catalog.getFileRef();
                } catch (FileSystemException e) {
                    logger.error(e.getMessage());
                }
            } else {
                catalogPath = super.locate(catalogPath);
            }
            return catalogPath;
        }
    };
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) ServletContextCatalogLocator(mondrian.spi.impl.ServletContextCatalogLocator) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) SolutionRepositoryVfsFileObject(org.pentaho.platform.repository.solution.filebased.SolutionRepositoryVfsFileObject)

Example 5 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project accumulo by apache.

the class AccumuloVFSClassLoader method getClassLoader.

public static ClassLoader getClassLoader() throws IOException {
    ReloadingClassLoader localLoader = loader;
    while (null == localLoader) {
        synchronized (lock) {
            if (null == loader) {
                FileSystemManager vfs = generateVfs();
                // Set up the 2nd tier class loader
                if (null == parent) {
                    parent = AccumuloClassLoader.getClassLoader();
                }
                FileObject[] vfsCP = resolve(vfs, AccumuloClassLoader.getAccumuloProperty(VFS_CLASSLOADER_SYSTEM_CLASSPATH_PROPERTY, ""));
                if (vfsCP.length == 0) {
                    localLoader = createDynamicClassloader(parent);
                    loader = localLoader;
                    return localLoader.getClassLoader();
                }
                // Create the Accumulo Context ClassLoader using the DEFAULT_CONTEXT
                localLoader = createDynamicClassloader(new VFSClassLoader(vfsCP, vfs, parent));
                loader = localLoader;
                // and SequenceFile$Reader was trying to instantiate the key class via WritableName.getClass(String, Configuration)
                for (FileObject fo : vfsCP) {
                    if (fo instanceof HdfsFileObject) {
                        String uri = fo.getName().getRootURI();
                        Configuration c = new Configuration(true);
                        c.set(FileSystem.FS_DEFAULT_NAME_KEY, uri);
                        FileSystem fs = FileSystem.get(c);
                        fs.getConf().setClassLoader(loader.getClassLoader());
                    }
                }
            }
        }
    }
    return localLoader.getClassLoader();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsFileObject(org.apache.commons.vfs2.provider.hdfs.HdfsFileObject) FileSystem(org.apache.hadoop.fs.FileSystem) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) FileObject(org.apache.commons.vfs2.FileObject) HdfsFileObject(org.apache.commons.vfs2.provider.hdfs.HdfsFileObject) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager)

Aggregations

FileSystemManager (org.apache.commons.vfs2.FileSystemManager)30 FileObject (org.apache.commons.vfs2.FileObject)26 FileSystemException (org.apache.commons.vfs2.FileSystemException)18 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)17 File (java.io.File)12 IOException (java.io.IOException)11 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)7 Test (org.junit.Test)6 FileContent (org.apache.commons.vfs2.FileContent)4 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)4 OutputStream (java.io.OutputStream)3 RepositoryException (javax.jcr.RepositoryException)3 FileName (org.apache.commons.vfs2.FileName)3 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)3 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Random (java.util.Random)2