Example usage for org.apache.hadoop.fs HarFileSystem HarFileSystem

List of usage examples for org.apache.hadoop.fs HarFileSystem HarFileSystem

Introduction

In this page you can find the example usage for org.apache.hadoop.fs HarFileSystem HarFileSystem.

Prototype

public HarFileSystem(FileSystem fs) 

Source Link

Document

Constructor to create a HarFileSystem with an underlying filesystem.

Usage

From source file:com.dianping.cat.hadoop.hdfs.HarConnectionPool.java

License:Open Source License

public HarFileSystem getHarfsConnection(String id, Date date, FileSystem fs) throws IOException {
    String serverUri = m_serverConfigManager.getHarfsServerUri(id);
    String baseUri = m_serverConfigManager.getHarfsBaseDir(id);
    String harUri = m_format.format(new Object[] { serverUri, baseUri, date });
    Pair<HarFileSystem, Long> har = m_hars.get(harUri);
    long current = System.currentTimeMillis();

    if (har == null) {
        synchronized (this) {
            if (har == null) {

                URI uri = URI.create(harUri);
                HarFileSystem harfs = new HarFileSystem(fs);

                try {
                    harfs.initialize(uri, harfs.getConf());
                    har = new Pair<HarFileSystem, Long>(harfs, current);

                    m_hars.put(harUri, har);
                } catch (IOException e) {
                    // ignore
                }/*from   ww  w .ja  v a  2s.  c  o  m*/
            }
        }
    }

    if (har != null) {
        har.setValue(current);
        return har.getKey();
    } else {
        return null;
    }
}