View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.tournament.botexecution;
2   
3   import java.io.File;
4   
5   import cz.cuni.amis.pogamut.ut2004.tournament.match.UT2004BotConfig;
6   import cz.cuni.amis.utils.NullCheck;
7   import cz.cuni.amis.utils.token.IToken;
8   import cz.cuni.amis.utils.token.Tokens;
9   
10  public class UT2004BotExecutionConfig {
11  	
12  	/**
13  	 * Unique id of this bot, used for reference inside tournament results.
14  	 * <p><p>
15  	 * DOES NOT MEAN THAT THE EXECUTED BOT WILL HAVE THIS ID IN UT2004!
16  	 */
17  	private IToken botId;
18  		
19  	/**
20  	 * Path to the directory that contains runnable jar file with the bot.
21  	 */
22  	private String pathToBotJar = null;
23  	
24  	/**
25  	 * Whether the StdErr of the bot execution should be redirected to log (== true, default) or sunk (== false).
26  	 */
27  	private boolean redirectStdErr = true;
28  	
29  	/**
30  	 * Whether the StdOut of the bot execution should be redirected to log (== true, default) or sunk (== false).
31  	 */
32  	private boolean redirectStdOut = true;
33  
34  	/**
35  	 * {@link UT2004BotExecutionConfig#pathToBotJar} as a {@link File}.
36  	 */
37  	private File fileToJar;
38  
39  	/**
40  	 * Returns ID of this bot configuration. This ID will be used for storing result of the tournament for this bot.
41  	 * <p><p>
42  	 * DOES NOT MEAN THAT THE EXECUTED BOT WILL HAVE THIS ID IN UT2004!
43  	 * 
44  	 * @return
45  	 */
46  	public IToken getBotId() {
47  		return botId;
48  	}
49  	
50  	/**
51  	 * Parameter-less constructor.
52  	 */
53  	public UT2004BotExecutionConfig() {		
54  	}
55  
56  	/**
57  	 * Copy-constructor;
58  	 * @param value
59  	 */
60  	public UT2004BotExecutionConfig(UT2004BotConfig value) {
61  		this.botId = value.getBotId();
62  		this.setPathToBotJar(value.getPathToBotJar());
63  		this.redirectStdErr = value.isRedirectStdErr();
64  		this.redirectStdOut = value.isRedirectStdOut();
65  	}
66  
67  	/**
68  	 * Sets ID of this bot configuration. This ID will be used for storing result of the tournament for this bot.
69  	 * <p><p>
70  	 * DOES NOT MEAN THAT THE EXECUTED BOT WILL HAVE THIS ID IN UT2004!
71  	 * 
72  	 * @param botId
73  	 */
74  	public UT2004BotExecutionConfig setBotId(String botId) {
75  		NullCheck.check(botId, "botId");
76  		this.botId = Tokens.get(botId);
77  		return this;
78  	}
79  	
80  	/**
81  	 * Sets ID of this bot configuration. This ID will be used for storing result of the tournament for this bot.
82  	 * <p><p>
83  	 * DOES NOT MEAN THAT THE EXECUTED BOT WILL HAVE THIS ID IN UT2004!
84  	 * 
85  	 * @param botId
86  	 */
87  	public UT2004BotExecutionConfig setBotId(IToken botId) {
88  		NullCheck.check(botId, "botId");
89  		this.botId = botId;
90  		return this;
91  	}
92  	
93  	/**
94  	 * Path to the runnable jar file contining the bot to be run.
95  	 * @return
96  	 */
97  	public String getPathToBotJar() {
98  		return pathToBotJar;
99  	}
100 
101 	/** 
102 	 * Sets the path to jar-file of the bot.
103 	 * @param botDirPath
104 	 */
105 	public UT2004BotExecutionConfig setPathToBotJar(String pathToBotJar) {
106 		if (pathToBotJar != null) {
107 			this.fileToJar = new File(pathToBotJar);
108 		} else {
109 			this.fileToJar = null;
110 		}
111 		this.pathToBotJar = pathToBotJar;
112 		return this;
113 	}
114 	
115 	/**
116 	 * Whether the jar specified by this config exists.
117 	 * @return
118 	 */
119 	public boolean isBotJarExist() {
120 		if (this.pathToBotJar == null) return false;
121 		File file = getJarFile();
122 		return file.exists() && file.isFile(); 
123 	}
124 
125 	/**
126 	 * Returns path to jar as a file.
127 	 * @return
128 	 */
129 	public File getJarFile() {
130 		return fileToJar;
131 	}
132 	
133 	/**
134 	 * Whether the StdErr of the bot execution should be redirected to log (== true, default) or sunk (== false).
135 	 * @return
136 	 */
137 	public boolean isRedirectStdErr() {
138 		return redirectStdErr;
139 	}
140 
141 	/**
142 	 * Sets whether the StdErr of the bot execution should be redirected to log (== true, default) or sunk (== false).
143 	 * @param redirectStdErr
144 	 */
145 	public UT2004BotExecutionConfig setRedirectStdErr(boolean redirectStdErr) {
146 		this.redirectStdErr = redirectStdErr;
147 		return this;
148 	}
149 
150 	/**
151 	 * Whether the StdOut of the bot execution should be redirected to log (== true, default) or sunk (== false).
152 	 * @return
153 	 */
154 	public boolean isRedirectStdOut() {
155 		return redirectStdOut;
156 	}
157 
158 	/**
159 	 * Sets whether the StdOut of the bot execution should be redirected to log (== true, default) or sunk (== false).
160 	 * @param redirectStdOut
161 	 */
162 	public UT2004BotExecutionConfig setRedirectStdOut(boolean redirectStdOut) {
163 		this.redirectStdOut = redirectStdOut;
164 		return this;
165 	}
166 
167 	@Override
168 	public String toString() {
169 		return "UT2004BotExecutionConfig[botId=" + botId.getToken() + ", jar=" + pathToBotJar + "]";
170 	}
171 
172 }