Subversion Repositories Code-Repo

Rev

Rev 96 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
96 Kevin 1
/*
2
 * CS 3114 Project 4
3
 * Author: Kevin Lee
4
 * Compiler: Eclipse 3.7.0
5
 * Operating System: Windows 7 x64
6
 * Date Completed: 12/4/2011
7
 * 
8
 * The following program is an combination of the previous three
9
 * projects. This program implements the GIS b-tree and
10
 * quad-tree, but instead of keeping the PRQuad-Tree in memory,
11
 * the PRQuad-Tree interfaces with a memory manager to store and
12
 * retrieve internal and leaf nodes, as well as city names. The
13
 * memory manager interfaces to a file ("p4bin.dat") using a 
14
 * buffer pool. The buffer pool is implemented using a least 
15
 * recently used block list. 
16
 * 
17
 * Note that while the PRQuad-Tree is optimized for speed, the
18
 * conversion of CityRecords to handles for the b-tree severely
19
 * slows down the program (see test _seq-16384-IR). If the b-tree
20
 * is kept completely in memory, the program runs >30x faster.
21
 * 
22
 * On my honor:
23
 *
24
 * - I have not used source code obtained from another student,
25
 * or any other unauthorized source, either modified or
26
 * unmodified.
27
 *
28
 * - All source code and documentation used in my program is
29
 * either my original work, or was derived by me from the
30
 * source code published in the textbook for this course.
31
 *
32
 * - I have not discussed coding details about this project with
33
 * anyone other than my partner (in the case of a joint
34
 * submission), instructor, ACM/UPE tutors or the TAs assigned
35
 * to this course. I understand that I may discuss the concepts
36
 * of this program with other students, and that another student
37
 * may help me debug my program so long as neither of us writes
38
 * anything during the discussion or modifies any computer file
39
 * during the discussion. I have violated neither the spirit nor
40
 * letter of this restriction.
41
 */
42
 
43
import java.io.BufferedReader;
44
import java.io.File;
45
import java.io.FileNotFoundException;
46
import java.io.FileReader;
47
import java.io.IOException;
48
 
49
public class Bindisk {
50
 
51
	public static void main(String[] args) {
52
 
53
		// 3 arguments must be supplied to the program
54
		if (args.length != 3) {
55
			System.out.println("3 Arguments must be supplied!");
56
			return;
57
		}
58
 
59
		// Parses passed arguments into member variables
60
		String dataFile = args[0];
61
		int buffSize = Integer.parseInt(args[1]);
62
		int blockSize = Integer.parseInt(args[2]);
63
 
64
		if (buffSize < 1 || buffSize > 20) {
65
			System.out.println("Number of buffers must be between 1 and 20");
66
			return;
67
		}
68
 
69
		LRUBuffer buffer = new LRUBuffer("p4bin.dat", "p4bin-stat.dat", buffSize, blockSize);
70
		MemManager memManager = new MemManager(buffer, blockSize);
71
 
72
		// Check to make sure the command file exists
73
		File cmdFile = new File(dataFile);
74
		if (!cmdFile.exists()) {
75
			System.out.printf("Command file not found");
76
			return;
77
		}
78
 
79
		CmdParser GISParser = new CmdParser(memManager);
80
		long time1 = System.currentTimeMillis();
81
		// Parse each command with the memory client
82
		try {
83
			BufferedReader reader = new BufferedReader(new FileReader(cmdFile));
84
			String cin;
85
			while ((cin = reader.readLine()) != null) {
86
				cin = cin.trim();
87
				if (cin.length() != 0) {
88
					// Send string to command parser
89
					GISParser.Parse(cin);
90
				}
91
			}
92
		} catch (FileNotFoundException e) {
93
			System.out.printf("Command file not found");
94
			return;
95
		} catch (IOException e) {
96
			System.out.printf("Unable to read input file");
97
			return;
98
		}
99
 
100
		buffer.flushBuffer();
101
		long time2 = System.currentTimeMillis();
102
		buffer.writeStats(time2-time1);
103
	}
104
 
105
}