6 import java
.rmi
.registry
.*;
7 import java
.rmi
.server
.*;
8 import java
.security
.*;
15 * SampleGetRunsClient is a sample implmentation of the abstract {@link GetRunsClient}
17 * @author PC<sup>2</sup> Team, pc2@ecs.csus.edu
19 public class SampleGetRunsClient
extends GetRunsClient
{
24 public SampleGetRunsClient() throws java
.rmi
.RemoteException
{
28 * Handle New Run (Sample)
30 * Outputs most information to the log <Br>
31 * Unpacks the input files into the current directory
32 * prepending RunXX onto the start of the filename.
34 public void handleNewRun(RunInfoAndFiles run
) {
36 String nl
= System
.getProperty("line.separator");
38 PC2Log
.message("handleNewRun: "+
39 run
.getUserSiteId() + ":" + run
.getRunId() );
41 PC2Log
.message("handleNewRun: "+
43 nl
+ "site:id " + run
.toString() +
44 nl
+ "user id " + run
.getUserId() +
45 nl
+ "user name " + run
.getUserTitle() +
46 nl
+ "problem id " + run
.getProblemId() +
47 nl
+ "problem name " + run
.getProblemTitle() +
48 nl
+ "language id " + run
.getLanguageId() +
49 nl
+ "language name " + run
.getLanguageTitle() +
50 nl
+ "main file name " + run
.getMainFileName()
53 if (run
.getNumUserFiles() == 0)
54 PC2Log
.message("handleNewRun: There are no files");
57 PC2Log
.message("handleNewRun: There are "+run
.getNumUserFiles()+" files");
58 for (int i
= 0; i
< run
.getNumUserFiles();i
++)
60 String newfilename
= "Run"+run
.getRunId()+"."+run
.getUserFileName(i
);
61 PC2Log
.message("handleNewRun: File ["+i
+"] "+run
.getUserFileName(i
)+" written to: "+newfilename
);
63 run
.writeUserFile(i
, newfilename
);
64 } catch (Exception ex
)
66 System
.err
.println("Exception in handleNewRun "+ex
.getMessage());
72 * Starts the application.
73 * @param args an array of command-line arguments
75 public static void main(java
.lang
.String
[] args
) {
77 SampleGetRunsClient sc
=null;
79 sc
= new SampleGetRunsClient();
80 } catch (Exception e
){
81 PC2Log
.message("error in new SampleClient()",e
);
85 String loginId
= "custom1";
90 System
.err
.println("From Command line using login: "+loginId
);
93 // This sets the debug level for the log according to pc2v8.ini
94 if (new PC2ini().containsKey("client.debugLevel")) {
95 String temp
=PC2ini
.getKey("client.debugLevel");
97 int value
=new Integer(temp
).intValue();
98 PC2Log
.setDebugLevel(value
);
99 } catch (NumberFormatException nfe
) {
105 if (! sc
.loginToPC2("127.0.0.1", PC2Constants
.DEFAULT_PC2_PORT
, 1, loginId
, loginId
))
107 PC2Log
.message("Could not login as "+loginId
);
108 JFrame frame
= new JFrame("Invisible JFrame... ooh");
109 JOptionPane
.showMessageDialog
112 "Could not login as "+loginId
,
114 JOptionPane
.INFORMATION_MESSAGE
119 } catch (Exception exc
) {
120 PC2Log
.message("Exception ",exc
);
123 sc
.showContestInfo(System
.out
);
125 sc
.waitAround(); // Wait for new runs, see the doc
126 // for this method to find out why.
129 * Displays all contest info
131 public void showContestInfo(PrintStream ps
) {
137 ps
.println("showContestInfo");
138 ps
.println("- - Problems - - ");
139 for (int i
= 1; i
<= getNumProblems(); i
++)
141 ps
.println("Problem "+i
+" \""+getProblemTitle(new Long(i
))+"\"");
143 ps
.println(getNumProblems()+" problems defined");
147 ps
.println("- - Languages - - ");
148 for (int i
= 1; i
<= getNumLanguages(); i
++)
150 ps
.println("Language "+i
+" \""+getLanguageTitle(new Long(i
))+"\"");
152 ps
.println(getNumLanguages()+" languages defined");
156 ps
.println("- - Team Names - - ");
157 for (int i
= 1; i
<= getNumTeamAccounts(); i
++)
159 ps
.println("Team "+i
+" \""+getTeamName (new Long(1), new Long (i
))+"\"");
161 ps
.println(getNumTeamAccounts()+" accounts defined");
164 } catch (Exception ex
) {
165 PC2Log
.message("Exception ",ex
);
171 * Wait around so that we can get incoming runs.
173 * Wait around until a sentinel file 'stopcust' is
174 * created. When file is found in current directory
177 * This functionality is done within PC<sup>2</sup> by
178 * using JFrame to keep the JVM alive.
180 public void waitAround() {
183 String filename
= "stopcust";
185 Thread th
= new Thread();
187 PC2Log
.message("Create file named '"+filename
+"' to exit client.");
190 for (long i
= 1; ; i
++)
192 PC2Log
.message("["+i
+"] waiting for "+secs
+" secs...");
193 th
.sleep(secs
* 1000);
196 File checkFile
= new File(filename
);
197 if (checkFile
.exists())
200 PC2Log
.message("Logging off...");
203 PC2Log
.message("Logged out.");
205 th
.sleep (secs
* 1000);
210 } catch (Exception ex
)
212 PC2Log
.message("Exception ",ex
);