KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > framework > Racer


1 /*
2  This file is part of the PolePosition database benchmark
3  http://www.polepos.org
4
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation; either version 2
8  of the License, or (at your option) any later version.
9
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14
15  You should have received a copy of the GNU General Public
16  License along with this program; if not, write to the Free
17  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18  MA 02111-1307, USA. */

19
20 package org.polepos.framework;
21
22 import java.util.*;
23
24 import org.polepos.reporters.*;
25
26 public class Racer implements Runnable JavaDoc {
27
28     
29     /**
30      * By setting the XSS_THREAD variable to true Poleposition can be
31      * configured to run in a dedicated thread to allow -Xss settings.
32      * see: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4689767
33      */

34     private static final boolean XSS_THREAD = false;
35
36     private final List<Circuit> circuits;
37     private final List<Team> teams;
38
39     public Racer(List<Circuit> circuits, List<Team> teams) {
40         this.circuits = circuits;
41         this.teams = teams;
42         
43         if(! XSS_THREAD){
44             run();
45             return;
46         }
47
48         new Thread JavaDoc(this).start();
49         
50         synchronized (this) {
51             try {
52                 this.wait(Integer.MAX_VALUE);
53             } catch (InterruptedException JavaDoc e) {
54                 e.printStackTrace();
55             }
56         }
57     }
58
59     public void run() {
60
61         synchronized (this) {
62
63             long start = System.currentTimeMillis();
64
65             Reporter[] reporters = new Reporter[] { new PlainTextReporter(), new PDFReporter(),
66                 new CSVReporter(), new HTMLReporter()};
67
68             for (Reporter reporter : reporters) {
69                 reporter.startSeason();
70             }
71
72             for (Circuit circuit : circuits) {
73
74                 System.out.println("* Racing on " + circuit.name());
75
76                 for (Reporter reporter : reporters) {
77                     reporter.sendToCircuit(circuit);
78                 }
79
80                 for (Team team : teams) {
81
82                     Driver[] drivers = team.nominate(circuit);
83
84                     if (drivers == null || drivers.length == 0) {
85
86                         for (Reporter reporter : reporters) {
87                             reporter.noDriver(team, circuit);
88                         }
89
90                     } else {
91                         for (Driver driver : drivers) {
92
93                             for (Car car : team.cars()) {
94
95                                 if (car != null) {
96
97                                     System.out.println("** On track: " + team.name() + "/"
98                                         + car.name());
99
100                                     TurnSetup[] setups = circuit.lapSetups();
101                                     TurnResult[] results = circuit.race(team, car, driver);
102
103                                     for (Reporter reporter : reporters) {
104                                         reporter.report(team, car, setups, results);
105                                     }
106                                 }
107                             }
108                         }
109                     }
110                 }
111             }
112
113             for (Reporter reporter : reporters) {
114                 reporter.endSeason();
115             }
116
117             long stop = System.currentTimeMillis();
118             long duration = stop - start;
119
120             System.out.println("\n****************************************************");
121             System.out.println("The F1 season was run O.K. without lethal accidents.");
122             System.out.println("****************************************************\n");
123             System.out.println("Overall time taken: " + duration + "ms\n");
124             System.out.println("All output from this benchmark run can be found in:");
125             System.out.println(reporters[0].path());
126             this.notify();
127         }
128         
129     }
130 }
131
Popular Tags