2009-08-04 10:36:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009, Swedish Institute of Computer Science
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @author Nicolas Tsiftes
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-11-19 11:17:37 +00:00
|
|
|
package org.contikios.coffee;
|
2009-08-04 10:36:53 +00:00
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
2013-11-19 11:17:37 +00:00
|
|
|
import org.contikios.coffee.CoffeeFS.CoffeeException;
|
2009-08-11 17:03:59 +00:00
|
|
|
|
2009-08-04 10:36:53 +00:00
|
|
|
public class CoffeeConfiguration {
|
|
|
|
public static final int FD_SET_SIZE = 256;
|
|
|
|
public static final int MAX_OPEN_FILES = 256;
|
|
|
|
public static final int LOG_TABLE_LIMIT = 256;
|
2012-01-28 02:34:16 +00:00
|
|
|
public final int nameLength;
|
|
|
|
public final int fsSize, sectorSize, pageSize;
|
|
|
|
public final int startOffset, pageTypeSize;
|
|
|
|
public final int defaultFileSize, defaultLogSize;
|
|
|
|
public final int pagesPerSector;
|
|
|
|
public final boolean useMicroLogs;
|
2009-08-04 10:36:53 +00:00
|
|
|
|
|
|
|
public CoffeeConfiguration(String filename)
|
|
|
|
throws CoffeeException, IOException {
|
2012-01-28 02:34:16 +00:00
|
|
|
String[] requiredParameters = {"name_length", "use_micro_logs", "fs_size",
|
|
|
|
"page_size", "sector_size",
|
2009-08-04 10:36:53 +00:00
|
|
|
"start_offset", "default_file_size",
|
|
|
|
"default_log_size", "page_type_size"};
|
|
|
|
Properties prop = new Properties();
|
2009-08-11 14:42:58 +00:00
|
|
|
InputStream stream = CoffeeConfiguration.class.getResourceAsStream("/" + filename);
|
|
|
|
if (stream == null) {
|
|
|
|
throw new CoffeeException("failed to load the configuration file " + filename);
|
|
|
|
}
|
2009-08-04 10:36:53 +00:00
|
|
|
|
2009-08-11 14:42:58 +00:00
|
|
|
prop.load(stream);
|
2012-01-28 02:34:16 +00:00
|
|
|
for (int i = 0; i < requiredParameters.length; i++) {
|
|
|
|
if (prop.getProperty(requiredParameters[i]) == null) {
|
|
|
|
throw new CoffeeException("missing the parameter \"" + requiredParameters[i] + "\" in the configuration file " + filename);
|
2009-08-04 10:36:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-28 02:34:16 +00:00
|
|
|
nameLength = Integer.parseInt(prop.getProperty("name_length"));
|
2009-08-04 10:36:53 +00:00
|
|
|
useMicroLogs = new Boolean(prop.getProperty("use_micro_logs")).booleanValue();
|
2012-01-28 02:34:16 +00:00
|
|
|
fsSize = Integer.parseInt(prop.getProperty("fs_size"));
|
|
|
|
sectorSize = Integer.parseInt(prop.getProperty("sector_size"));
|
|
|
|
pageSize = Integer.parseInt(prop.getProperty("page_size"));
|
|
|
|
defaultFileSize = Integer.parseInt(prop.getProperty("default_file_size"));
|
|
|
|
defaultLogSize = Integer.parseInt(prop.getProperty("default_log_size"));
|
|
|
|
startOffset = Integer.parseInt(prop.getProperty("start_offset"));
|
|
|
|
pageTypeSize = Integer.parseInt(prop.getProperty("page_type_size"));
|
2009-08-04 10:36:53 +00:00
|
|
|
|
|
|
|
pagesPerSector = sectorSize / pageSize;
|
|
|
|
}
|
|
|
|
}
|