001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file ../GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package org.griphyn.vdl.euryale;
017:
018: import java.io.IOException;
019: import java.io.File;
020:
021: /**
022: *
023: * A Virtual Hashed File Factory that does not do any existence checks while
024: * creating a directory. The factory, is used to create remote paths without
025: * checking for correctness.
026: *
027: * Additionally, it employs a decimal numbering scheme instead of hexadecimal
028: * used for HashedFileFactory.
029: *
030: * @author Karan Vahi
031: * @version $Revision: 289 $
032: */
033: public class VirtualDecimalHashedFileFactory extends HashedFileFactory {
034:
035: /**
036: * Constructor: Creates the base directory and employs sanity checks.
037: * @param baseDirectory is the place where the other dirs are created,
038: * and where the DAG file resides.
039: * @throws IOException if the location is not a writable directory,
040: * or cannot be created as such.
041: */
042: public VirtualDecimalHashedFileFactory(File baseDirectory)
043: throws IOException {
044: super (baseDirectory);
045: }
046:
047: /**
048: * Constructor: Creates the directory and employs sanity checks.
049: * @param baseDirectory is the place where the other dirs are created,
050: * and where the DAG file resides.
051: * @throws IOException if the location is not a writable directory,
052: * or cannot be created as such.
053: */
054: public VirtualDecimalHashedFileFactory(String baseDirectory)
055: throws IOException {
056: super (baseDirectory);
057: }
058:
059: /**
060: * Constructor: Creates the base directory and employs sanity checks.
061: * @param baseDirectory is the place where the other dirs are created,
062: * and where the DAG file resides.
063: * @param totalFiles is the number of files to support, and the number
064: * of times, the virtual constructor is expected to be called.
065: * @throws IOException if the location is not a writable directory,
066: * or cannot be created as such.
067: */
068: public VirtualDecimalHashedFileFactory(File baseDirectory,
069: int totalFiles) throws IOException {
070: super (baseDirectory, totalFiles);
071: }
072:
073: /**
074: * Constructor: Creates the directory and employs sanity checks.
075: * @param baseDirectory is the place where the other dirs are created,
076: * and where the DAG file resides.
077: * @param totalFiles is the number of files to support, and the number
078: * of times, the virtual constructor is expected to be called.
079: * @throws IOException if the location is not a writable directory,
080: * or cannot be created as such.
081: */
082: public VirtualDecimalHashedFileFactory(String baseDirectory,
083: int totalFiles) throws IOException {
084: super (baseDirectory, totalFiles);
085: }
086:
087: /**
088: * Resets the helper structures after changing layout parameters. You
089: * will also need to call this function after you invoked the virtual
090: * constructors, but want to change parameter pertaining to the
091: * directory structure. The structured file count will also be reset!
092: */
093: public void reset() {
094: super .reset();
095: m_count = 0;
096: mh_level = new int[m_levels];
097: //we are using decimal instead of hexa for this!
098: mh_digits = (int) Math.ceil(Math.log(m_filesPerDirectory)
099: / Math.log(10));
100: mh_buffer = new StringBuffer(mh_digits);
101: }
102:
103: /**
104: * Converts the given integer into hexadecimal notation, using
105: * the given number of digits, prefixing with zeros as necessary.
106: *
107: * @param number is the number to format.
108: * @return a string of appropriate length, filled with leading zeros,
109: * representing the number hexadecimally.
110: */
111: public String format(int number) {
112: mh_buffer.delete(0, mh_digits);
113: mh_buffer.append(Integer.toString(number));
114: while (mh_buffer.length() < mh_digits)
115: mh_buffer.insert(0, '0');
116: return mh_buffer.toString();
117: }
118:
119: /**
120: * Checks the destination location for existence, if it can
121: * be created, if it is writable etc. Does no check as it is
122: * virtual.
123: *
124: * @param dir is the new base directory to optionally create
125: */
126: protected void sanityCheck(File dir) throws IOException {
127:
128: }
129:
130: /**
131: * Creates a directory for the hashed file directory structure on the
132: * submit host. It only creates the File with correct path name, however
133: * does not physically create the file.
134: *
135: *
136: * @return the File structure to the created directory
137: *
138: * @throws IOException the exception.
139: */
140: protected File createDirectory() throws IOException {
141: // create directory, as necessary
142: File d = getBaseDirectory();
143: for (int i = 0; i < m_levels; ++i) {
144: d = new File(d, format(mh_level[i]));
145: }
146: return d;
147: }
148:
149: }
|