001: /*
002: This file is part of the PolePosition database benchmark
003: http://www.polepos.org
004:
005: This program is free software; you can redistribute it and/or
006: modify it under the terms of the GNU General Public License
007: as published by the Free Software Foundation; either version 2
008: of the License, or (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public
016: License along with this program; if not, write to the Free
017: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
018: MA 02111-1307, USA. */
019:
020: package org.polepos.framework;
021:
022: import java.util.*;
023:
024: import org.polepos.reporters.*;
025:
026: public class Racer implements Runnable {
027:
028: /**
029: * By setting the XSS_THREAD variable to true Poleposition can be
030: * configured to run in a dedicated thread to allow -Xss settings.
031: * see: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4689767
032: */
033: private static final boolean XSS_THREAD = false;
034:
035: private final List<Circuit> circuits;
036: private final List<Team> teams;
037:
038: public Racer(List<Circuit> circuits, List<Team> teams) {
039: this .circuits = circuits;
040: this .teams = teams;
041:
042: if (!XSS_THREAD) {
043: run();
044: return;
045: }
046:
047: new Thread(this ).start();
048:
049: synchronized (this ) {
050: try {
051: this .wait(Integer.MAX_VALUE);
052: } catch (InterruptedException e) {
053: e.printStackTrace();
054: }
055: }
056: }
057:
058: public void run() {
059:
060: synchronized (this ) {
061:
062: long start = System.currentTimeMillis();
063:
064: Reporter[] reporters = new Reporter[] {
065: new PlainTextReporter(), new PDFReporter(),
066: new CSVReporter(), new HTMLReporter() };
067:
068: for (Reporter reporter : reporters) {
069: reporter.startSeason();
070: }
071:
072: for (Circuit circuit : circuits) {
073:
074: System.out.println("* Racing on " + circuit.name());
075:
076: for (Reporter reporter : reporters) {
077: reporter.sendToCircuit(circuit);
078: }
079:
080: for (Team team : teams) {
081:
082: Driver[] drivers = team.nominate(circuit);
083:
084: if (drivers == null || drivers.length == 0) {
085:
086: for (Reporter reporter : reporters) {
087: reporter.noDriver(team, circuit);
088: }
089:
090: } else {
091: for (Driver driver : drivers) {
092:
093: for (Car car : team.cars()) {
094:
095: if (car != null) {
096:
097: System.out.println("** On track: "
098: + team.name() + "/"
099: + car.name());
100:
101: TurnSetup[] setups = circuit
102: .lapSetups();
103: TurnResult[] results = circuit
104: .race(team, car, driver);
105:
106: for (Reporter reporter : reporters) {
107: reporter.report(team, car,
108: setups, results);
109: }
110: }
111: }
112: }
113: }
114: }
115: }
116:
117: for (Reporter reporter : reporters) {
118: reporter.endSeason();
119: }
120:
121: long stop = System.currentTimeMillis();
122: long duration = stop - start;
123:
124: System.out
125: .println("\n****************************************************");
126: System.out
127: .println("The F1 season was run O.K. without lethal accidents.");
128: System.out
129: .println("****************************************************\n");
130: System.out.println("Overall time taken: " + duration
131: + "ms\n");
132: System.out
133: .println("All output from this benchmark run can be found in:");
134: System.out.println(reporters[0].path());
135: this.notify();
136: }
137:
138: }
139: }
|