View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.analyzer;
2   
3   import java.util.Map;
4   
5   import cz.cuni.amis.pogamut.base.agent.IAgentId;
6   import cz.cuni.amis.pogamut.base.agent.params.IAgentParameters;
7   import cz.cuni.amis.pogamut.base.agent.utils.runner.IAgentRunner;
8   import cz.cuni.amis.pogamut.base.agent.utils.runner.IMultipleAgentRunner;
9   import cz.cuni.amis.pogamut.base.communication.connection.IWorldConnectionAddress;
10  import cz.cuni.amis.pogamut.base.communication.connection.impl.socket.SocketConnectionAddress;
11  import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
12  import cz.cuni.amis.pogamut.ut2004.agent.params.UT2004AgentParameters;
13  import cz.cuni.amis.pogamut.ut2004.factory.guice.remoteagent.UT2004ObserverModule;
14  import cz.cuni.amis.pogamut.ut2004.utils.UT2004AnalyzerRunner;
15  
16  /**
17   * Agent parameters are meant to provide run-time parameters needed by {@link UT2004Analyzer}.
18   * <p><p>
19   * Crucial parameters that (even though are present in the {@link UT2004AnalyzerRunner} might be needed
20   * in order to customize whole {@link UT2004Analyzer}: {@link UT2004AnalyzerParameters#setObserverModule(UT2004AnalyzerObserverModule).
21   * <p><p>
22   * NOTE: all {@link IAgentParameters} implementors are usually used together with {@link IAgentRunner} or {@link IMultipleAgentRunner}
23   * which usually contains sensible default params, therefore there is no need to set all parameters
24   * into newly created ones as runners will supply them via {@link IAgentParameters#assignDefaults(IAgentParameters)}.
25   *
26   * @see UT2004AgentParameters
27   * @author Jimmy
28   */
29  public class UT2004AnalyzerParameters extends UT2004AgentParameters {
30  
31  	private SocketConnectionAddress observerAddress;
32  	private UT2004AnalyzerObserverModule observerModule;
33  	private String outputPath;
34  	private Boolean waitForMatchRestart = null;
35  	private Map<UnrealId, String> fileNames = null;
36  	
37  	/**
38  	 * If you need to populate the parameters after instantiation, use setters available in this
39  	 * class: {@link UT2004AnalyzerParameters#setAgentId(IAgentId)}, {@link UT2004AnalyzerParameters#setWorldAddress(IWorldConnectionAddress)},
40  	 * {@link UT2004AnalyzerParameters#setObserverModule(UT2004ObserverModule)}.
41  	 */
42  	public UT2004AnalyzerParameters() {
43  		super();
44  	}
45  
46  	public UT2004AnalyzerObserverModule getObserverModule() {
47  		return observerModule;
48  	}
49  
50  	/**
51  	 * Sets observer module (one that will be used to construct new {@link UT2004AnalyzerObserver} in 
52  	 * order to sniff info about connected bots.
53  	 * <p><p>
54  	 * WARNING: Note that you should not mess with 'setters' in different threads as they
55  	 * are non-thread-safe and may interrupt horrible agent instantiations with such behavior.
56  	 * @param address
57  	 * @return this instance
58  	 */
59  	public UT2004AnalyzerParameters setObserverModule(UT2004AnalyzerObserverModule observerModule) {
60  		this.observerModule = observerModule;
61  		return this;
62  	}
63  	
64  	@Override
65  	public UT2004AnalyzerParameters setAgentId(IAgentId agentId) {
66  		super.setAgentId(agentId);
67  		return this;
68  	}
69  	
70  	@Override
71  	public UT2004AnalyzerParameters setWorldAddress(IWorldConnectionAddress address) {
72  		super.setWorldAddress(address);
73  		return this;
74  	}
75  	
76  	/**
77  	 * Contains path to directory where the observer should output its results. MUST POINT TO DIR!
78  	 * @return
79  	 */
80  	public String getOutputPath() {
81  		return outputPath;
82  	}
83  
84  	/**
85  	 * Sets  path to directory where the observer should output its results. MUST POINT TO DIR!
86  	 * @param outputPath
87  	 */
88  	public UT2004AnalyzerParameters setOutputPath(String outputPath) {
89  		this.outputPath = outputPath;
90  		return this;
91  	}
92  	
93  	/**
94  	 * Whether the analyzer's observers should wait for match-restart before it starts to collect data.
95  	 * @return
96  	 */
97  	public boolean isWaitForMatchRestart() {
98  		return waitForMatchRestart == null ? false : waitForMatchRestart;
99  	}
100 
101 	/**
102 	 * Sets whether the analyzer's observers should wait for match-restart before it starts to collect data.
103 	 * @param waitForMatchRestart
104 	 */
105 	public UT2004AnalyzerParameters setWaitForMatchRestart(boolean waitForMatchRestart) {
106 		this.waitForMatchRestart = waitForMatchRestart;
107 		return this;
108 	}	
109 	
110 	/**
111 	 * This may be used to provide concrete filenames for outputting stats for bots identified by their id.
112 	 * @return
113 	 */
114 	public Map<UnrealId, String> getFileNames() {
115 		return fileNames;
116 	}
117 
118 	/**
119 	 * This may be used to provide concrete filenames for outputting stats for bots identified by their id.
120 	 * @param fileNames
121 	 * @return
122 	 */
123 	public UT2004AnalyzerParameters setFileNames(Map<UnrealId, String> fileNames) {
124 		this.fileNames = fileNames;
125 		return this;
126 	}
127 
128 	/**
129 	 * Returns observer address that should be used for spawning new observers.
130 	 * @return
131 	 */
132 	public SocketConnectionAddress getObserverAddress() {
133 		return observerAddress;
134 	}
135 
136 	/**
137 	 * Sets observer address that should be used for spawning new observers. If you do not specify it a default address will be used.
138 	 * @param observerAddress
139 	 */
140 	public UT2004AnalyzerParameters setObserverAddress(SocketConnectionAddress observerAddress) {
141 		this.observerAddress = observerAddress;
142 		return this;
143 	}
144 
145 	
146 	@Override
147 	public void assignDefaults(IAgentParameters defaults) {
148 		super.assignDefaults(defaults);
149 		if (defaults instanceof UT2004AnalyzerParameters) {
150 			if (observerModule == null) observerModule = ((UT2004AnalyzerParameters)defaults).getObserverModule();
151 			if (observerAddress == null) observerAddress = ((UT2004AnalyzerParameters)defaults).getObserverAddress();
152 			if (outputPath == null) outputPath = ((UT2004AnalyzerParameters)defaults).getOutputPath();
153 			if (waitForMatchRestart == null && ((UT2004AnalyzerParameters)defaults).waitForMatchRestart != null)
154 				waitForMatchRestart = ((UT2004AnalyzerParameters)defaults).waitForMatchRestart;
155 			if (fileNames == null && ((UT2004AnalyzerParameters)defaults).fileNames != null) {
156 				this.fileNames = ((UT2004AnalyzerParameters)defaults).fileNames;
157 			}
158 		}
159 	}	
160 	
161 }