org.apache.nutch.fs
Class NutchFileSystem

java.lang.Object
  extended byorg.apache.nutch.fs.NutchFileSystem
Direct Known Subclasses:
LocalFileSystem, NDFSFileSystem

public abstract class NutchFileSystem
extends Object

NutchFileSystem is an interface for a fairly simple distributed file system. A Nutch installation might consist of multiple machines, which should swap files transparently. This interface allows other Nutch systems to find and place files into the distributed Nutch-controlled file world. The standard job of NutchFileSystem is to take the location- independent NutchFile objects, and resolve them using local knowledge and local instances of ShareGroup.

Author:
Mike Cafarella

Field Summary
static Logger LOG
           
 
Constructor Summary
NutchFileSystem()
           
 
Method Summary
abstract  void close()
          No more filesystem operations are needed.
abstract  void completeLocalInput(File localFile)
          Called when we're all done writing to the target.
abstract  void completeLocalOutput(File nfsOutputFile, File tmpLocalFile)
          Called when we're all done writing to the target.
abstract  void copyFromLocalFile(File src, File dst)
          The src file is on the local disk.
abstract  void copyToLocalFile(File src, File dst)
          The src file is under NFS2, and the dst is on the local disk.
abstract  NFSOutputStream create(File f)
          Opens an OutputStream at the indicated File, whether local or via NDFS.
abstract  NFSOutputStream create(File f, boolean overwrite)
           
 boolean createNewFile(File f)
          Creates the given File as a brand-new zero-length file.
abstract  boolean delete(File f)
          Deletes File
abstract  boolean exists(File f)
          Check if exists
static NutchFileSystem get()
          Returns the default filesystem implementation.
abstract  long getLength(File f)
           
abstract  String getName()
          Returns a name for this filesystem, suitable to pass to getNamed(String).
static NutchFileSystem getNamed(String name)
          Returns a named filesystem.
abstract  boolean isDirectory(File f)
           
 boolean isFile(File f)
           
abstract  File[] listFiles(File f)
           
 File[] listFiles(File f, FileFilter filter)
           
abstract  void lock(File f, boolean shared)
          Obtain a lock on the given File
abstract  void mkdirs(File f)
          Make the given file and all non-existent parents into directories.
abstract  void moveFromLocalFile(File src, File dst)
          The src file is on the local disk.
abstract  NFSInputStream open(File f)
          Opens an InputStream for the indicated File, whether local or via NDFS.
static NutchFileSystem parseArgs(String[] argv, int i)
          Parse the cmd-line args, starting at i.
abstract  void release(File f)
          Release the lock
abstract  boolean rename(File src, File dst)
          Renames File src to File dst.
abstract  File startLocalInput(File nfsInputFile, File tmpLocalFile)
          Returns a local File that the user can read from.
abstract  File startLocalOutput(File nfsOutputFile, File tmpLocalFile)
          Returns a local File that the user can write output to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final Logger LOG
Constructor Detail

NutchFileSystem

public NutchFileSystem()
Method Detail

parseArgs

public static NutchFileSystem parseArgs(String[] argv,
                                        int i)
                                 throws IOException
Parse the cmd-line args, starting at i. Remove consumed args from array. We expect param in the form: '-local | -ndfs '

Throws:
IOException

get

public static NutchFileSystem get()
                           throws IOException
Returns the default filesystem implementation.

Throws:
IOException

getName

public abstract String getName()
Returns a name for this filesystem, suitable to pass to getNamed(String).


getNamed

public static NutchFileSystem getNamed(String name)
                                throws IOException
Returns a named filesystem. Names are either the string "local" or a host:port pair, naming an NDFS name server.

Throws:
IOException

open

public abstract NFSInputStream open(File f)
                             throws IOException
Opens an InputStream for the indicated File, whether local or via NDFS.

Throws:
IOException

create

public abstract NFSOutputStream create(File f)
                                throws IOException
Opens an OutputStream at the indicated File, whether local or via NDFS.

Throws:
IOException

create

public abstract NFSOutputStream create(File f,
                                       boolean overwrite)
                                throws IOException
Throws:
IOException

createNewFile

public boolean createNewFile(File f)
                      throws IOException
Creates the given File as a brand-new zero-length file. If create fails, or if it already existed, return false.

Throws:
IOException

rename

public abstract boolean rename(File src,
                               File dst)
                        throws IOException
Renames File src to File dst. Can take place on local fs or remote NDFS.

Throws:
IOException

delete

public abstract boolean delete(File f)
                        throws IOException
Deletes File

Throws:
IOException

exists

public abstract boolean exists(File f)
                        throws IOException
Check if exists

Throws:
IOException

isDirectory

public abstract boolean isDirectory(File f)
                             throws IOException
Throws:
IOException

isFile

public boolean isFile(File f)
               throws IOException
Throws:
IOException

getLength

public abstract long getLength(File f)
                        throws IOException
Throws:
IOException

listFiles

public abstract File[] listFiles(File f)
                          throws IOException
Throws:
IOException

listFiles

public File[] listFiles(File f,
                        FileFilter filter)
                 throws IOException
Throws:
IOException

mkdirs

public abstract void mkdirs(File f)
                     throws IOException
Make the given file and all non-existent parents into directories.

Throws:
IOException

lock

public abstract void lock(File f,
                          boolean shared)
                   throws IOException
Obtain a lock on the given File

Throws:
IOException

release

public abstract void release(File f)
                      throws IOException
Release the lock

Throws:
IOException

copyFromLocalFile

public abstract void copyFromLocalFile(File src,
                                       File dst)
                                throws IOException
The src file is on the local disk. Add it to NFS at the given dst name and the source is kept intact afterwards

Throws:
IOException

moveFromLocalFile

public abstract void moveFromLocalFile(File src,
                                       File dst)
                                throws IOException
The src file is on the local disk. Add it to NFS at the given dst name, removing the source afterwards.

Throws:
IOException

copyToLocalFile

public abstract void copyToLocalFile(File src,
                                     File dst)
                              throws IOException
The src file is under NFS2, and the dst is on the local disk. Copy it from NFS control to the local dst name.

Throws:
IOException

startLocalOutput

public abstract File startLocalOutput(File nfsOutputFile,
                                      File tmpLocalFile)
                               throws IOException
Returns a local File that the user can write output to. The caller provides both the eventual NFS target name and the local working file. If the NFS is local, we write directly into the target. If the NFS is remote, we write into the tmp local area.

Throws:
IOException

completeLocalOutput

public abstract void completeLocalOutput(File nfsOutputFile,
                                         File tmpLocalFile)
                                  throws IOException
Called when we're all done writing to the target. A local NFS will do nothing, because we've written to exactly the right place. A remote NFS will copy the contents of tmpLocalFile to the correct target at nfsOutputFile.

Throws:
IOException

startLocalInput

public abstract File startLocalInput(File nfsInputFile,
                                     File tmpLocalFile)
                              throws IOException
Returns a local File that the user can read from. The caller provides both the eventual NFS target name and the local working file. If the NFS is local, we read directly from the source. If the NFS is remote, we write data into the tmp local area.

Throws:
IOException

completeLocalInput

public abstract void completeLocalInput(File localFile)
                                 throws IOException
Called when we're all done writing to the target. A local NFS will do nothing, because we've written to exactly the right place. A remote NFS will copy the contents of tmpLocalFile to the correct target at nfsOutputFile.

Throws:
IOException

close

public abstract void close()
                    throws IOException
No more filesystem operations are needed. Will release any held locks.

Throws:
IOException


Copyright © 2006 The Apache Software Foundation