Revision: 91
http://polepos.svn.sourceforge.net/polepos/?rev=91&view=rev
Author: carlrosenberger
Date: 2009-09-17 13:52:58 +0000 (Thu, 17 Sep 2009)
Log Message:
-----------
cr + pr: Added the capability to specify a custom settings file.
Modified Paths:
--------------
trunk/polepos/src/org/polepos/framework/Circuit.java
trunk/polepos/src/org/polepos/framework/TurnSetup.java
trunk/polepos/src/org/polepos/runner/AbstractRunner.java
Added Paths:
-----------
trunk/polepos/src/org/polepos/framework/TurnSetupConfig.java
Modified: trunk/polepos/src/org/polepos/framework/Circuit.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/Circuit.java 2009-09-15 13:28:25 UTC (rev 90)
+++ trunk/polepos/src/org/polepos/framework/Circuit.java 2009-09-17 13:52:58 UTC (rev 91)
@@ -32,7 +32,7 @@
private final List<Lap> mLaps;
- private final TurnSetup[] mLapSetups;
+ private TurnSetup[] mLapSetups;
// TODO: watcher can be installed, and should be sorted, i.e. memory watcher
// should start before time watcher
@@ -47,9 +47,12 @@
protected Circuit(){
initWatchers();
mLaps = new ArrayList<Lap>();
- mLapSetups = TurnSetup.read(this);
addLaps();
}
+
+ public void setTurnSetups(TurnSetup[] turnSetups){
+ mLapSetups = turnSetups;
+ }
private void initWatchers() {
_timeWatcher = new TimeWatcher();
Modified: trunk/polepos/src/org/polepos/framework/TurnSetup.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/TurnSetup.java 2009-09-15 13:28:25 UTC (rev 90)
+++ trunk/polepos/src/org/polepos/framework/TurnSetup.java 2009-09-17 13:52:58 UTC (rev 91)
@@ -21,7 +21,6 @@
import java.util.*;
-import org.polepos.*;
/**
@@ -29,29 +28,6 @@
*/
public class TurnSetup implements Cloneable{
-
- private final static PropertiesHandler mProperties = new PropertiesHandler(Settings.CIRCUIT);
-
- public final static String OBJECTCOUNT = "objects";
- public final static String SELECTCOUNT = "selects";
- public final static String UPDATECOUNT = "updates";
- public final static String COMMITCOUNT = "commits";
- public final static String TREEWIDTH = "width";
- public final static String TREEDEPTH = "depth";
- public final static String COMMITINTERVAL = "commitinterval";
- public final static String OBJECTSIZE = "size";
-
- private final static String[] AVAILABLE_SETTINGS = new String[]{
- OBJECTCOUNT,
- SELECTCOUNT,
- UPDATECOUNT,
- COMMITCOUNT,
- TREEWIDTH,
- TREEDEPTH,
- COMMITINTERVAL,
- OBJECTSIZE
- };
-
private Map<SetupProperty, SetupProperty> mSettings = new Hashtable<SetupProperty, SetupProperty>();
public TurnSetup() {
@@ -63,7 +39,7 @@
}
}
- private TurnSetup deepClone(){
+ TurnSetup deepClone(){
TurnSetup res = null;
try {
res = (TurnSetup)this.clone();
@@ -77,53 +53,6 @@
return res;
}
- public static TurnSetup[] read(Circuit circuit){
-
- Vector<TurnSetup> vec = new Vector<TurnSetup>();
-
- for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
-
- int[] values = null;
-
- try{
- values = mProperties.getIntArray(circuit.internalName() + "." + AVAILABLE_SETTINGS[i]);
- }catch(Exception e){
-
- }
-
- if(values!= null && values.length > 0){
- int len = values.length;
-
- // make sure that we have enough LapSetup objects in our vector
- // and clone the last if we dont or create a first one
- while(vec.size() < len){
- if(vec.size() > 0){
- vec.add((vec.get(vec.size() - 1)).deepClone());
- }else{
- vec.add(new TurnSetup());
- }
- }
-
- // pass values to all LapSetup objects and take the last value as
- // the default if there are more than we have values
- int j = 0;
- Iterator it = vec.iterator();
- while(it.hasNext()){
- TurnSetup ls = (TurnSetup)it.next();
- SetupProperty sp =new SetupProperty(AVAILABLE_SETTINGS[i], values[j]);
- ls.mSettings.put(sp, sp);
- if(j < values.length - 1){
- j++;
- }
- }
- }
- }
-
- TurnSetup[] res = new TurnSetup[vec.size()];
- vec.toArray(res);
-
- return res;
- }
private int getSetting(String key){
SetupProperty p = mSettings.get(new SetupProperty(key, 0));
@@ -134,40 +63,40 @@
}
public int getCommitInterval(){
- return getSetting(COMMITINTERVAL);
+ return getSetting(TurnSetupConfig.COMMITINTERVAL);
}
public int getCommitCount(){
- return getSetting(COMMITCOUNT);
+ return getSetting(TurnSetupConfig.COMMITCOUNT);
}
public int getObjectCount(){
- return getSetting(OBJECTCOUNT);
+ return getSetting(TurnSetupConfig.OBJECTCOUNT);
}
public int getSelectCount(){
- return getSetting(SELECTCOUNT);
+ return getSetting(TurnSetupConfig.SELECTCOUNT);
}
public int getUpdateCount(){
- return getSetting(UPDATECOUNT);
+ return getSetting(TurnSetupConfig.UPDATECOUNT);
}
public int getTreeWidth(){
- return getSetting(TREEWIDTH);
+ return getSetting(TurnSetupConfig.TREEWIDTH);
}
public int getTreeDepth(){
- return getSetting(TREEDEPTH);
+ return getSetting(TurnSetupConfig.TREEDEPTH);
}
public int getObjectSize(){
- return getSetting(OBJECTSIZE);
+ return getSetting(TurnSetupConfig.OBJECTSIZE);
}
public int getMostImportantValueForGraph(){
- for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
- int val = getSetting(AVAILABLE_SETTINGS[i]);
+ for (int i = 0; i < TurnSetupConfig.AVAILABLE_SETTINGS.length; i++) {
+ int val = getSetting(TurnSetupConfig.AVAILABLE_SETTINGS[i]);
if(val > 0){
return val;
}
@@ -176,10 +105,10 @@
}
public String getMostImportantNameForGraph(){
- for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
- int val = getSetting(AVAILABLE_SETTINGS[i]);
+ for (int i = 0; i < TurnSetupConfig.AVAILABLE_SETTINGS.length; i++) {
+ int val = getSetting(TurnSetupConfig.AVAILABLE_SETTINGS[i]);
if(val > 0){
- return AVAILABLE_SETTINGS[i];
+ return TurnSetupConfig.AVAILABLE_SETTINGS[i];
}
}
return "";
@@ -189,4 +118,8 @@
return Collections.unmodifiableSet(mSettings.keySet());
}
+ public void addSetting(SetupProperty setupProperty){
+ mSettings.put(setupProperty, setupProperty);
+ }
+
}
Added: trunk/polepos/src/org/polepos/framework/TurnSetupConfig.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/TurnSetupConfig.java (rev 0)
+++ trunk/polepos/src/org/polepos/framework/TurnSetupConfig.java 2009-09-17 13:52:58 UTC (rev 91)
@@ -0,0 +1,102 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with this program; if not, write to the Free
+Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+package org.polepos.framework;
+
+import java.util.*;
+
+import org.polepos.*;
+
+public class TurnSetupConfig {
+
+ private final PropertiesHandler mProperties;
+ public final static String OBJECTCOUNT = "objects";
+ public final static String SELECTCOUNT = "selects";
+ public final static String UPDATECOUNT = "updates";
+ public final static String COMMITCOUNT = "commits";
+ public final static String TREEWIDTH = "width";
+ public final static String TREEDEPTH = "depth";
+ public final static String COMMITINTERVAL = "commitinterval";
+ public final static String OBJECTSIZE = "size";
+ final static String[] AVAILABLE_SETTINGS = new String[]{
+ OBJECTCOUNT,
+ SELECTCOUNT,
+ UPDATECOUNT,
+ COMMITCOUNT,
+ TREEWIDTH,
+ TREEDEPTH,
+ COMMITINTERVAL,
+ OBJECTSIZE
+ };
+
+ public TurnSetupConfig(String propertiesFileName){
+ mProperties = new PropertiesHandler(propertiesFileName);
+ }
+
+
+ public TurnSetup[] read(Circuit circuit){
+
+ Vector<TurnSetup> vec = new Vector<TurnSetup>();
+
+ for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
+
+ int[] values = null;
+
+ try{
+ values = mProperties.getIntArray(circuit.internalName() + "." + AVAILABLE_SETTINGS[i]);
+ }catch(Exception e){
+
+ }
+
+ if(values!= null && values.length > 0){
+ int len = values.length;
+
+ // make sure that we have enough LapSetup objects in our vector
+ // and clone the last if we dont or create a first one
+ while(vec.size() < len){
+ if(vec.size() > 0){
+ vec.add((vec.get(vec.size() - 1)).deepClone());
+ }else{
+ vec.add(new TurnSetup());
+ }
+ }
+
+ // pass values to all LapSetup objects and take the last value as
+ // the default if there are more than we have values
+ int j = 0;
+ Iterator it = vec.iterator();
+ while(it.hasNext()){
+ TurnSetup ls = (TurnSetup)it.next();
+ SetupProperty sp =new SetupProperty(AVAILABLE_SETTINGS[i], values[j]);
+ ls.addSetting(sp);
+ if(j < values.length - 1){
+ j++;
+ }
+ }
+ }
+ }
+
+ TurnSetup[] res = new TurnSetup[vec.size()];
+ vec.toArray(res);
+
+ return res;
+ }
+
+
+}
Property changes on: trunk/polepos/src/org/polepos/framework/TurnSetupConfig.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/polepos/src/org/polepos/runner/AbstractRunner.java
===================================================================
--- trunk/polepos/src/org/polepos/runner/AbstractRunner.java 2009-09-15 13:28:25 UTC (rev 90)
+++ trunk/polepos/src/org/polepos/runner/AbstractRunner.java 2009-09-17 13:52:58 UTC (rev 91)
@@ -19,14 +19,25 @@
package org.polepos.runner;
+import org.polepos.*;
import org.polepos.framework.*;
import org.polepos.reporters.*;
public abstract class AbstractRunner {
public void run() {
- new Racer(circuits(), teams(), reporters()).run();
+ run(Settings.CIRCUIT);
}
+
+ public void run(String propertiesFileName){
+ TurnSetupConfig turnSetupConfig = new TurnSetupConfig(propertiesFileName);
+ Circuit[] circuits = circuits();
+ for(Circuit circuit: circuits){
+ TurnSetup[] turnSetups = turnSetupConfig.read(circuit);
+ circuit.setTurnSetups(turnSetups);
+ }
+ new Racer(circuits, teams(), reporters()).run();
+ }
protected abstract Circuit[] circuits();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|